Wednesday, December 7, 2011

TC74 DIGITAL TEMPERATURE SENSOR

The TC74 is a digital temperature sensor that outputs an eight bit word that corresponds to temperature. The output is compatible with the IIC serial data bus interface. Temperature accuracy is +/- 2 °C from +25 °C to +85 °C and +/- 3 °C from 0 °C to +125 °C with a resolution of 1 °C. Package options are either TO-220 or SOT-23.

All TC74 sensors can be used with a supply voltage from 2.7 VDC to 5.5 VDC. However, the TC74 is available with specific supply voltages of either 3.3 VDC or 5.0 VDC. By matching the sensor to the supply voltage, better accuracy can be obtained. Also, each voltage can be obtained with eight different address values, allowing more than one sensor on a single IIC bus.

The eight bit output is in two’s complement form. Using the two’s complement number system allows a way to express both positive and negative numbers. In two’s complement, all numbers that have a most significant bit (MSB) of 0 are positive and all numbers with a MSB of 1 are negative. Therefore, the largest positive number that can be expressed as an eight bit number is 127/D or (01111111). Negative numbers consist of values from -1 to -128 with 0 being considered a positive number.

Some Examples:

+127 °C  =  0111 1111b
  +25 °C  =  0001 1001b
    +0 °C  =  0000 0000b
     -1 °C  =  1111 1111b
   -25 °C  =  1110 0111b
   -55 °C  =  1100 1001b

In order to display the correct negative value, I convert any negative numbers back into its positive number. I do this by taking the two’s complement of the negative number. Two’s complement = one’s complement + 1. The one’s complement is performed by inverting all bits, 1’s become 0’s and 0’s become 1’s.

EXAMPLE:

-1 °C   = 1111 1111 = 0000 0000 + 1 = 1
-25 °C = 1110 0111 = 0001 1000 + 1 = 25
-55 °C = 1100 1001 = 0011 0110 + 1 = 55
TC74 SERIAL PORT OPERATION

START Condition (S)
The TC74 continuously monitors the SDA and SCLK lines for a START condition (a high-to-low transition of SDA while SCLK is high) and will not respond until this condition is met.

Address Byte
Immediately following the START condition, the master must transmit the address byte to the TC74. The 7-bit address transmitted in the serial bit stream must match for the TC74 to respond with an Acknowledge (indicating the TC74 is on the bus and ready to accept data). The 8-bit in the address byte is a Read/Write bit. This bit is a ‘1’ for a read operation or ‘0’ for a write operation.

Acknowledge (ACK)
Acknowledge (ACK) provides a positive handshake between the master and the TC74. The master releases SDA after transmitting 8 bits. The master then generates a ninth clock cycle to allow the TC74 to pull the SDA line low. This action acknowledges that the TC74 successfully received the previous 8 bits of data or address.

Data Byte
After a successful acknowledge (ACK) of the address byte, the master must transmit the data byte to be written, or clock-in the data to be read. An acknowledge (ACK) will be generated after a successful write of a data byte into the TC74.

STOP Condition (P)
Communications must be terminated by a STOP condition (a low-to-high transition of SDA while SCLK is high). The STOP condition must be communicated by the master to the TC74.

The following is a C function that is used to send and receive data from the TC74.
It was written for the FREESCALE MC9S08 series 8 bit microcontrollers.

IIC REGISTER BIT DEFINITIONS

IICC:    IIC Control Register
IICD:    IIC Data I/O Register

IICC_TX:         Transmit Mode Select: 0 = Receive, 1 = Transmit
IICC_TXAK:    Transmit Acknowledge Enable
IICS_IICIF:      IIC Interrupt Flag
IICC_RSTA:     Repeat Start
IICC_MST:       Master Mode Select
IICC_RXAK:    Receive Acknowledge


IIC TC74 TEMPERATURE SENSOR DATA FUNCTION
void iic_tmpdata(void)

{
//GET TEMPERATURE DATA FROM SENSOR
//WRITE - SEND START BYTE
IICC_TX = 1;
IICC_TXAK = 0;
IICC = 0xB0;
IICD = 0x96;
while (!IICS_IICIF);
IICS_IICIF = 1;
while (IICS_RXAK);

//WRITE - SEND COMMAND BYTE
IICD = 0x01;
while (!IICS_IICIF);
IICS_IICIF = 1;
while (IICS_RXAK);

//WRITE - SEND CONFIGURATION BYTE
//$00 = normal mode, $80 = standby mode
IICD = 0x00;
while (!IICS_IICIF);
IICS_IICIF = 1;
while (IICS_RXAK);

//WRITE - STOP AND DELAY BEFORE READ
IICC_MST = 0;
iic_wait (50);

//READ - SEND SLAVE ADDRESS
IICC = 0xB0;
IICD = 0x96;
while (!IICS_IICIF);
IICS_IICIF = 1;
while (IICS_RXAK);

//READ - SEND COMMAND BYTE (TEMPERATURE)
IICD = 0x00;
while (!IICS_IICIF);
IICS_IICIF = 1;
while (IICS_RXAK);

//READ - REPEAT START COMMAND
IICC_RSTA = 1;
IICD = 0x97;
while (!IICS_IICIF);
IICS_IICIF = 1;
while (IICS_RXAK);

//READ - PERFORM DUMMY READ
IICC_TX = 0;
IICC_TXAK = 1;
TC74_data = IICD;
while (!IICS_IICIF);
IICS_IICIF = 1;

//READ - STOP
IICC_MST = 0;
iic_wait (50);

//READ TEMPERATURE
TC74_data = IICD;
}

CIRCUIT BOARD

A relatively simple circuit board was designed to display the temperature data from the TC74 sensor. The microcontroller was a FREESCALE MC9S08QG8 operating at 3.3 VDC. Two LTS3401 (“0.8”) common anode green LED displays were used along with a CAT4016 constant current LED driver to drive the display segments.

The CAT4016 can drive up to 16 LEDS, making it perfect for two seven segment displays along with a decimal point on each display. Current limiting for the LED’s requires only a single 4K resistor. A 4K resistor will set the LED current at 15 mA per segment. The displays are directly driven and not multiplexed. I prefer direct drive as it lowers CPU overhead and power supply bus noise.

For a negative sign, I usually prefer to use the middle (“g”) segment on an LED display. Unfortunately, doing so in this case, with only two digits available,  would limit the minimum temperature display to only -9 °C. I decided instead to use a 2mm x 7mm rectangular green LED just to the left of the tens display as a negative indicator. This allows the minimum display to be -99 °C. The negative LED was controlled by an available port pin on the MCU.

The TC74 was connected to the PCB using a 2x5 pin connector made by 3M.
This would allow using a four conductor cable to connect the sensor for remote operation.


The single sided PCB measures 3in x 3in and was homemade using a photo negative process.

TC74 PCB SCHEMATIC

CLICK ON FOR LARGER IMAGE



TC74 PCB LAYOUT
TC74 PCB LAYOUT PDF


CLICK ON FOR LARGER IMAGE


FINISHED PCB


CLICK ON FOR LARGER IMAGE
 

TEMPERATURE DISPLAY ROUTINE

The display loop routine shows the temperature in both °C and °F. The example below indicates a temperature of  -10 °C and 14 °F. The program also includes a display test that lights all the display segments and the two indicator LED's when the PCB is powered up.

An alternate program could be easily created that stores the highest maximum temperature and also the lowest minimum temperature. The PCB has a PB switch which could control an interrupt (flag) that causes the display loop to display the high / low temperature as “HI” / (temp) and “Lo” / (temp) in both °C and °F. This is something I have done with a similar TC74 design that uses an LCD display.


CLICK ON FOR LARGER IMAGE

REFERENCE: MICROCHIP TC74 DATASHEET  http://www.microchip.com/

No comments:

Post a Comment