Professional Documents
Culture Documents
Bai10 ADC
Bai10 ADC
Bai10 ADC
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
value = read_adc();
Starts the conversion and reads the value from
ADRESH and ADRESL registers
PIC16F887
ADCON0 REGISTER
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
ADCON1 REGISTER
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.
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
ANALYZE
Inside PIC
Vin Dout
LM35 ADC CPU
ANALYZE
𝒏
𝟐 −𝟏
Vref+
= ? Vin
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
Lesson 10
ADC