User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 78 © 2009 Microchip Technology Inc.
The Initialize() configures the peripherals as follows:
•Ports
- Configure pin 13 as an analog input (using TRISB4).
- Clear the PORTC register.
- Configure RC0, RC1, RC2 and RC3 pins as digital output.
•ADC
- Select ADC conversion clock F
RC
.
- Configure voltage reference using VDD.
- Select channel 10 as the ADC input channel (Pin 13: RB4/AN10).
- Select result format left justified (10-bit result in ADRESH<7:0> and
ADRESL<7:6>).
- Turn on ADC module.
Next, the Get_Inputs() performs an ADC on the voltage present on pin 13. The
internal capacitor connected to the input of the ADC peripheral needs time to charge to
the voltage present on the pin. Therefore, software will need to implement a short delay
to allow for this charging time. The ADC Module section “A/D Acquisition Require-
ments” of the data sheet goes into great detail and includes an equation for selecting
an appropriate acquisition time. For the purposes of this lab, a simple 1mS delay
should be more than sufficient. These parameters become important in high-speed
applications where every μS counts.
The GO/DONE
bit in ADCON0 is used to start the ADC process when set to1’. This
bit also serves as a flag that indicates when the ADC is completed (GO/DONE
= 0).
Therefore, the Get_Inputs() initiates an ADC by setting GO/DONE
then sits and
waits for the bit to clear indicating a completed conversion.
The software flowchart for the Get_Inputs() is shown in Figure 5-3.
Note: The ADC conversion clock is the time that will be used to convert the analog
voltage present on pin 13 to a 10-bit value in the ADRESH:ADRESL regis-
ters. It takes 11 of these conversion clock cycles to perform a complete
ADC. If the conversion clock period is insufficient, an incomplete ADC result
will occur. The electrical specifications for the PIC16F690 state that the
conversion clock must have a period of at least 1.5
μSeconds or a fre-
quency of approximately 667 kHz. The ADC Module section of the data
sheet specifies acceptable conversion clock frequencies depending on the
main oscillator used to drive the microcontroller and should be referenced.
In this application, a dedicated internal oscillator for the ADC module is
used ensuring a conversion clock frequency of between 2-6
μSeconds.
(see Table 17-16 in Section 17 of the PIC16F690 Data Sheet).