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

Dependencies:   mbed

main.cpp

Committer:
tgartlan
Date:
2019-03-27
Revision:
1:6bb2d13644e8
Parent:
0:23ff2f1bb142

File content as of revision 1:6bb2d13644e8:

#include "mbed.h"
Timer t;
Serial pc(USBTX, USBRX);
AnalogOut Aout(p18);
AnalogIn Ain(p20);

DigitalOut myled(LED1);

int main() {
    float value = 0;
    unsigned short value2 = 0;
    //while(1) {
        t.start();
        pc.printf("Hello World!\n\r");
        t.stop();
        pc.printf("time take was %f seconds\n", t.read());
        t.reset();
        myled = 1;
        wait(2);
        myled = 0;
        wait(2);
        pc.printf("Testing ADC time with floats!\n\r");
        t.reset();
        t.start();
        value = Ain;
        //value2 = Ain.read_u16();
        t.stop();
        pc.printf("ADC took %f seconds when using floats\n", t.read());
        wait(2);
        myled = 0;
        wait(2);
        pc.printf("Testing ADC time using integers!\n\r");
        t.reset();
        t.start();
        //value = Ain;
        value2 = Ain.read_u16();
        t.stop();
        pc.printf("ADC took %f seconds when using integers\n", t.read());
        wait(2);
        pc.printf("Testing DAC time suing floats!\n\r");
        t.reset();
        t.start();
        Aout =value;
        t.stop();
        pc.printf("DAC took %f seconds when using floats\n", t.read());
        wait(2);
     
        pc.printf("Testing DAC time suing integers!\n\r");
        t.reset();
        t.start();
        Aout.write_u16(value2 << 6);
        t.stop();
        pc.printf("DAC took %f seconds when using integers\n", t.read());
        wait(2);
        while(1);
        
    //}
}