Junaid Ahmed
/
202A_HW1_ADCDAC
Program to generate sine wave via adc
Revision 0:66a0740d3ac0, committed 2014-02-15
- Comitter:
- mja054
- Date:
- Sat Feb 15 01:02:50 2014 +0000
- Commit message:
- Sine wave generation
Changed in this revision
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
sine-wave.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 66a0740d3ac0 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Feb 15 01:02:50 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43 \ No newline at end of file
diff -r 000000000000 -r 66a0740d3ac0 sine-wave.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sine-wave.cpp Sat Feb 15 01:02:50 2014 +0000 @@ -0,0 +1,56 @@ +#include "mbed.h" +#include "AnalogOut.h" +#include "AnalogIn.h" +#include <math.h> + +#define I2C0_SDA PTE25 +#define I2C0_SCL PTE24 +#define MMA8451_I2C_ADDRESS (0x1d<<1) +#define MAG3110_I2C_ADDRESS (0x0E<<1) +#define LIGHT_SENSOR_PIN PTE22 +#define PI 3.141f + +Serial pc_sine(USBTX, USBRX); +Timer timer; + + +void sine_wave() +{ + int t = 0; + float s; + AnalogOut a(PTE30); + while (1) { // sin(2 * PI * f * t / Fs) + s = sin(2 * PI * 1 * t / 100.0); + s = s/2 + .5; + a.write(s); + pc_sine.printf ("%f\n", s); + if (t == 100) + t = 0; + else + t++; + wait(0.01); + } +} + +void sine_wave_read() +{ + AnalogIn a(PTB0); + while(1) { + pc_sine.printf("%f\n", a.read()); + wait(0.01); + } +} + + +int main() { + sine_wave(); + + char c = pc_sine.getc(); + + switch (c) { + case '1':sine_wave(); + break; + case '2': sine_wave_read(); + break; + } +}