User manual

Table Of Contents
Comparator Peripheral Labs
© 2009 Microchip Technology Inc. DS41369A-page 69
reference, the cycle repeats and the system oscillates. The frequency of this oscillation
is dependant on the RC time constant (
τ = R x C), or the time it takes to discharge the
capacitor to 37% of its initial voltage. As either the resistance or capacitance
decreases, so will
τ effectively increasing the frequency of the oscillator. If the resistor
is replaced with a Negative Temperature Coefficient (NTC) thermistor where resistance
decreases as temperature increases, any temperature change would cause a shift in
resistance with a subsequent shift in the frequency of the oscillator.
This oscillator can be created quite easily by simply initializing the comparator and
nothing more. However, with the addition of some intelligence and some additional
peripherals, a high resolution sensor measurement application can be achieved.
The PIC16F690 features a 16-bit timer/counter peripheral Timer1. This timer can either
use the internal instruction clock (F
OSC/4) as its time base or an external clock source
on the Timer1 Clock Input (T1CKI) pin to increment two 8-bit registers, TMR1H and
TMR1L, to obtain a combined 16-bit result. In this application, the oscillator described
will be used as the Timer1 clock source. Therefore, the TMR1H:TMR1L will increment
with each low-to-high transition effectively counting the number of pulses. The Timer0
peripheral features an interrupt-on-overflow (255-0) that will be used to provide a fixed
time frame in which the TMR1H:TMR1L registers will count. On a Timer0 overflow inter-
rupt, the Timer1 peripheral stops counting and the current value in the upper 4-bits of
TMR1H will be output to four LEDs connected to PORTC pins RC3, RC2, RC1 and
RC0. In order to obtain a usable result, it is important that Timer0 triggers an interrupt
before the TMR1H:TMR1L result overflows. If the temperature to the thermistor
changes, the oscillator frequency will shift resulting in a change in the number of counts
the Timer1 peripheral was able to implement before the fixed Timer0 interrupt with a
different result displayed on the LEDs.
The schematic for this lab is shown in Figure 4-5.
FIGURE 4-5: SCHEMATIC FOR COMPARATOR LAB 3
U2
1
2
3
4
5
6
7
8
9
10
20
19
18
17
16
15
14
13
12
11
J9
J8
C12IN0-
C1OUT
R1
100K
D1
1N4148
V
SS
C
1
1μF
V
SS
R3
10K
NTC thermistor
R7
470
LED4
V
SS
RC0
RC1
RC2
T1CKI
RC3
R6
470
LED3
V
SS
R5
470
LED2
V
SS
R4
470
LED1
V
SS
R2
10K
V
SS