- What is ADC?
- Characteristics of ADC
- Features of ADC
- ADCON0 register
- ADCON1 and ADCON2 register
- Calculating Analog to Digital conversion time
- Steps to program A/D converter
What is ADC?
ADC stands for Analog to Digital converter. ADC devices are the most widely used devices for data acquisition.
The computer understands the binary values but in the real world, everything is available in analogue values. Temperature, pressure, humidity, velocity etc are few examples of physical quantities that we deal with in everyday life.
Therefore. we need an Analog-to-digital converter to translate the Analog signal to digital numbers so that the microcontroller can read and process them.
The ADC is widely used in data acquisition, in recent years an increasing number of microcontrollers have an on-chip ADC peripheral just like timer and USART.
An on-chip ADC eliminates the need for external ADC which leaves more pins for other input-output activities.
Characteristics of ADC
1. Resolution
2. Conversion time
3. Vref
4. Digital data output
In the 10-bit ADC of the PIC18 chip, we have 10-bit of digital data output.
To calculate the output voltage we use the following formula:
Dout= Vin/stepsize
where,
Dout = digital data output (in decimal)
Vin = Analog input voltage
Example:-
For the 10-bit ADC, we have Vref = 5V. Calculate the D0-D9 output if the Analog input is 1.7V.
solve
step size = 5/1024 = 4.88mV
Dout = 1.7V/4.88x10^3 V
Dout = 348.360 = 348 (decimal)
5. Analog input channel
Features of ADC
- It is a 10-bit ADC.
- It can have 5 to 15 channels of Analog input channels, depending on the family member.
- The converted output data is held by two special function register ADRESL and ADRESH.
- The ADRESL and ADRESH register give us 16-bits and the ADC output data is 10-bit wide hence 6-bit are unused.
- We can use Vdd the voltage source of the PIC18 itself as the Vref or connecting it to an external voltage source for Vref.
- The conversion time is decided by the Fosc of crystal frequency connected to the OSC pins. The Fosc for PIC18 is as high as 40MHz, the conversion time cannot be shorter than 1.6ms.
- It allows the implementation of differential Vref voltage.
ADCON0 register
This register is used to set the conversion time and select the Analog input channel. To reduce the power consumption of PIC18, the ADC feature is turned off when the microcontroller is powered up. We need to turn on the ADC using the ADCON0 register.
ADCON1 and ADCON2 registers
Calculating A/D conversion time
We can set A/D conversion time with the help of both ADCON0 and ADCON1 register. The conversion is defined in terms of Tad. Where Tad is the conversion time per bit.
To calculate the Tad we need to select a conversion clock source of Fosc/2, Fosc/4, Fosc/8, Fosc/16, Fosc/32, Fosc/64. Where Fosc is the speed of the crystal frequency connected to the PIC18 chip.
For PIC18 the conversion time is 12 times the Tad and Tad cannot be faster than 1.6ms.
To use the internal RC oscillator for the conversion clock source the Tad is typically 4 to 6 micro-seconds and the conversion time is 12x6us = 72us.
Another important factor is timing acquisition (Tacq). After an (A/D) channel is selected we must allow some time for the sample and hold capacitor (C hold) to charge fully to the input voltage. It is only after the elapsing of this acquisition time the A/D conversion can be started.
Steps to program the A/D converter of PIC18
- Turn on the ADC module of the PIC18 because it is disabled upon power-on reset to save power, we can use ADCON0, ADON instruction.
- Make the PIN for the selected ADC channel on the input pin. We use TRISAx or TRISEx where x is the channel number.
- Select voltage reference and Analog input channels, we use ADCON0 and ADCON1.
- Select the conversion speed, we use register ADCON0 and ADCON1.
- Wait for the required acquisition time.
- Activate the start conversion bit of GO/DONE.
- Wait for the conversion to be completed by polling the end-of-conversion (GO/DONE) bit.
- After the GO/DONE bit has gone LOW read the ADRESL and ADRESH register to get the digital data output.
- Go back to step5.
CONNECT WITH US