User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 64 © 2009 Microchip Technology Inc.
2. Copy/paste the code in Example 4-2 into the main() section labeled:
//ADD MAIN CODE HERE
EXAMPLE 4-2: MAIN() CODE FOR COMPARATOR LAB 1
3. Compile the project. There should be no errors.
4.2.4.4 TESTING THE APPLICATION
Program the PIC16F690. The LED connected to the C1OUT pin should light when the
voltage present on the C12IN0- pin is less than the 2.5V present on the C1IN+ pin and
turn off when the 2.5V is exceeded.
The solution for this project is located in the
C:\PICDEM_Lab\Comparator_Labs\Comparator_Lab1\solution directory.
4.2.5 Lab 2: Using the Comparator Voltage Reference
4.2.5.1 NEW REGISTERS USED IN THIS LAB
To configure the peripherals used in this lab, the following registers are used:
1. Voltage Reference Control Register: VRCON (Register 8-5 in Section 8 of the
PIC16F690 Data Sheet).
- Enables either the Comparator Voltage Reference or the 0.6V constant
reference as the non-inverting reference input to Comparator C1 or
Comparator C2.
- Selects either a High or Low resolution 16-level voltage range.
- Enable a 0.6V reference.
- Uses three bits to configure the reference voltage level.
4.2.5.2 OVERVIEW
This lab expands on Lab 1 by utilizing the internal Comparator Voltage Reference
(CV
REF) feature on the PIC16F690. The CVREF provides an internally generated
voltage reference that can be used by the Comparator 1 non-inverting reference input
so that external components are not needed such as the resistor voltage divider used
in the previous lab. The CV
REF features:
Independent comparator operation
Two 16-level voltage ranges
Ratiometric with V
DD
Initialize(); //Initialize the relevant registers
while(1);
Note: The inclusion of the while loop forces the microcontroller to sit and wait at
a “known” instruction. At start-up, the contents of the program memory are
unknown. Without the while loop, the microcontroller will continue to run
through each address in program memory executing whatever resides at a
particular address. This could have adverse effects on the application.
Note: This application uses two pins that are used during the programming pro-
cess (ICSPDATA and ICSPCLK). The jumper wires connecting these pins
to the application circuit may need to be disconnected while programming
if there are problems with the MPLAB IDE connecting to the PIC16F690.