Datasheet
PIC18F97J94 FAMILY
DS30575A-page 522 2012 Microchip Technology Inc.
26.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.
26.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 I
S 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 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.
26.7.2 IMPLEMENTATION
To implement this theory, all that is needed is to
connect a regular junction diode to one of the micro-
controller’s A/D pins (Figure 26-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 in Figure 26-4, the diode
is driven by the CTMU at I
F. The resulting VF across the
diode is measured by the A/D. A code snippet is shown
in Example 26-5.
FIGURE 26-4: CTMU TEMPERATURE
MEASUREMENT CIRCUIT
EXAMPLE 26-5: CTMU ROUTINE FOR TEMPERATURE MEASUREMENT USING INTERNAL DIODE
VF =
kT
q
1n 1 –
I
F
IS
)
(
PIC
®
Microcontroller
A/D Converter
CTMU
Current Source
MUX
A/D
VF
VF
IF
CTMU
A/D
Equivalent Circuit
Simplified Block Diagram
// Initialize CTMU
CTMUICON = 0x03;
CTMUCONbits.CTMUEN = 1;
CTMUCON3bits.EDG1STAT = 1;
ADCON1Hbits.FORM = 0; // Right Justified
ADCON1Hbits.MODE12 = 0; // 12-Bit A/D Operation
ADCHS0Lbits.CHOSA = 0x18; // Enable ADC and connect to Internal diode
ADCON1Hbits.ADON = 1; // Enable ADC
Note: The temperature diode is not calibrated or standardized; the user must calibrate the diode to their application.