Analog To Digital Converter Using ARM7

Introduction

Most of the sensors and transducers are analog such as temperature, humidity, pressure. To interface these sensors to micro-controllers we need to convert the analog output of these sensors to digital.

  • Some microcontroller have inbuilt analog to digital converter.
  • Microcontrollers that don’t have internal ADC, external ADC is used.
  • External ADC : ADC0808,ADC0804.
  • Convert analog pulses to digital i.e., binary 0s and 1s.
  • Types of ADC
    1.Digital Ramp ADC.
    2.Successive Approximation ADC.
    3.Flash ADC.

ADC LPC21xx

  • 10-bit successive approximation analog to digital converter.
  • Input multiplexing among 4 pins or 8 pins.
  • Power-down mode.
  • Measurement range 0 V to VDDA.
  • 10-bit conversion time 2.44 ms(400,000 conversions per second).
  • Burst conversion mode for single or multiple inputs.
  • Optional conversion on transition on input pin or Timer Match signal.

ADC LPC21xx Register Description

  • ADCR :- ADC Control Register
    The ADCR register must be written to select the operating mode before ADC conversion can occur.
  • ADGDR :- ADC Global Data Register
    This register contains the ADC DONE bit and the result of the most recent ADC conversion.
  • ADSTAT:- ADC Status Register
    This register contains DONE and OVERRUN flags for all of the ADC channels, as well as the ADC interrupt flag.
  • ADINTEN :- ADC Interrupt Enable Register
    This register contains enable bits that allow the DONE flag of each ADC channel to be included or excluded from contributing to the generation of an ADC interrupt.
  • ADDR0:- ADC Channel 0 Data Register
    This register contains the result of the most recent conversion completed on channel 0.
  • ADDR1:- ADC Channel 1 Data Register.
    This register contains the result of the most recent conversion completed on channel 1.
  • ADDR2:- ADC Channel 2 Data Register
    This register contains the result of the most recent conversion completed on channel 2.
  • ADDR3:- ADC Channel 3 Data Register.
    This register contains the result of the most recent conversion completed on channel 3.
  • ADDR4:- ADC Channel 4 Data Register.
    This register contains the result of the most recent conversion completed on channel 4.
  • ADDR5:- ADC Channel 5 Data Register
    This register contains the result of the most recent conversion completed on channel 5.
  • ADDR6:- ADC Channel 6 Data Register.
    This register contains the result of the most recent conversion completed on channel 6.
  • ADDR7:- ADC Channel 7 Data Register.
    This register contains the result of the most recent conversion completed on channel 7.

Code

 
 #include <LPC21xx.H>
 unsigned int val=0;
 int main()
 {
 IODIR1=0X00FF0000; // P1.16..23 defined as Outputs
 VPBDIV=0X02; //Set the Pclk to 30 Mhz
 PCONP|=0X00001000; //set PCAD=1
 ADCR|=0X00270601; // Setup A/D: 10-bit AIN0 @ 3MHz
 while(1)
 {
 ADCR|=0X01000000; // Start A/D Conversion
 do
 {
 val=ADDR; // Read A/D Data Register
 }
 //Wait for the conversion to complete
 while((val & 0x80000000)==0);
 //Extract the A/D result
 val=(val>>8 & 0x000003FF)<<14;
 //write the result onto the LED pins
 IOCLR1=~val;
 IOSET1=val;
 }
 }