SEARCH
TOOLBOX
LANGUAGES
modified on 14 August 2014 at 15:55 ••• 10,841 views

05-05 DataConversion

From Manuals

Revision as of 15:55, 14 August 2014 by Support (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This example reads an Analog to Digital Converter (ADC) and outputs it to a Digital to Analog Converter(DAC).

/*Program Example 5.5: Inputs signal through ADC, and outputs to DAC.
View DAC output on oscilloscope. To demonstrate Nyquist, connect variable
frequency signal generator to ADC input. Allows measurement of conversion
times, and explores Nyquist limit.
                                                                           */
#include "mbed.h"
AnalogOut Aout(DAC0);      //defines analog output on Pin DAC0
AnalogIn Ain(A0);        //defines analog input on Pin A0 
DigitalOut test(p21);
float ADCdata;

int main() {
  while(1) {
    ADCdata=Ain;   //starts A-D conversion, and assigns analog value to ADCdata
    test=1;        //switch test output, as time marker
    test=0;
    Aout=ADCdata;  // transfers stored value to DAC, and forces a D-A conversion
    test=1;        //a double pulse, to mark the end of conversion
    test=0;
    test=1;
    test=0;
    //wait(0.001);    //optional wait state, to explore different cycle times
   }
}


BAM210
Schematic for example 05-05