Using the Timer to test the maximum speed of the ADC and DAC

Dependencies:   mbed

Committer:
tgartlan
Date:
Wed Mar 27 10:45:24 2019 +0000
Revision:
1:6bb2d13644e8
Parent:
0:23ff2f1bb142
Using the timer to test the speed of the ADC and DAC first usingfloats, then using integers. ADC looks to be 10 times slower than DAC.; Not sure if experiment is good since no real difference between float and interger for ADC. Time is 20us for both

Who changed what in which revision?

UserRevisionLine numberNew 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 1:6bb2d13644e8 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 1:6bb2d13644e8 22 pc.printf("Testing ADC time with floats!\n\r");
tgartlan 1:6bb2d13644e8 23 t.reset();
tgartlan 1:6bb2d13644e8 24 t.start();
tgartlan 1:6bb2d13644e8 25 value = Ain;
tgartlan 1:6bb2d13644e8 26 //value2 = Ain.read_u16();
tgartlan 1:6bb2d13644e8 27 t.stop();
tgartlan 1:6bb2d13644e8 28 pc.printf("ADC took %f seconds when using floats\n", t.read());
tgartlan 1:6bb2d13644e8 29 wait(2);
tgartlan 1:6bb2d13644e8 30 myled = 0;
tgartlan 1:6bb2d13644e8 31 wait(2);
tgartlan 1:6bb2d13644e8 32 pc.printf("Testing ADC time using integers!\n\r");
tgartlan 0:23ff2f1bb142 33 t.reset();
tgartlan 0:23ff2f1bb142 34 t.start();
tgartlan 0:23ff2f1bb142 35 //value = Ain;
tgartlan 0:23ff2f1bb142 36 value2 = Ain.read_u16();
tgartlan 0:23ff2f1bb142 37 t.stop();
tgartlan 1:6bb2d13644e8 38 pc.printf("ADC took %f seconds when using integers\n", t.read());
tgartlan 0:23ff2f1bb142 39 wait(2);
tgartlan 1:6bb2d13644e8 40 pc.printf("Testing DAC time suing floats!\n\r");
tgartlan 0:23ff2f1bb142 41 t.reset();
tgartlan 0:23ff2f1bb142 42 t.start();
tgartlan 0:23ff2f1bb142 43 Aout =value;
tgartlan 0:23ff2f1bb142 44 t.stop();
tgartlan 1:6bb2d13644e8 45 pc.printf("DAC took %f seconds when using floats\n", t.read());
tgartlan 0:23ff2f1bb142 46 wait(2);
tgartlan 1:6bb2d13644e8 47
tgartlan 1:6bb2d13644e8 48 pc.printf("Testing DAC time suing integers!\n\r");
tgartlan 1:6bb2d13644e8 49 t.reset();
tgartlan 1:6bb2d13644e8 50 t.start();
tgartlan 1:6bb2d13644e8 51 Aout.write_u16(value2 << 6);
tgartlan 1:6bb2d13644e8 52 t.stop();
tgartlan 1:6bb2d13644e8 53 pc.printf("DAC took %f seconds when using integers\n", t.read());
tgartlan 1:6bb2d13644e8 54 wait(2);
tgartlan 1:6bb2d13644e8 55 while(1);
tgartlan 0:23ff2f1bb142 56
tgartlan 1:6bb2d13644e8 57 //}
tgartlan 0:23ff2f1bb142 58 }