PIC16F887
Lesson 10
ADC
PIC16F887
ADC FEATURES
The converter generates a 10-bit binary result
using the method of successive approximation
and stores the conversion results into the ADC
registers (ADRESL and ADRESH)
There are 14 separate analog inputs
The A/D converter converts an analog input
signal into a 10-bit binary number
The minimum resolution or quality of
conversion may be adjusted to various needs
by selecting voltage references
PIC16F887
ADC
PIC16F887
ADC
The operation of A/D converter is in
control of the bits of four registers:
ADRESH Contains high byte of
conversion result
ADRESL Contains low byte of
conversion result
ADCON0 Control register 0
ADCON1 Control register 1.
PIC16F887
ADRESH AND ADRESL REGISTERS
value = read_adc();
Starts the conversion and reads the value from
ADRESH and ADRESL registers
PIC16F887
ADCON0 REGISTER
ADCS1, ADCS0 - A/D Conversion Clock Select bits
ADCS1 ADCS2 CLOCK
0 0 Fosc/2
0 1 Fosc/8
1 0 Fosc/32
1 1 RC *
PIC16F887
ADCON0 REGISTER
setup_adc(mode)
Select clock for ADC with mode is:
ADC_OFF
ADC_CLOCK_DIV_2
ADC_CLOCK_DIV_8
ADC_CLOCK_DIV_32
ADC_CLOCK_INTERNAL
PIC16F887
ADCON0 REGISTER
CHS3-CHS0 - Analog Channel Select bits
set_adc_channel( x )
X : 0-15
PIC16F887
ADCON0 REGISTER
GO/DONE - A/D Conversion Status
bit determines current status of conversion:
1 - A/D conversion is in progress.
0 - A/D conversion is complete.
This bit is automatically cleared by hardware
when the A/D conversion is complete.
ADON - A/D On bit enables A/D converter.
1 - A/D converter is enabled.
0 - A/D converter is disabled.
PIC16F887
ADCON1 REGISTER
ADFM - A/D Result Format Select bit
1 - Conversion result is right justified. Six most
significant bits of the ADRESH are not used.
0 - Conversion result is left justified. Six least
significant bits of the ADRESL are not used.
PIC16F887
ADCON1 REGISTER
VCFG1 - Voltage Reference bit selects negative voltage
reference source needed for the operation of A/D converter.
1 - Negative voltage reference is applied to the Vref- pin.
0 - Power supply voltage Vss is used as negative
voltage reference source.
VCFG0 - Voltage Reference bit selects positive voltage
reference source needed for the operation of A/D converter.
1 - Positive voltage reference is applied to the Vref+ pin.
0 - Power supply voltage Vdd is used as positive
voltage reference source.
PIC16F887
ADCON1 REGISTER
setup_adc_ports(mode )
Configure pins used for ADC. mode can be:
sAN0 : use pin AN0 to be analog pin
…
sAN15 : use AN15 to be analog input
NO_ANALOGS : no use any analog pin
ALL_ANALOG : all AN0 to AN15 are analog
VSS_VDD : use vss and vdd as vref- and vref+
VSS_VREF : vref- = vss, vref+ external source
VREF_VREF : vref- and vref+ are external source
VREF_VDD : vref- from external source, vref+ = vdd
Use “|” between multi-choice
PIC16F887
VREF SELECT
PIC16F887
EXAMPLE
Measure the temperature using LM35
sensor connecting with PIC16F887
though ADC channel 0 and display the
result on the first line of LCD
PIC16F887
ANALYZE
Inside PIC
Vin Dout
LM35 ADC CPU
For simply I choose vref+ = VDD and vref- =
VSS ( VSS_VDD)
When reading ADC, we only get the Dout value
and because it is not the temperature so we
must know how to convert the result to the
temperature.
PIC16F887
ANALYZE
𝒏
𝟐 −𝟏
Vref+
= ? Vin
What we want to know here is
Vin Dout One digit of Dout equate to how
much voltage of Vin. We this
parameter is step size (SS)
SS
Vref- 0
PIC16F887
ANALYZE
1 SS
Dout ? Vin
Vin = Dout*SS
LM35: 10mV/1°C
1°C 0.01V
? t° Vin
t° = = x
t° = x =
PIC16F887
SCHEMATIC
PIC16F887
CODE
PIC16F887
CODE
PIC16F887
CODE
PIC16F887
Test the theory by simulink
PIC16F887
Lesson 10
ADC