Microchip Technology TMPSNSRD-TCPL1 Hoja De Datos

Descargar
Página de 52
© 2009-2012 Microchip Technology Inc.
DS22203C-page 25
MCP9804
5.1.3.1
T
A
 Bits to Temperature Conversion
To convert the T
A
 bits to decimal temperature, the
upper three boundary bits (T
A
<15:13>) must be
masked out. Then, determine the SIGN bit (bit 12) to
check positive or negative temperature, shift the bits
accordingly, and combine the upper and lower bytes of
the 16-bit register. The upper byte contains data for
temperatures greater than +32°C while the lower byte
contains data for temperature less than +32°C, includ-
ing fractional data. When combining the upper and
lower bytes, the upper byte must be right-shifted by
4 bits (or multiply by 2
4
) and the lower byte must be left-
shifted by 4 bits (or multiply by 2
-4
). Adding the results
of the shifted values provides the temperature data in
decimal format (see 
).
The temperature bits are in two’s compliment format,
therefore, positive temperature data and negative tem-
perature data are computed differently. 
shows the temperature computation. The example
instruction code, outlined in 
, shows the
communication flow; also se
 for the timing
diagram.
EQUATION 5-1:
BYTES TO 
TEMPERATURE 
CONVERSION
EXAMPLE 5-1:
SAMPLE INSTRUCTION CODE
Where:
T
A
= Ambient Temperature (°C)
UpperByte = T
A
 bit 15 to bit 8
LowerByte = T
A
 bit 7 to bit 0
Temperature T
A
 
 
0°C
Temperature 
< 0°C
T
A
UpperByte
2
4
LowerByte
2
4
×
+
×
(
)
=
T
A
256
UpperByte
2
4
LowerByte
2
4
×
+
×
(
)
=
i2c_start();
// send START command
i2c_write (AddressByte & 0xFE);
//WRITE Command 
)
//also, make sure bit 0 is cleared ‘0’
i2c_write(0x05);
// Write T
A
 Register Address
i2c_start();
//Repeat START
i2c_write(AddressByte | 0x01);
// READ Command 
(see 
)
//also, make sure bit 0 is Set ‘1’
UpperByte = i2c_read(ACK);
// READ 8 bits 
//and Send ACK bit
LowerByte = i2c_read(NAK);
// READ 8 bits 
//and Send NAK bit
i2c_stop();
// send STOP command
//Convert the temperature data
//First Check flag bits
if ((UpperByte & 0x80) == 0x80){
//T
A
 
≥ T
CRIT
}
if ((UpperByte & 0x40) == 0x40){
//T
A
 > T
UPPER
}
if ((UpperByte & 0x20) == 0x20){
//T
A
 < T
LOWER
}
UpperByte = UpperByte & 0x1F;
//Clear flag bits
if ((UpperByte & 0x10) == 0x10){
//T
A
 < 0°C
UpperByte = UpperByte & 0x0F;
//Clear SIGN
Temperature = 256 - (UpperByte x 16 + LowerByte / 16);
}else
//T
A
  
≥ 0°C
Temperature = (UpperByte x 16 + LowerByte / 16);
//Temperature = Ambient Temperature (°C)
This example routine assumes the variables and I
2
C™ communication subroutines are predefined
(see 
):