Datasheet
2011 Microchip Technology Inc. Preliminary DS39977C-page 255
PIC18F66K80 FAMILY
18.7 Measuring Temperature
with the CTMU
The constant current source provided by the CTMU
module can be used for low-cost temperature
measurement by exploiting a basic property of com-
mon and inexpensive diodes. An on-chip temperature
sense diode is provided on ADC Channel 29 to further
simplify design and cost.
18.7.1 BASIC PRINCIPAL
We can show that the forward voltage (VF) of a P-N
junction, such as a diode, is an extension of the
equation for the junction’s thermal voltage:
where
k is the Boltzmann constant (1.38 x 10
-23
J K
-1
),
T is the absolute junction temperature in kelvin, q is the
electron charge (1.6 x 10
-19
C), IF is the forward current
applied to the diode and
IS is the diode’s characteristic
saturation current, which varies between devices.
Since
k and q are physical constants, and IS is a constant
for the device, this only leaves
T and IF as independent
variables. If
IF is held constant, it follows from the equa-
tion that
VF will vary as a function of T. As the natural log
term of the equation will always be negative, the temper-
ature will be negatively proportional to
VF. In other
words, as temperature increases,
VF decreases.
By using the CTMU’s current source to provide a
constant
IF, it becomes possible to calculate the
temperature by measuring the
VF across the diode.
18.7.2 IMPLEMENTATION
To implement this theory, all that is needed is to con-
nect a regular junction diode to one of the microcon-
troller’s A/D pins (Figure 18-2). The A/D channel
multiplexer is shared by the CTMU and the ADC.
To perform a measurement, the multiplexer is config-
ured to select the pin connected to the diode. The
CTMU current source is then turned on and an A/D
conversion is performed on the channel. As shown in
the equivalent circuit diagram, the diode is driven by
the CTMU at
IF. The resulting VF across the diode is
measured by the ADC. A code snippet is shown in
Example 18-5.
FIGURE 18-4: CTMU TEMPERATURE
MEASUREMENT CIRCUIT
EXAMPLE 18-5: ROUTINE FOR TEMPERATURE MEASUREMENT USING INTERNAL DIODE
V
F
=
kT
q
1n 1 –
I
F
I
S
)
(
PIC
®
Microcontroller
A/D Converter
CTMU
Current Source
MUX
A/D
VF
VF
IF
CTMU
ADC
Equivalent Circuit
Simplified Block Diagram
// Initialize CTMU
CTMUICON = 0x03;
CTMUCONHbits.CTMUEN = 1;
CTMUCONLbits.EDG1STAT = 1;
// Initialize ADC
ADCON0 = 0xE5; // Enable ADC and connect to Internal diode
ADCON1 = 0x00;
ADCON2 = 0xBE; //Right Justified
ADCON0bits.GO = 1; // Start conversion
while(ADCON0bits.G0);
Temp = ADRES; // Read ADC results (inversely proportional to temperature)
Note: The temperature diode is not calibrated or standardized; the user must calibrate the diode to their application.