Datasheet
2010-2012 Microchip Technology Inc. DS39977F-page 249
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 (V
F
) 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), I
F
is the forward current
applied to the diode and
I
S
is the diode’s characteristic
saturation current, which varies between devices.
Since
k and q are physical constants, and I
S
is a constant
for the device, this only leaves
T and I
F
as independent
variables. If
I
F
is held constant, it follows from the equa-
tion that
V
F
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
V
F
. In other
words, as temperature increases,
V
F
decreases.
By using the CTMU’s current source to provide a
constant
I
F
, it becomes possible to calculate the
temperature by measuring the
V
F
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
I
F
. The resulting V
F
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
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
V
F
V
F
I
F
CTMU
A/D
Equivalent Circuit
Simplified Block Diagram
// Initialize CTMU
CTMUICON = 0x03;
CTMUCONHbits.CTMUEN = 1;
CTMUCONLbits.EDG1STAT = 1;
// Initialize ADC
ADCON0 = 0x75; // 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.