Basic_sine_wave_generator
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
Fork of 4180_proj by
Diff: main.cpp
- Revision:
- 3:bb920a8eb590
- Parent:
- 2:cc462c2a54f6
- Child:
- 4:1b82016459ff
--- a/main.cpp Fri Nov 27 00:42:38 2015 +0000 +++ b/main.cpp Fri Nov 27 02:03:52 2015 +0000 @@ -1,23 +1,34 @@ +/* ECE4180 Final Project -- mbed Function Generator + + Platform: mbed LPC-1768 + + Team member: Hanjie Xie + Qiuyang Tao + Xuefeng Jin + Yuqing Peng +*/ + + #include "mbed.h" #include "uLCD_4DGL.h" -// Objects for devices +//----- Objects for devices---------------------- Serial pc(USBTX, USBRX); uLCD_4DGL lcd(p13, p14, p15); AnalogOut aout(p18); DigitalOut dout(LED1); +//-----Global variable used for Func_Gen--------- const double pi = 3.14; float time_interv; -uint16_t sample = 0; int length_waveform=1000; uint16_t waveform[1000]; +float x; -int waveform_type=0; -float freq=2; //Hz -float amp=1; //Sacle factor, 1=full range -float offset=0.5; -float x; +//-----User Specified, change it if needed------- +int waveform_type=0; //0 for sine, +float freq,amp=1,offset=0.5; + void initialize_LCD(){ lcd.baudrate(3000000); @@ -28,49 +39,43 @@ lcd.printf("Fun Generator Demo"); } -void generate_waveform_datapoints(){ +void generate_waveform_datapoints(){ //Generate data points for the waveform float t=0; time_interv=1.0/freq/length_waveform; + //------if sine wave-------- + if (waveform_type==0){ + for (int datapoint_counter=0; datapoint_counter<length_waveform; datapoint_counter++){ + x=amp*(cos(2*pi*freq*t)+1); + waveform[datapoint_counter]=(uint16_t) (x*32767); + t += time_interv; + } + } + + //------if other wave-------- +} + +void output_waveform_datapoints(){ //Output the data points using DAC (pin18) + time_interv=1.0/freq/length_waveform; for (int datapoint_counter=0; datapoint_counter<length_waveform; datapoint_counter++){ - x=amp*(cos(2*pi*freq*t)+1); - waveform[datapoint_counter]=(uint16_t) (x*32767); - aout.write_u16(waveform[datapoint_counter]); - t += time_interv; - wait(time_interv); } } -void output_waveform_datapoints(){ - - - -} - int main(void){ - + waveform_type=0; //0 for sine, + freq=2; //Hz + amp=1; //Sacle factor, 1=full range + offset=0.5; initialize_LCD(); generate_waveform_datapoints(); - - - while (1){ - - generate_waveform_datapoints(); output_waveform_datapoints(); - - - /*for (float t = 0.0f; t < 1/freq; t += 1/fs) { - x=amp*(cos(2*pi*freq*t)+1); - sample=(uint16_t) (x*32767); - aout.write_u16(sample);; - wait(1/fs); - }*/ + } }