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)

Dependencies:   TextLCD mbed

Committer:
jf1vrr
Date:
Sun Apr 17 14:50:50 2011 +0000
Revision:
0:9bc069e1c225
Rev. 0.01A 2011/04/17

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jf1vrr 0:9bc069e1c225 1 /* This program makes a sine wave. This converts 360 degrees
jf1vrr 0:9bc069e1c225 2 into radian every once from 0 and gives it in sine function.
jf1vrr 0:9bc069e1c225 3 The value multiply 0.5 by the result of the calculation and add 0.5
jf1vrr 0:9bc069e1c225 4 to give an offset voltage. As for the value that calculated,
jf1vrr 0:9bc069e1c225 5 it becomes a sin wave of center level 1.65V, 0V at the minimum,
jf1vrr 0:9bc069e1c225 6 up to 3.3V with a DA converter in this way.
jf1vrr 0:9bc069e1c225 7 The sine wave is stored in a local file. Extension is .CSV.
jf1vrr 0:9bc069e1c225 8 You can make a graph by Excel and confirm a sine wave.
jf1vrr 0:9bc069e1c225 9 */
jf1vrr 0:9bc069e1c225 10 #include "mbed.h"
jf1vrr 0:9bc069e1c225 11 #include "TextLCD.h"
jf1vrr 0:9bc069e1c225 12
jf1vrr 0:9bc069e1c225 13 TextLCD lcd(p24, p26, p27, p28, p29, p30);
jf1vrr 0:9bc069e1c225 14
jf1vrr 0:9bc069e1c225 15 LocalFileSystem local("local");
jf1vrr 0:9bc069e1c225 16 DigitalOut busy(LED2);
jf1vrr 0:9bc069e1c225 17 AnalogOut DA(p18);
jf1vrr 0:9bc069e1c225 18 AnalogIn AD(p20);
jf1vrr 0:9bc069e1c225 19
jf1vrr 0:9bc069e1c225 20 int main() {
jf1vrr 0:9bc069e1c225 21 lcd.printf("SinWave\n");
jf1vrr 0:9bc069e1c225 22 FILE *fp;
jf1vrr 0:9bc069e1c225 23
jf1vrr 0:9bc069e1c225 24 if ( NULL == (fp = fopen( "/local/sinewave.csv", "w" )) )
jf1vrr 0:9bc069e1c225 25 error( "" );
jf1vrr 0:9bc069e1c225 26
jf1vrr 0:9bc069e1c225 27 busy = 1;
jf1vrr 0:9bc069e1c225 28
jf1vrr 0:9bc069e1c225 29 for (float i=0; i<360; i++) {
jf1vrr 0:9bc069e1c225 30 DA = sin(i/180*3.14)*0.5+0.5;
jf1vrr 0:9bc069e1c225 31 wait(0.05);
jf1vrr 0:9bc069e1c225 32 lcd.locate(0,1);
jf1vrr 0:9bc069e1c225 33 lcd.printf("DA out %0.5fV", AD.read()*3.3);
jf1vrr 0:9bc069e1c225 34 fprintf( fp, "%f\n", (float)AD.read()*3.3 );
jf1vrr 0:9bc069e1c225 35 }
jf1vrr 0:9bc069e1c225 36 fclose( fp );
jf1vrr 0:9bc069e1c225 37 busy = 0;
jf1vrr 0:9bc069e1c225 38 }