{"id":3146,"date":"2011-07-17T14:48:53","date_gmt":"2011-07-17T18:48:53","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=3146"},"modified":"2012-11-06T14:00:32","modified_gmt":"2012-11-06T19:00:32","slug":"using-tc74-microchip-thermal-sensor-for-temperature-measurement","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/using-tc74-microchip-thermal-sensor-for-temperature-measurement\/","title":{"rendered":"Using TC74 (Microchip) thermal sensor for temperature measurement"},"content":{"rendered":"<p>The TC74 chip is a serially accessible, digital temperature\u00a0sensor from Microchip Technology that acquires and converts temperature information from its onboard solid-state sensor with a resolution of 1\u00b0C. The temperature is available as an 8-bit digital word stored in its internal temperature register, which is accessible through a 2-wire I2C compatible serial bus. This tutorial describes how to use the TC74 sensor with a PIC microcontroller to measure the surrounding temperature.<\/p>\n<div id=\"attachment_3167\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_title.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3167\" class=\"size-full wp-image-3167\" title=\"TC74_title\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_title.jpg\" alt=\"\" width=\"560\" height=\"333\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_title.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_title-550x327.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3167\" class=\"wp-caption-text\">Using TC74 sensor for temperature measurement<\/p><\/div>\n<p><!--more--><\/p>\n<p><strong>Theory<\/strong><\/p>\n<p>The TC74 digital temperature sensor is available in\u00a0SOT-23 and\u00a0TO-220 packages. The communication with the device is accomplished via a 2-wire I2C compatible serial bus.\u00a0Temperature resolution is 1\u00b0C and conversion rate is a\u00a0nominal 8 samples\/sec. The pin diagram of TC74 chip is shown below for reference.<\/p>\n<div id=\"attachment_3160\" style=\"width: 473px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_PinDiagram.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3160\" class=\"size-full wp-image-3160\" title=\"TC74_PinDiagram\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_PinDiagram.jpg\" alt=\"\" width=\"463\" height=\"403\" \/><\/a><p id=\"caption-attachment-3160\" class=\"wp-caption-text\">Pin diagram of TC74<\/p><\/div>\n<p>The TC74 stores the measured temperature into its 8-bit internal register as 2&#8217;s complement binary format. The most significant bit is the sign bit, which is set to 1 for negative temperatures. Therefore, the maximum measurable positive temperature is + 127\u00a0\u00b0C (0111 1111). The TC74 has also got another 8-bit Read\/Write Configuration Register (RWCR) that is used to\u00a0put the device into a low\u00a0power (I<sub>DD<\/sub> = 5 \u00b5A, typical) Standby mode. In this\u00a0mode, the A\/D converter is halted and the temperature\u00a0data registers are frozen. Bit 7 of RWCR must be set to put TC74 into Standby mode.<\/p>\n<div id=\"attachment_3175\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TempTable.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3175\" class=\"size-medium wp-image-3175\" title=\"TempTable\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TempTable-550x341.jpg\" alt=\"\" width=\"550\" height=\"341\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TempTable-550x341.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TempTable.jpg 698w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-3175\" class=\"wp-caption-text\">Temperature conversion table and internal registers<\/p><\/div>\n<p><strong><em>Serial port operation<\/em><\/strong><\/p>\n<p>The Serial Clock input (SCLK) and bidirectional data\u00a0port (SDA) form a 2-wire bidirectional serial port for communicating with the TC74. The port is I2C compatible and all transfers take place under the control of a host, usually a microcontroller. The host microcontroller provides the clock signal for all the data transfers and the TC74\u00a0always operates as a Slave. The default 7-bit I2C address of TC74 is 1001 101b. However, 7 other address options are also available which can be identified from the part number of the device. For example, I have got a TC74A0 in TO-220 package. A0 corresponds to the device address 1001 000b. Similarly, TC74A3 has its I2C address 1001 011b. Refer the <strong><a href=\"http:\/\/ww1.microchip.com\/downloads\/en\/devicedoc\/21462c.pdf\" target=\"_blank\">datasheet<\/a><\/strong> for further details. If you are not familiar with I2C protocol, please read my article, <strong><a href=\"http:\/\/embedded-lab.com\/blog\/?p=2583\" target=\"_blank\">Inter-Integrated Circuit (I2C) communication in PIC<\/a><\/strong>. Reading temperature from a TC74 device through I2C port involves the following steps:<\/p>\n<ul>\n<li><span style=\"color: #800000;\"><em>The host microcontroller issues a Start condition followed by the address byte. The address byte consists of the 7-bit slave address and a Read\/Write bit (R\/W). The R\/W bit is always &#8216;0&#8217; (Write) in the first phase. <\/em><\/span><\/li>\n<li><span style=\"color: #800000;\"><em>If the received 7-bit address matches with its own slave address, the TC74 responds with an acknowledge pulse. <\/em><\/span><\/li>\n<li><span style=\"color: #800000;\"><em>The host microcontroller next sends the command byte to TC74 to indicate which register it wants to access. For reading the temperature, the command byte should be 00h. The TC74 responds with an acknowledge pulse.<\/em><\/span><\/li>\n<li><span style=\"color: #800000;\"><em>The host microcontroller issues a new Start condition because the direction of data transfer is now going to be changed. The new address byte with R\/W bit 1 is sent by the host, which is acknowledged by the slave. <\/em><\/span><\/li>\n<li><span style=\"color: #800000;\"><em>The TC74 transmits the 8-bit temperature data from the temperature register. Upon receiving the byte, the host doesn&#8217;t acknowledge, but generates a Stop condition.<\/em><\/span><\/li>\n<\/ul>\n<p><strong>Circuit diagram<\/strong><\/p>\n<p>I am using PIC18F2550 to demonstrate here, but it can be implemented with any other smaller size PIC microcontrollers that support I2C communication. The temperature is read from the TC74 sensor and displayed on a character LCD. Don&#8217;t forget to put two pull-up resistors (1K) on SDA and SCL lines of I2C bus. The PIC18F2550 microcontroller used in this experiment is from the <strong><a href=\"http:\/\/embedded-lab.com\/blog\/?p=2321\" target=\"_blank\">StartUSB for PIC board<\/a><\/strong>.<\/p>\n<div id=\"attachment_3163\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74Circuit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3163\" class=\"size-medium wp-image-3163\" title=\"TC74Circuit\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74Circuit-550x427.jpg\" alt=\"\" width=\"550\" height=\"427\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74Circuit-550x427.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74Circuit.jpg 800w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-3163\" class=\"wp-caption-text\">Circuit diagram<\/p><\/div>\n<div id=\"attachment_3169\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/SetUp2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3169\" class=\"size-full wp-image-3169\" title=\"SetUp2\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/SetUp2.jpg\" alt=\"\" width=\"560\" height=\"321\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/SetUp2.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/SetUp2-550x315.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3169\" class=\"wp-caption-text\">Circuit setup on breadboard<\/p><\/div>\n<div id=\"attachment_3161\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/SetUp1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3161\" class=\"size-full wp-image-3161\" title=\"SetUp1\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/SetUp1.jpg\" alt=\"\" width=\"560\" height=\"418\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/SetUp1.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/SetUp1-550x410.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3161\" class=\"wp-caption-text\">TC74 temperature sensor<\/p><\/div>\n<p><strong>Software<\/strong><\/p>\n<p>The firmware for PIC18F2550 is developed in C using mikroC Pro for PIC compiler. The compiler provides the built-in library for I2C support. The microcontroller reads the temperature word from the TC74&#8217;s internal temperature register and displays it on the LCD. The following program works for the entire operating range of TC74 (-40\u00a0\u00b0C\u00a0to 125\u00a0\u00b0C).<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #808080; font-style: italic;\">\/*\n  Project: Using TC74 with PIC microcontroller\n           for temperature measurement\n  MCU: PIC18F2550 on-board StartUSB for PIC\n       Clock 48.0 MHz using HS + PLL\n  MCLR Enabled\n*\/<\/span>\n&nbsp;\n<span style=\"color: #666666; font-style: italic;\">\/\/ Define LCD module connections.<\/span>\n sbit LCD_RS at RC6_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_EN at RC7_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_D4 at RB4_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_D5 at RB5_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_D6 at RB6_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_D7 at RB7_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_RS_Direction at TRISC6_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_EN_Direction at TRISC7_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_D4_Direction at TRISB4_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_D5_Direction at TRISB5_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_D6_Direction at TRISB6_bit<span style=\"color: #339933;\">;<\/span>\n sbit LCD_D7_Direction at TRISB7_bit<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #666666; font-style: italic;\">\/\/ End LCD module connection definition<\/span>\n&nbsp;\n<span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">char<\/span> Temp<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> num<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #993333;\">const<\/span> <span style=\"color: #993333;\">int<\/span> TC74A0 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x90<\/span><span style=\"color: #339933;\">;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> check_device<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> dev_address<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n I2C1_Start<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span>I2C1_Wr<span style=\"color: #009900;\">&#40;<\/span>dev_address<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n  Lcd_Out<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;Device not found&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n <span style=\"color: #009900;\">&#125;<\/span>\n <span style=\"color: #b1b100;\">else<\/span> Lcd_Out<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;TC74 device&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  I2C1_Stop<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> Read_Temp<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> result<span style=\"color: #339933;\">;<\/span>\n I2C1_Start<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>          <span style=\"color: #666666; font-style: italic;\">\/\/ Issue start signal<\/span>\n I2C1_Wr<span style=\"color: #009900;\">&#40;<\/span>TC74A0<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>       <span style=\"color: #666666; font-style: italic;\">\/\/ Address + Write bit<\/span>\n I2C1_Wr<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x00<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/ Read Temp<\/span>\n I2C1_Repeated_Start<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/ Issue start signal<\/span>\n I2C1_Wr<span style=\"color: #009900;\">&#40;<\/span>TC74A0<span style=\"color: #339933;\">+<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>     <span style=\"color: #666666; font-style: italic;\">\/\/ Address + Read bit<\/span>\n result <span style=\"color: #339933;\">=<\/span> I2C1_Rd<span style=\"color: #009900;\">&#40;<\/span>0u<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n <span style=\"color: #b1b100;\">return<\/span> result<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">char<\/span> temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #ff0000;\">&quot; 000  C&quot;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #993333;\">void<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  CMCON <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x07<\/span><span style=\"color: #339933;\">;<\/span>   <span style=\"color: #666666; font-style: italic;\">\/\/ Disable comparators<\/span>\n  ADCON1 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x0F<\/span><span style=\"color: #339933;\">;<\/span>  <span style=\"color: #666666; font-style: italic;\">\/\/ Disable Analog functions<\/span>\n  TRISA <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>\n  TRISC <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>\n  TRISB <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>\n  I2C1_Init<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">100000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>   <span style=\"color: #666666; font-style: italic;\">\/\/ Initiate I2C<\/span>\n  Lcd_Init<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>          <span style=\"color: #666666; font-style: italic;\">\/\/ Initialize LCD<\/span>\n  Lcd_Cmd<span style=\"color: #009900;\">&#40;<\/span>_LCD_CLEAR<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/ CLEAR display<\/span>\n  Lcd_Cmd<span style=\"color: #009900;\">&#40;<\/span>_LCD_CURSOR_OFF<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>        <span style=\"color: #666666; font-style: italic;\">\/\/ Cursor off<\/span>\n  Lcd_Out<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;Testing TC74&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  Lcd_Out<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">2<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #ff0000;\">&quot;Thermal sensor&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  Delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  Lcd_Cmd<span style=\"color: #009900;\">&#40;<\/span>_LCD_CLEAR<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  <span style=\"color: #b1b100;\">do<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n   check_device<span style=\"color: #009900;\">&#40;<\/span>TC74A0<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n   num <span style=\"color: #339933;\">=<\/span> Read_Temp<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n&nbsp;\n   <span style=\"color: #666666; font-style: italic;\">\/\/ Check for negative temperature<\/span>\n   <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span>num <span style=\"color: #339933;\">&amp;<\/span>gt<span style=\"color: #339933;\">;<\/span> <span style=\"color: #0000dd;\">127<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n    temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #ff0000;\">'-'<\/span><span style=\"color: #339933;\">;<\/span>\n    num <span style=\"color: #339933;\">=<\/span> ~num <span style=\"color: #339933;\">+<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>\n   <span style=\"color: #009900;\">&#125;<\/span>\n   <span style=\"color: #b1b100;\">else<\/span> temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #ff0000;\">'+'<\/span><span style=\"color: #339933;\">;<\/span>\n&nbsp;\n   temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> num<span style=\"color: #339933;\">\/<\/span><span style=\"color: #0000dd;\">100<\/span> <span style=\"color: #339933;\">+<\/span> <span style=\"color: #0000dd;\">48<\/span><span style=\"color: #339933;\">;<\/span>\n   temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">2<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #009900;\">&#40;<\/span>num<span style=\"color: #339933;\">\/<\/span><span style=\"color: #0000dd;\">10<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">%<\/span><span style=\"color:#800080;\">10<\/span> <span style=\"color: #339933;\">+<\/span> <span style=\"color: #0000dd;\">48<\/span><span style=\"color: #339933;\">;<\/span>\n   temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">3<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> num<span style=\"color: #339933;\">%<\/span><span style=\"color:#800080;\">10<\/span> <span style=\"color: #339933;\">+<\/span> <span style=\"color: #0000dd;\">48<\/span><span style=\"color: #339933;\">;<\/span>\n   temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">5<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">223<\/span><span style=\"color: #339933;\">;<\/span>\n&nbsp;\n   <span style=\"color: #666666; font-style: italic;\">\/\/ eliminate 0s at beginning<\/span>\n   <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span>temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">==<\/span> <span style=\"color: #ff0000;\">'0'<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n      temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #ff0000;\">' '<\/span><span style=\"color: #339933;\">;<\/span>\n      <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span>temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">2<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">==<\/span> <span style=\"color: #ff0000;\">'0'<\/span><span style=\"color: #009900;\">&#41;<\/span> temperature<span style=\"color: #009900;\">&#91;<\/span><span style=\"color: #0000dd;\">2<\/span><span style=\"color: #009900;\">&#93;<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #ff0000;\">' '<\/span><span style=\"color: #339933;\">;<\/span>\n   <span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n   Lcd_Out<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">2<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">4<\/span><span style=\"color: #339933;\">,<\/span>temperature<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n   Delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">500<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  <span style=\"color: #009900;\">&#125;<\/span> <span style=\"color: #b1b100;\">while<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p style=\"text-align: center;\"><a href=\"http:\/\/embedded-lab.com\/uploads\/HexFiles\/PIC18F2550\/TC74_ThermalSensor.zip\" target=\"_blank\">Download the mikroC source and HEX files<\/a><\/p>\n<p><strong>Output<\/strong><\/p>\n<p>The following pictures show the device displaying both positive and negative temperatures. The tip of a hot soldering rod saturates the sensor at 127\u00a0\u00b0C. To test the negative temperature reading, the device is put inside the freezer.<\/p>\n<div id=\"attachment_3170\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_Output.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3170\" class=\"size-full wp-image-3170\" title=\"TC74_Output\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_Output.jpg\" alt=\"\" width=\"560\" height=\"333\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_Output.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/TC74_Output-550x327.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3170\" class=\"wp-caption-text\">Displaying room temperature<\/p><\/div>\n<div id=\"attachment_3168\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/MaximumTempOutput.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3168\" class=\"size-full wp-image-3168\" title=\"MaximumTempOutput\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/MaximumTempOutput.jpg\" alt=\"\" width=\"560\" height=\"380\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/MaximumTempOutput.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/MaximumTempOutput-550x373.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3168\" class=\"wp-caption-text\">Maximum measurable temperature<\/p><\/div>\n<div id=\"attachment_3172\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/FreezerTemp.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3172\" class=\"size-full wp-image-3172\" title=\"FreezerTemp\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/FreezerTemp.jpg\" alt=\"\" width=\"560\" height=\"408\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/FreezerTemp.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/FreezerTemp-550x400.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3172\" class=\"wp-caption-text\">Measuring negative temperature inside the freezer<\/p><\/div>\n<div id=\"_mcePaste\"><strong>Conclusion<\/strong><\/div>\n<div>The technique of interfacing Microchip&#8217;s TC74 sensor with a PIC microcontroller to measure the ambient temperature was discussed and demonstrated successfully. The communication with the TC74 sensor was accomplished through an I2C bus interface of PIC18F2550. The 8-bit temperature word was read from the internal temperature register and displayed on a LCD screen by the PIC18F2550 microcontroller.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The TC74 chip is a serially accessible, digital temperature\u00a0sensor from Microchip Technology that acquires and converts temperature information from its onboard solid-state sensor with a resolution of 1\u00b0C. The temperature is available as an 8-bit digital word stored in its internal temperature register, which is accessible through a 2-wire I2C compatible serial bus. This tutorial describes how to use the TC74 sensor with a PIC microcontroller to measure the surrounding temperature.<\/p>\n","protected":false},"author":1,"featured_media":3160,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,29,105,183],"tags":[306,305,247,304],"class_list":["post-3146","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded-labs","category-embedded-lessons","category-pic18f","category-tips-and-tricks","tag-digital-thermometer","tag-microchip-temperature-sensor","tag-pic18f2550","tag-tc74"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/3146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=3146"}],"version-history":[{"count":11,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/3146\/revisions"}],"predecessor-version":[{"id":6288,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/3146\/revisions\/6288"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/3160"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=3146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=3146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=3146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}