• Pic® Basic


  • TC74 I2C Temperature Sensor

    The TC74 is a serially accessible, digital temperature sensor using communication via a 2-wire SMBus/I2C compatible serial port. Temperature data is converted from the on board thermal sensing element and made available as an 8-bit digital byte. The temperature data can be read at any time (?). Eight SMBus/I2C addresses are programmable for the TC74, which allows for a multi-sensor configuration. The maximum clock frequency is 100 Khz.
    In temperature data registers, each unit value represents one degree (Celsius). The value is in 2’s complement binary format such that a reading of b00000000 corresponds to 0°C. The TC74 is internally programmed to have a default SMBus/I2C address value of b10011010 (TC74A5).
    The TC74 sensor has 2 registers, the Configuration and Temperature registers.

    STANDBY MODE:
    Also, there is low power Standby mode when temperature acquisition is suspended. During standby operation, the quiescent current is 5 µA (typ). In this mode, the A/D converter is halted and the temperature data registers are frozen. The SMBus/I2C port, though, operates normally. Standby mode is enabled by setting the SHDN bit in the CONFIG register (Bit7).

    READY MODE: (Bit 6)
    The maximum ensured conversion time after Power-on Reset (POR to DATA_READY) is 250 msec.
    The DATA_READY could be read only to know the state of the sensor. The DATA_READY Bit is avaible 250mS after the STANDBY bit has been cleared. (Very important)

    READING TEMPERATURE:
    Temperature resolution is 1°C. Conversion rate is a nominal 8 samples/sec. During normal operation, the quiescent current is 200 µA (typ). Output current should be minimized for best temperature accuracy. Power dissipation within the TC74 will cause self-heating and temperature drift error. It shows dramatically in the SMT model.

    SMBus/I2C Protocols of the TC74 temperature sensor.

    Receive Byte Format:
    After Power up the temperature value is available after 250mS. The temperature record is already pointed out.
    The temperature value could be read with a simple and fast format.
    Code:
        While 1 = 1
            BusIn TC74A4_ADRRead,[Temperature]
        
            If Temperature.7 = 1 Then          
                Temperature = ~Temperature + 1          ' It is a negative Result.
                HRSOut "Temperature: -", Dec Temperature
            Else                                        ' It is a positive result. 
                HRSOut "Temperature: +", Dec Temperature
            EndIf
            HRSOut " Degrees ", "(", IBin8 Temperature, ")", CR
    
            DelayMS 3000
        Wend
    Read Byte Format:
    This is the standard format to read a register. The address must be pointed out first.
    Code:
        While 1 = 1
            BusIn TC74A4_ADRRead,TC74_RTR,[Temperature]
    
            If Temperature.7 = 1 Then          
                Temperature = ~Temperature + 1          ' It is a negative Result.
                HRSOut "Temperature: -", Dec Temperature
            Else                                        ' It is a positive result. 
                HRSOut "Temperature: +", Dec Temperature
            EndIf
            HRSOut " Degrees ", "(", IBin8 Temperature, ")", CR
    
            DelayMS 3000
        Wend
    Write Byte Format:
    This is the standard format to write a data to a register.
    Code:
        BStart
        BusOut xTC74_AddressWrite  ' Command to write a byte
        BusOut TC74_RWCR           ' Config Register Address
        BusOut TC74_STANDBY        ' Loading the value to the Config Register.
        BStop
    Testing:
    After trying all formats for some time, I realized that the readings were false sometimes.
    The datasheet is not very clear in this regard. I have been given two types of problems.

    Fails to read with the Receive Byte Format:
    The Receive Byte Format only works if the power up was successful and if the code had not read or written in the configuration register. Then it is extremely easy to read an erroneous temperature.

    Fails to read the Read Byte Format:
    The Receive Byte Format only works if the power up has succeeded well. But the two formats may fail in 5 minutes, one hour, one day, one week ... WHY ???

    Because the sensor can happen in Standby mode. (As a fault) Not explained in the datasheet.
    - After a bad power up. (With noise or DV/DT incorrect?)
    - If the I2C communication has been interrupted or impaired by noise (unlikely but possible), by reset (Watchdog, Bootloader or by a switch reset).

    - For the Receive Byte Format reading: the value will always be equal to +128 degrees. In some cases the reading will be +64 degrees if the sensor is ready.
    - For the Read Byte Format reading: the last reading will be repeated forever.

    Only the temperature reading will be valid if before the Ready bit is set to 1. The two ways of reading the temperature are prohibited for being unreliable.

    I wrote 2 reliable commands to read the temperature.
    1- Read the configuration register before reading the temperature and send errors.
    2- Read the configuration register before reading the temperature, correct the error and if the sensor does not work the corresponding error is sent.

    Testing Files:
    Test1_TC74.Bas
    This demo can test the TC74_ReadSRTemp() command to verify the NACK & Ready state.
    The Sensor is scaned until the correct address sensor is found.
    If the sensor is not ready, the TC74_NormalMode() command is sent.
    Try to disable the the TC74_NormalMode() command, comment the line 74 of the demo.
    And try what happens.

    Test2_TC74.Bas
    This demo can test the TC74_ReadSecTemp() command to verify the NACK & Ready state.
    The Sensor is scanned until the correct address sensor is found.
    When the correct address sensor is found the answer would be correct.
    All correction have been made by the TC74_ReadSecTemp() command.

    Test3_TC74.Bas
    This demo can test the TC74_ReadSecTemp() command to verify the NACK & Ready states.
    After reading, the sensor is set to Standby Mode to reduce self heating.
    The Sensor is scanned until the correct address sensor is found.
    When the correct address sensor is found the answer would be correct.
    All correction have been made by the TC74_ReadSecTemp() command.
    If the sensor is not running with the TC74_ReadSeCTemp command then the sensor is damaged.

    The Commands:
    Status = TC74_ReadStatus(Address Sensor)
    This command reads the Configuration Register of the TC74 sensor.

    TC74_StandbyMode(Address Sensor, Return Acknowledge)
    This command sets the Standby bit of the Configuration Register.

    TC74_NormalMode(Address Sensor, Return Acknowledge)
    This command clears the Standby bit of the Configuration Register.

    Temperature = TC74_ReadSRTemp(Address Sensor, Return Sign, Return Acknowledge)
    This command read the Status Ready Bit, if it is correct, the temperature is sent. Alternately an error is set.
    The code to extract the sign and calculate the 2’s complement is included.

    Temperature = TC74_ReadSeCTemp(Address Sensor, Return Sign, Return Acknowledge)
    This command read the Status Ready Bit, if it is correct, the temperature is sent. If the Ready bit is not set, the Normal Mode is written in the sensor. The Status is read again and if the sensor is not ready an error is set. The code to extract the sign and calculate the 2’s complement is included.

    Receive the "Return Acknowledge" is not mandatory:
    TC74_StandbyMode(Address Sensor)
    TC74_NormalMode(Address Sensor)
    Temperature = TC74_ReadSRTemp(Address Sensor, Return Sign)
    Temperature = TC74_ReadSeCTemp(Address Sensor, Return Sign)

    If the user prefers to receive the original temperature format of the sensor, write this $Define before the file.
    $define _TempOrgFormat_
    Include "TC74-S.inc"

    With the "Original Format Option", the commands must be written like this:
    Temperature = TC74_ReadSRTemp(Address Sensor, Return Acknowledge)
    Temperature = TC74_ReadSeCTemp(Address Sensor, Return Acknowledge)
    Receive the "Return Acknowledge" is not mandatory.

    As I2C communication needs a control of the ACK, the HBusin/HBusout commands has been chosen for the hardware I2C and Busin/Busout for the software I2C.

    The libraries "TC74-H.inc" and "TC74-S.inc" are available.
    The "Testing" folder contains some good and bad examples of reading TC74 I2C temperature sensor.
    Not simply use a good code but also use a good technique.
    Alberto

    Update Version 1.2 15/03/2016
    Fixed error for the OrgTemperature return variable.
    Added configuration of the I2C Bus pins to digital for PIC18F2xK22 series.
    Added the TC74_Present() command.
    Added some minor changes for compatibility with others libraries.

    Download the code from the Files Server.
  • Recent Activity

    amod-29593

    Pulse counter using COUNTER command

    Thread Starter: amod

    How I can use counter command for counting pulses on portd.3 of 16f877A.Iam making a 8 digit object counter.

    amod Today, 19:27 Go to last post
    teo-16018

    Assembler to Proton

    Thread Starter: teo

    Hello everybody, How can I translate from Assembler into Proton? --------------------------------------------------------------------------...

    teo Today, 18:59 Go to last post
    mjturner-211

    CWrite Issues on 16F

    Thread Starter: mjturner

    I want to commit some values to EEPROM, but it seems they no longer include the separate EEPROM area anymore. So I'm having to use the code flash...

    mjturner Today, 17:48 Go to last post