User manual
Robotics experiment with PIC microcontroller l 61
5.3 ADC configuration
For using the ADC module of PIC16F887 microcontroller the following functions
must be considered:
l
Port configuration
l
Channel selection
l
ADC voltage reference selection
l
ADC conversion clock source
l
Results formatting
5.4.1 Port configuration
The ADC can be used to convert both analog and digital signals. When convert-
ing analog signals, the I/O pin should be configured for analog by setting the associated
TRIS and ANSEL bits.
5.4.2 Channel selection
The CHS bits of the ADCON0 register determine which channel is connected to the
sample and hold circuit. When changing channels, a delay is required before starting the
next conversion.
5.4.3 ADC Voltage reference
The VCFG bits of the ADCON0 register provide independent control of the positive
and negative voltage references. The positive voltage reference can be either Vdd or
an external voltage source. Likewise, the negative voltage reference can be either Vss or
an external voltage source.
For the RBX-877V2.0 Robot Controller board will select the positive reference to
+5V and negative reference at ground or Vss.
5.4.4 Conversion Clock
The source of the conversion clock is software selectable via the ADCS bits of the
ADCON0 register. There are four possible clock options:
l
F
OSC
/2 : for 20MHz clock, T
AD
= 100ns
l
F
OSC
/8 : for 20MHz clock, T
AD
= 400ns
l
F
OSC
/32 : for 20MHz clock, T
AD
= 1.6µs
l
F
RC
(dedicated internal oscillator) : T
AD
= 2 to 6µs
The time to complete one bit conversion is defined as T
AD
. One full 10-bit conver-
sion requires 11 T
AD
periods.