![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Using the Timer to test the maximum speed of the ADC and DAC
main.cpp@0:23ff2f1bb142, 2017-03-07 (annotated)
- Committer:
- tgartlan
- Date:
- Tue Mar 07 12:56:43 2017 +0000
- Revision:
- 0:23ff2f1bb142
- Child:
- 1:6bb2d13644e8
Using the Timer to test the speed of the UART, ADC and DAC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tgartlan | 0:23ff2f1bb142 | 1 | #include "mbed.h" |
tgartlan | 0:23ff2f1bb142 | 2 | Timer t; |
tgartlan | 0:23ff2f1bb142 | 3 | Serial pc(USBTX, USBRX); |
tgartlan | 0:23ff2f1bb142 | 4 | AnalogOut Aout(p18); |
tgartlan | 0:23ff2f1bb142 | 5 | AnalogIn Ain(p20); |
tgartlan | 0:23ff2f1bb142 | 6 | |
tgartlan | 0:23ff2f1bb142 | 7 | DigitalOut myled(LED1); |
tgartlan | 0:23ff2f1bb142 | 8 | |
tgartlan | 0:23ff2f1bb142 | 9 | int main() { |
tgartlan | 0:23ff2f1bb142 | 10 | float value = 0; |
tgartlan | 0:23ff2f1bb142 | 11 | unsigned short value2 = 0; |
tgartlan | 0:23ff2f1bb142 | 12 | while(1) { |
tgartlan | 0:23ff2f1bb142 | 13 | t.start(); |
tgartlan | 0:23ff2f1bb142 | 14 | pc.printf("Hello World!\n\r"); |
tgartlan | 0:23ff2f1bb142 | 15 | t.stop(); |
tgartlan | 0:23ff2f1bb142 | 16 | pc.printf("time take was %f seconds\n", t.read()); |
tgartlan | 0:23ff2f1bb142 | 17 | t.reset(); |
tgartlan | 0:23ff2f1bb142 | 18 | myled = 1; |
tgartlan | 0:23ff2f1bb142 | 19 | wait(2); |
tgartlan | 0:23ff2f1bb142 | 20 | myled = 0; |
tgartlan | 0:23ff2f1bb142 | 21 | wait(2); |
tgartlan | 0:23ff2f1bb142 | 22 | pc.printf("Testing ADC time!\n\r"); |
tgartlan | 0:23ff2f1bb142 | 23 | t.reset(); |
tgartlan | 0:23ff2f1bb142 | 24 | t.start(); |
tgartlan | 0:23ff2f1bb142 | 25 | //value = Ain; |
tgartlan | 0:23ff2f1bb142 | 26 | value2 = Ain.read_u16(); |
tgartlan | 0:23ff2f1bb142 | 27 | t.stop(); |
tgartlan | 0:23ff2f1bb142 | 28 | pc.printf("ADC took %f seconds\n", t.read()); |
tgartlan | 0:23ff2f1bb142 | 29 | wait(2); |
tgartlan | 0:23ff2f1bb142 | 30 | pc.printf("Testing DAC time!\n\r"); |
tgartlan | 0:23ff2f1bb142 | 31 | t.reset(); |
tgartlan | 0:23ff2f1bb142 | 32 | t.start(); |
tgartlan | 0:23ff2f1bb142 | 33 | Aout =value; |
tgartlan | 0:23ff2f1bb142 | 34 | t.stop(); |
tgartlan | 0:23ff2f1bb142 | 35 | pc.printf("DAC took %f seconds\n", t.read()); |
tgartlan | 0:23ff2f1bb142 | 36 | wait(2); |
tgartlan | 0:23ff2f1bb142 | 37 | |
tgartlan | 0:23ff2f1bb142 | 38 | } |
tgartlan | 0:23ff2f1bb142 | 39 | } |