0% found this document useful (0 votes)
48 views31 pages

Module 3 Adc

Uploaded by

giri keshav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views31 pages

Module 3 Adc

Uploaded by

giri keshav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

ANALOG TO DIGITAL CONVERTER

Microcontrollers are very useful especially when it


comes to communicating with other devices, such as
sensors, motors, switches, memory, and even
another microcontroller.
As we all know many interface methods have been
developed over years to solve the complex problems
of balancing needs of features, cost, size, power
consumption, reliability, etc. but the ADC Analog-to-
Digital converter remains famous among all.
Using this ADC we can connect any type of Analog
sensor.
The A/D module has high and low-voltage reference
input that is software selectable to some combination of
VDD, VSS, RA2 or RA3.
With 5v as the Vref the resolution of Pic16f877a ADC
can be determined as below:
Resolution of ADC = Vref / (2^{10}-1)
= 5/1023
=0.004887
= 4.887mv
(The ADC resolution is defined as the smallest
incremental voltage that can be recognized and thus
causes a change in the digital output.)
ADC BLOCK DIAGRAM

It is a 10 bit ADC module.


That means an analog input converted into a
corresponding 10-bit digital output.
A sample and hold circuit to acquire the input
voltage, Vin.
A voltage comparator that compares Vin to the DAC
output. It outputs the comparison result to the
successive approximation register (SAR).
A successive approximation register designed to
supply the approximated digital code of Vin to the
internal DAC.
An internal reference DAC that supplies the
comparator with an analog voltage equivalent of the
digital code supplied by the SAR.
A register ADRES to store the ADC result upon-end
of-conversion(EOC).
PIC16F877A ADC pins
PIC16F877A has an inbuilt 10 bit Successive
Approximation ADC which is multiplexed among 8 input
pins.
The below table shows the ADC input pins multiplexed
with other GPIO pins.
The ADC pin can be enabled by configuring the
corresponding ADCON1 register.
When the ADC function is selected for a pin ,then other
Digital signals are disconnected from the ADC input pins.
ADC Channel PIC16f877A Pin Function
Pin
Channel 0 RA0 (Port A) AN0
Channel 1 RA1 (Port A) AN1
Channel 2 RA2 (Port A) AN2/VREF-
Channel 3 RA3 (Port A) AN3/VREF+
Channel 4 RA5 (Port A) AN4
Channel 5 RE0 (Port E) AN5
Channel 6 RE1 (Port E) AN6
Channel 7 RE2 (Port E) AN7
ADC REGISTERS

A/D has 4 main registers:


A/D Control Register 0 (ADCON0)
A/D Control Register 1 (ADCON1)
A/D Result High Register (ADRESH)
A/D Result Low Register (ADRESL)
Register Description
ADCON0 Used to Turn ON the ADC, Select the
Sampling Freq and also Start the
conversion.
ADCON1 Used to configure the GPIO pins for
ADC
ADRESH Holds the higher byte of ADC result
ADRESL Holds the lower byte of ADC result
A/D Control Register 0 (ADCON0)
This register uses to select input channels and
control conversion process.
It also controls the operation of A/D Converter.
ADON: A/D On bit
1 = A/D converter module is powered up
0 = A/D converter module is shut-off and consumes no
operating current
GO/DONE: A/D Conversion Status bit
When ADON = 1:
1 = A/D conversion in progress (setting this bit starts the A/D
conversion which is automatically cleared by hardware when the
A/D conversion is complete)
0 = A/D conversion not in progress

CHS2:CHS0: bits are the channel select bits from 7(0-


7) variable channels which are multiplexed with digital
I/O pins.
CHS2-CHS0:Analog Channel Select bits
000 = Channel 0 (AN0)
001 = Channel 1 (AN1)
010 = Channel 2 (AN2)
011 = Channel 3 (AN3)
100 = Channel 4 (AN4)
101 = Channel 5 (AN5)
110 = Channel 6 (AN6)
111 = Channel 7 (AN7)

ADCS1:ADCS0: Configures the clock option for ADC


peripheral. The system clock is divided to configure
the clock for AD conversion configurations for different
clocks.
ADCS2-ADCS0:A/D Conversion Clock Select bits
A/D Control Register 1 (ADCON1)
The ADCON1 register, shown below, configures the
functions of the port pins i.e Used to configure the GPIO
pins for ADC. The port pins can be configured as analog
inputs (RA3 can also be the voltage reference) or as
digital I/O.
ADFM: A/D Result Format Select bit
1 = Right justified. Six (6) Most Significant bits of ADRESH are read
as ‘0’.
0 = Left justified. Six (6) Least Significant bits of ADRESL are read
as ‘0’.

ADCS2: A/D Conversion Clock Select bit


PCFG3-PCFG0: A/D Port Configuration Control bits
A/D Result High Register (ADRESH) &
A/D Result Low Register (ADRESL)
The ADRESH: ADRESL registers contain
the 10-bit result of the A/D conversion.
When the A/D conversion is complete,
the result is loaded into this A/D Result
register pair, the GO/DONE bit
(ADCON0<2>) is cleared and the A/D
interrupt flag bit ADIF is set.
Steps to follow for Analog to Digital Conversion
To do an A/D Conversion, follow these steps:
1. Configure the A/D module:
Configure analog pins/voltage reference and digital I/O
(ADCON1)
Select A/D input channel (ADCON0)
Select A/D conversion clock (ADCON0)
Turn on A/D module (ADCON0)

2. Configure A/D interrupt (if desired):


• Clear ADIF bit
• Set ADIE bit
• Set PEIE bit
• Set GIE bit
3. Wait the required acquisition time.
4. Start conversion:
Set GO/DONE bit (ADCON0)
5. Wait for A/D conversion to complete by either:
Polling for the GO/DONE bit to be cleared
(interrupts disabled);
Waiting for the A/D interrupt
6. Read A/D Result register pair (ADRESH: ADRESL),
clear bit ADIF if required.
• ADC module of PIC microcontroller have usually 5 input
for 28 pin devices and 8 inputs for 40 pin devices.
• The conversion of analog signal to PIC ADC module
results in corresponding 10 bit digital number.
• PIC ADC module has software selectable high and low
voltage reference input to some combination of VDD,
VSS, RA2 and RA3.
• In the following example project we will convert analog
input to channel 1 to 10 bit digital number with low
voltage reference (Vref-) 0v and high voltage reference
(Vref+) 5V.
• The output will be displayed using 10 LEDs.
• change the Vref- and Vref+ by configuring the ADCON1
register.
0v = 0000000000
5v = 1111111111
• Resolution = (Vref+ – Vref-)/(1024-1)
(as it is 10 bit ADC)
= 5/1023
= 4.887 mV
Thus it means that for a change in 4.887mV, the
binary output changes by 1.
ADCON1= 80H= 10000000 BINARY
1 = Right justified. Six (6) Most Significant bits of
ADRESH are read as ‘0’.
TRISC=3FH
00111111
• Though, the MikroC Pro for microcontroller
has got a built-in library function termed as
ADC_Read (), by default, uses the internal RC
CLK for ADC operation.
• So no need to reset the ADCON1 register.
• ANSEL= 0x04= 0000 0100
• The ANSEL and ANSELH registers are used to
configure the input mode of an I/O pin to
analog or digital.
• The rule is: To configure a pin as an analog
input, the appropriate bit of the ANSEL or
ANSELH registers must be set (1).
• To configure a pin as a digital input/output, the
appropriate bit must be cleared (0).

You might also like