English
Language : 

PIC18F26K80-I Datasheet, PDF (249/622 Pages) Microchip Technology – 28/40/44/64-Pin, Enhanced Flash Microcontrollers with ECAN™ and nanoWatt XLP Technology
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 A/D 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:
( ) VF =
kT
q
1n
1–
IF
IS
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 A/D.
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 A/D. A code snippet is shown in
Example 18-5.
FIGURE 18-4:
CTMU TEMPERATURE
MEASUREMENT CIRCUIT
Simplified Block Diagram
PIC® Microcontroller
Current Source CTMU
A/D Converter
MUX
A/D
VF
Equivalent Circuit
IF
CTMU
A/D
VF
EXAMPLE 18-5: ROUTINE FOR TEMPERATURE MEASUREMENT USING INTERNAL DIODE
// Initialize CTMU
CTMUICON = 0x03;
CTMUCONHbits.CTMUEN = 1;
CTMUCONLbits.EDG1STAT = 1;
// Initialize ADC
ADCON0 = 0x75;
ADCON1 = 0x00;
ADCON2 = 0xBE;
// Enable ADC and connect to Internal diode
//Right Justified
ADCON0bits.GO = 1;
while(ADCON0bits.G0);
Temp = ADRES;
// Start conversion
// 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.
 2010-2012 Microchip Technology Inc.
DS39977F-page 249