This program makes a sine wave. This converts 360 degrees into radian every once from 0 and gives it in sine function. The value multiply 0.5 by the result of the calculation and add 0.5 to give an offset voltage. As for the value that calculated, it becomes a sin wave of center level 1.65V, 0V at the minimum, up to 3.3V with a DA converter in this way. The sine wave is stored in a local file. Extension is .CSV. You can make a graph by Excel and confirm a sine wave. See: http://blogs.yahoo.co.jp/jf1vrr_station/19797477.html (Japanese)
Revision 0:9bc069e1c225, committed 2011-04-17
- Comitter:
- jf1vrr
- Date:
- Sun Apr 17 14:50:50 2011 +0000
- Commit message:
- Rev. 0.01A 2011/04/17
Changed in this revision
diff -r 000000000000 -r 9bc069e1c225 TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Sun Apr 17 14:50:50 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r 9bc069e1c225 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Apr 17 14:50:50 2011 +0000 @@ -0,0 +1,38 @@ +/* This program makes a sine wave. This converts 360 degrees +into radian every once from 0 and gives it in sine function. +The value multiply 0.5 by the result of the calculation and add 0.5 +to give an offset voltage. As for the value that calculated, +it becomes a sin wave of center level 1.65V, 0V at the minimum, +up to 3.3V with a DA converter in this way. +The sine wave is stored in a local file. Extension is .CSV. +You can make a graph by Excel and confirm a sine wave. +*/ +#include "mbed.h" +#include "TextLCD.h" + +TextLCD lcd(p24, p26, p27, p28, p29, p30); + +LocalFileSystem local("local"); +DigitalOut busy(LED2); +AnalogOut DA(p18); +AnalogIn AD(p20); + +int main() { + lcd.printf("SinWave\n"); + FILE *fp; + + if ( NULL == (fp = fopen( "/local/sinewave.csv", "w" )) ) + error( "" ); + + busy = 1; + + for (float i=0; i<360; i++) { + DA = sin(i/180*3.14)*0.5+0.5; + wait(0.05); + lcd.locate(0,1); + lcd.printf("DA out %0.5fV", AD.read()*3.3); + fprintf( fp, "%f\n", (float)AD.read()*3.3 ); + } + fclose( fp ); + busy = 0; +}
diff -r 000000000000 -r 9bc069e1c225 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Apr 17 14:50:50 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912