Ad Code

What is the Internal ADC pic18f chips?



Hello... In today's article, we will talk about the internal ADC pic18f. 
We will cover the article on the following points:
  • 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

ADC pic18f has an n-bit resolution, where n = 8,10,12,13 or even 24 bits.
The higher the resolution, the smaller the step size. Stepsize is the smallest change that can be recognized by an ADC. 

The resolution of an ADC pic18f is decided at the time of its design and cannot be changed, but we can control the step size with the help of the Vref.

2. Conversion time

The time is taken by the ADC to convert the Analog input to a digital number is called the conversion time.

3. Vref 

It is an input voltage used for reference voltage. The voltage connected to the pin along with the resolution of the ADC chip decides the stepsize.


Example:-   

If the Analog input range needs to be 0 to 5V. Vref is connected to 5V that gives 5V/1024 = 4.88mV for the stepsize of a 10-bit ADC.

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

The PIC18 microcontroller chip comes with 5 to 15 ADC channels, depending on the family member this channel allowing us to monitor multiple quantities such as temperature, pressure, heat, and so on.

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.
                                            Vref = Vref(+)  -  Vref(-)

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

This register is used to select the Vref voltage among other things. This register also used for making it right justified or left justified because we need only 10 bits of the 16.


The PORTA (RA0, RA1, RA2, RA3 and RA5) and PORTE (RE0, RE1, RE2) are used for Analog input channels.
For PCFG = 0110 we can use all the pins of PORTA as the digital I/O. The default is PCFG = 0000 which allows us to use all the 8 pins for Analog inputs.


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

  1. 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.
  2. Make the PIN for the selected ADC channel on the input pin. We use TRISAx or TRISEx where x is the channel number.
  3. Select voltage reference and Analog input channels, we use ADCON0 and ADCON1.
  4. Select the conversion speed, we use register ADCON0 and ADCON1.
  5. Wait for the required acquisition time.
  6. Activate the start conversion bit of GO/DONE.
  7. Wait for the conversion to be completed by polling the end-of-conversion (GO/DONE) bit.
  8. After the GO/DONE bit has gone LOW read the ADRESL and ADRESH register to get the digital data output.
  9. Go back to step5.