Rob Toulson / Mbed 2 deprecated PE_05-05_DataConversion

Dependencies:   mbed

Committer:
robt
Date:
Mon Oct 15 21:21:42 2012 +0000
Revision:
0:84f45646bc00
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:84f45646bc00 1 /*Program Example 5.5: Inputs signal through ADC, and outputs to DAC.
robt 0:84f45646bc00 2 View DAC output on oscilloscope. To demonstrate Nyquist, connect variable
robt 0:84f45646bc00 3 frequency signal generator to ADC input. Allows measurement of conversion
robt 0:84f45646bc00 4 times, and explores Nyquist limit.
robt 0:84f45646bc00 5 */
robt 0:84f45646bc00 6 #include "mbed.h"
robt 0:84f45646bc00 7 AnalogOut Aout(p18); //defines analog output on Pin 18
robt 0:84f45646bc00 8 AnalogIn Ain(p20); //defines analog input on Pin 20
robt 0:84f45646bc00 9 DigitalOut test(p5);
robt 0:84f45646bc00 10 float ADCdata;
robt 0:84f45646bc00 11
robt 0:84f45646bc00 12 int main() {
robt 0:84f45646bc00 13 while(1) {
robt 0:84f45646bc00 14 ADCdata=Ain; //starts A-D conversion, and assigns analog value to ADCdata
robt 0:84f45646bc00 15 test=1; //switch test output, as time marker
robt 0:84f45646bc00 16 test=0;
robt 0:84f45646bc00 17 Aout=ADCdata; // transfers stored value to DAC, and forces a D-A conversion
robt 0:84f45646bc00 18 test=1; //a double pulse, to mark the end of conversion
robt 0:84f45646bc00 19 test=0;
robt 0:84f45646bc00 20 test=1;
robt 0:84f45646bc00 21 test=0;
robt 0:84f45646bc00 22 //wait(0.001); //optional wait state, to explore different cycle times
robt 0:84f45646bc00 23 }
robt 0:84f45646bc00 24 }
robt 0:84f45646bc00 25