Analog to digital and digital to analog conversion at 8 kHz rate on PA0 (A/D) and PA4 (D/A): use of timers and sleep() (to save energy). On PC8 there's a rising and falling signal to measure the time required by the A/D and D/A interrupt service routine.
Revision 1:a71233fe1e1c, committed 2016-05-04
- Comitter:
- IZ0ABD
- Date:
- Wed May 04 14:50:04 2016 +0000
- Parent:
- 0:57e0a19da71e
- Commit message:
- 2 timers, 8 kHz analog sampling on PA0 and analog output on PA4 + a H-L signal on PC8 to measure the time required by the A/D + D/A conversion.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-src.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 57e0a19da71e -r a71233fe1e1c main.cpp --- a/main.cpp Tue Dec 16 13:17:50 2014 +0000 +++ b/main.cpp Wed May 04 14:50:04 2016 +0000 @@ -1,17 +1,37 @@ #include "mbed.h" Ticker toggle_led_ticker; +Ticker sampler; + +// I/Os +AnalogIn analog_sample(A0); // Analog IN A0 +AnalogIn threshold_vlaue(A1); // Threshold A1 +AnalogOut my_output(PA_4); // Analog OUT A2 DigitalOut led1(LED1); +DigitalOut do0(PC_8); +DigitalOut do1(PC_9); + +float analog_value; +//uint16_t analog_value; void toggle_led() { led1 = !led1; } +void ADCisr() { + do0 = 1; + analog_value = analog_sample.read(); // Converts and read the analog input value (value from 0x0000 to 0xFFFF) + my_output.write(analog_value); +} + int main() { // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms) - toggle_led_ticker.attach(&toggle_led, 0.1); + toggle_led_ticker.attach(&toggle_led, 0.5); + sampler.attach(&ADCisr, 0.000125); // the address of the function to be attached (&..) and the interval (8 Khz) while (true) { // Do other things... + do0 = 0; + sleep(); // Enter in sleep } } \ No newline at end of file
diff -r 57e0a19da71e -r a71233fe1e1c mbed-src.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Wed May 04 14:50:04 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-src/#a11c0372f0ba