• PicŪ Basic


  • TC77 Temperature Sensor Interface

    The TC77 device operates as a temperature sensor via an SPI interface. Its circuit connections are very simple, and the device has a temperature range of -55°C to +125°C.

    The TC77's datasheet can be downloaded from here: TC77.pdf

    The circuit for the TC77 is shown below:

































    Click here for a more detailed image


    The interfacing code is listed below:
    Code:
    ' Interface to a TC77 temperature sensor
    ' Transmits the temperature (in degrees Centigrade) on the serial terminal
    '
    ' For the Amicus18 board, which uses a PIC18F25K20 device operating at 64MHz
    ' Written by Les Johnson 06-01-2016
    '
        Include "Amicus18.inc"                                      ' Configure the compiler to use a PIC18F25K20 at 64MHz. i.e. An Amicus18 board 
        Declare Float_Display_Type = Fast                           ' Set for faster and more accurate floating point displaying
    '
    ' Create some variables
    '
        Dim TC_fTemperature As Float                                ' Holds the temperature
        Dim TC_bBitCounter As Byte                                  ' Used to count the bits in the bit-bashed SPI interface
        Dim TC_wTemperature As SWord                                ' Used to hold the raw data from the device
    '
    ' Define some pins for the SPI interface to the TC77 device
    '
        $define TC_SCK_Pin PORTB.0                                  ' Connects to the TC77's SCK pin 
        $define TC_CS_Pin  PORTB.1                                  ' Connects to the TC77's CS pin 
        $define TC_SIO_Pin PORTB.2                                  ' Connects to the TC77's SIO pin 
    
    '-------------------------------------------------------------------------------
        GoTo Main                                                   ' Jump over the subroutines
    '-------------------------------------------------------------------------------
    ' Setup the TC77 device's SPI interface
    ' Input     : None
    ' Output    : None
    ' Notes     : None
    ' 
    $define TC77_Init() '
        High TC_CS_Pin  '
        Low TC_SCK_Pin  '
        Input TC_SIO_Pin
    
    '----------------------------------------------------------------------
    ' Read the data from the TC77 device's SPI interface
    ' Input     : None  
    ' Output    : TC_wTemperature holds the 16-bit temperature value
    ' Notes     : None
    '
    $define TC77_SPI_Read() GoSub _TC77_SPI_Read
    
    _TC77_SPI_Read:     
        Clear TC_CS_Pin                                             ' Enable the SPI interface
        Clear TC_SCK_Pin                                            ' Pull TC_SCK_Pin low   
        TC_bBitCounter = 15                                         ' Set bit counter for 16-bits
        Repeat                                                      ' Create a loop for the bits
            Set TC_SCK_Pin                                          ' TC_SCK_Pin rising edge     
            TC_wTemperature.0 = TC_SIO_Pin                          ' Receive the bit from the device
            Clear TC_SCK_Pin                                        ' Pull the TC_SCK_Pin low
            TC_wTemperature = TC_wTemperature << 1                  ' Rotate the bit
            Dec TC_bBitCounter
        Until TC_bBitCounter = 0    
        Set TC_CS_Pin                                               ' Disable the SPI interface
        Return
    
    '-------------------------------------------------------------------------------- 
    ' Interface to a TC77 temperature sensor
    ' Input     : None
    ' Output    : TC_fTemperature holds the temperature (in degrees Centigrade)
    ' Notes     : The TC77 Temperature Register is a 16-bit read only register.
    '             The temperature data format is a 13-bit two's complement digital 
    '             word (bits 15:3). The least significant bit (LSb) is equal to 
    '             0.0625 degrees C. Bit 2 is set to a logic '1' after the completion
    '             of the first temperature conversion following a power-up or reset 
    '             event. Bits 1:0 are tri-stated.
    '
    $define TC77_GetTemperature(pResult) '
        GoSub _TC77_ReadTemp             '
        pResult = TC_fTemperature
    
    _TC77_ReadTemp:
        TC77_SPI_Read()                                             ' Read the data from the device into TC_wTemperature
    
        TC_wTemperature = TC_wTemperature >> 6                      ' Right adjust 13-bit 2's complement temperature value into TC_wTemperature
        If TC_wTemperature.9 = 1 Then                               ' Is it a negative temperature?       
            TC_wTemperature.Byte1 = TC_wTemperature.Byte1 | $FE     ' Yes. So sign extend bits 15 to 10 in TC_wTemperature
            TC_wTemperature = ~TC_wTemperature                      ' \ 2's complement
            Inc TC_wTemperature                                     ' /
            TC_wTemperature = -TC_wTemperature                      ' Make negative
        EndIf
        TC_fTemperature = TC_wTemperature / 2                       ' Divide by 2 for the temperature    
        Return
    
    '--------------------------------------------------------------------------------  
    ' The main program loop starts here
    '
    Main:
        TC77_Init()                                                 ' Initialise the TC77 interface 
    
        While
            TC77_GetTemperature(TC_fTemperature)                    ' Get the temperature
    
            HRSOut Dec1 TC_fTemperature, 13                         ' Transmit the temperature serially
            DelayMS 500
        Wend
    Below is the program running in the Proteus simulator:


    The above simulation files can be downloaded from here:
    TC77_Proteus_Design.zip


  • Recent Activity

    normnet-324

    FineLineIDE

    Thread Starter: normnet

    Coming soon a new IDE: FineLineIDE! Features include:<O:p</O:p Bracket lines linking If-Endif, For-Next etc.<O:p</O:p Tabbed explorer so...

    normnet Today, 09:31 Go to last post
    Henk57-24049

    Compiler 3.6.1.7 issue with 16F1829 and I2C-LCD

    Thread Starter: Henk57

    Spend this afternoon with a compiler issue; no error's, but my LCD give only first line with squares, no characters, nothing. If I flash an old .hex...

    Henk57 Today, 11:43 Go to last post
    Les-15

    New dual core dsPIC33CH PIC

    Thread Starter: normnet

    The Master core and Slave core can operate independently, and can be programmed and debugged separately during the application development. Both...

    Les Yesterday, 15:40 Go to last post