Rob Toulson / Mbed 2 deprecated PE_05-05_DataConversion

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*Program Example 5.5: Inputs signal through ADC, and outputs to DAC. 
00002 View DAC output on oscilloscope. To demonstrate Nyquist, connect variable 
00003 frequency signal generator to ADC input. Allows measurement of conversion 
00004 times, and explores Nyquist limit.
00005                                                                             */
00006 #include "mbed.h"
00007 AnalogOut Aout(p18);      //defines analog output on Pin 18
00008 AnalogIn Ain(p20);        //defines analog input on Pin 20
00009 DigitalOut test(p5);
00010 float ADCdata;
00011 
00012 int main() {
00013   while(1) {
00014     ADCdata=Ain;   //starts A-D conversion, and assigns analog value to ADCdata
00015     test=1;        //switch test output, as time marker
00016     test=0;
00017     Aout=ADCdata;  // transfers stored value to DAC, and forces a D-A conversion 
00018     test=1;        //a double pulse, to mark the end of conversion 
00019     test=0;     
00020     test=1;
00021     test=0;             
00022     //wait(0.001);    //optional wait state, to explore different cycle times
00023    }
00024 }
00025