Module 13: Interfacing ADC Introduction ADC Programming DAC Programming Sensor Interfacing
Introduction
ADC Devices o Analog-to-digital converters (ADC) are among the most widely used devices for data acquisition. o Digital computer use binary (discrete), but physical world everything is analog (continuous). o Thus a device called transducer (sensor) is needed to convert physical quantities (i.e. temperature, pressure, etc) to electrical (voltage/current) signal. o ADC is used to translate the analog signals to digital signal.
ADC Characteristics o In ATmega32, an n-bit ADC is used to translate the analog signals to digital signal so that micro-p can read and process them. o Some of the major characteristics of ADC that we need to know. 1. Resolution ADC has n-bit resolution (8, 10, 12, 16..) Higher-resolution ADCs provide smaller step size- smallest change can be discerned by an ADC. Although ADC resolution is fixed, but the step size can be controlled by Vref.
2. Conversion time ADC Characteristics Conversion time is time ADC takes to convert the analog input to digital number. 3. Vref Vref is input voltage used for reference voltage. The voltage connected to this pin, along with ADC resolution, will dictate the step size. 4. Digital data output In an 8-bit ADC, we have an 8-bit digital data output of D0-D7. Thus, Dout:
ADC Characteristics 5. Parallel vs Serial ADC Parallel ADC 8 or more pins dedicated to bring out the binary data. Serial ADC Only one pin for data out.
ADC Characteristics 6. Analog input channel Many data acquisition application need more than one ADC. Thus, ADC chips comes with 2, 4, 8 or even 16 channels on a single chip. 7. Successive approximate ADC Widely used to convert analog input to digital input. Hass thee main components: successive approximation register (SAR); comparator; control unit.
ADC Programming
ATmega32 ADC Features o ADC peripheral of ATmega32 has the following characteristics: 1. 10-bit ADC. 2. Has 8 analog input channels, 7 differential input channels and 2 differential input channel with optional gain of 10x and 200x. 3. The converted output binary data is held by two special function registers: ADCL (A/D Result Low) & ADCH (A/D Result High). 4. Since ADCH:ADCL gives us 16-bit and ADC data out only 10-bit, thus remaining 6-bit is unused. 5. Three option for Vref. Vref connected to AVCC (analog Vcc); internal 2.6V reference;, external AREF pin. 6. Conversion time dictated by crystal frequency connected to XTAL and ADPS0:2 bits.
ADC Connection & Programming o Used inductor and capacitor in order to get a stable voltage source to the AVCC pin. o In ATmega32, five major registers are associated with ADC: 1. ADCH (high data) 2. ADCL (low data) Store result after conversion 3. ADCSRA (ADC Control and Status Register) 4. ADMUX (ADC multiplexer selection register) 5. SPIOR (Special Function I/O Register)
o There are three option for Vref selection: 1. AREF pin 2. AVCC pin 3. Internal 2.56V o The REFS1:0 bit 7:6 in ADMUX will determine the Vref. ADMUX Register
ADMUX Register o The MUX4:0 bit 4:0 in ADMUX will determine the analog channel and gain selection to be used. o Either single-ended or differential input can be selected to be converted to digital data. o If single-ended is selected, you can chooses input channel among ADC0 to ADC7 single pin is used as analog line, and GND as common ground.
ADMUX Register o If differential input is selected, you can chooses input channel as well as the op-amp gain: 1x, 10x, 200x.
ADMUX Register o The ADLAR bit 5 in ADMUX will determine either the left bits or the right bits of ADCH:ADCL registers used to store the result. o AVRs have a 10-bit ADC, but since two 8-bit registers dedicated to ADC result (ADCH:ADCL), thus 6 bits are unused and need to select position which bits are used and not. o Set One 1 : left justified. o Set Zero 0 : right justified.
ADCH:ADCL Registers o ADCH:ADCL registers are used to store the results after the A/D conversion is complete. o Since the ADC is 10-bit while ADCH:ADCL are 16-bit, we need to set the ADLAR bit of the ADMUX for making it right-justified or left-justified.
ADCSRA Register o The ADCSRA register is the status and control register of ADC.
ADCSRA Register o The ADPS2:0 Bit 2:0 : ADC Prescaler/Conversion time o These bits will determine the division factor between XTAL frequency and the input clock of ADC. o To select conversion time, we can select any of Fosc/2, Fosc/4, Fosc/8, Fosc/16, Fosc/32, Fosc/64 or Fosc/128 for ADC clock. o Fosc is the speed of the crystal frequency connected to AVR. o For the AVR, ADC requires an input clock frequency less than 200 KHz for the maximum accuracy.
ADCSRA Register
Steps Programming the ADC using Polling 1. Make the pin for selected ADC channel as an input pin. 2. Turn ON ADC module, since its disable upon power-on-reset to save power. 3. Select conversion speed ADPS2:0 4. Select voltage reference (REFS1:0) and ADC input channel (MUX4:0) in ADMUX register. 5. Activate start conversion bit write 1 to ADSC of ADCSRA register. 6. Wait for the conversion to be completed by polling the ADIF bit of ADCSRA register. 7. After ADIF = HIGH 1, read ADCH:ADCL to get digital data output. * read ADCL before ADCH. 8. If want to read the selected channel again, go back to step 5. 9. If want to select another Vref source or input channel, go back to step 4.
Steps Programming the ADC using Polling: Example
Steps Programming the ADC using Polling: Example
Steps Programming the ADC using Interrupt 1. Initialize interrupt vector table. 2. Make the pin for selected ADC channel as an input pin. 3. Turn ON ADC module, since its disable upon power-on-reset to save power. 4. Select conversion speed ADPS2:0 5. Select voltage reference (REFS1:0) and ADC input channel (MUX4:0) in ADMUX register. 6. Activate start conversion bit write 1 to ADSC of ADCSRA register. 7. Set ADIE = HIGH (A/D interrupt enable). Upon completion of conversion, ADIF changes to HIGH. 8. If ADIF = HIGH 1, it force CPU to jump to ADC interrupt handler to read ADCH:ADCL to get digital data output. * read ADCL before ADCH. 9. If want to read the selected channel again, go back to step 5. 10. If want to select another Vref source or input channel, go back to step 4.
Steps Programming the ADC using Interrupt
Steps Programming the ADC using Interrupt
DAC Programming
Digital-to-Analog Converter (DAC) o DAC widely used to convert digital pulses to analog signals. o There are two methods of creating DAC: 1. Binary weighted 2. R/2R ladder to achieve higher degree of precision. (DAC0808).
DAC0808 o In DAC0808, the digital inputs are converted to current (Iout), and by connecting resistor to the Iout, we convert the result to voltage. o Iref is the input current that must be applied to pin 14.
Sensor Interfacing