Lab 6: Temperature Introduction Temperature is a very fundamental parameter that is important in a number of contexts. Most electronic devices operate most effectively over a limited range of temperatures and require cooling if they exceed some maximum. It is an important indicator of human health and disease. We will use temperature sensing to provide an example of the power of using a microcontroller to decode a sensor, displaying the sensor output on an LCD display with proper scaling and units. The boards use the Microchip TL1047A temperature sensor to provide a DC output directly proportional to temperature. The following discussion provides a roadmap for adding temperature measurement and display capabilities to your Qik-Start boards. You will need to add math subroutines to your program to do the calculations necessary to convert the raw AD converter input into temperatures in Celsius, Kelvin and Fahrenheit, and to convert the binary numbers output from the math subroutines into decimal suitable for display. You also need to add a Temperature mode to your main() subroutine. Finally, in the second part of this lab, you will transmit your temperatures to a PC via the RS232 link, and receive the data using the Hyperlink program. You will use this data to analyze the time constant of your temperature sensor to a step increase and decrease in ambient temperature. Figure 1. Input circuit for temperature on Qik - Start board. Procedure There are a lot of different parts to this lab. Be systematic, and perform the requirements in testable steps. For example, first install the temperature mode into EnterKey and test that it is working. Then do the AD conversion part, and check the values in T1HIGH and T1LOW using the watch window in the ICD to see if they are reasonable. Use the Hex capabilities of the calculator in Windows accessories to check your results. Finally install the math subroutines. Be sure to put test points in your program, so you can check the math at each stage to see if it is doing what you think it is doing. Convert to decimal form and display. Once this is working you can try the serial communications. Ask us for help if you get stuck! The boards use a cost effective temperature sensor that provides a linear output voltage proportional to the temperature. As shown in Fig. 1 above, the output of the TC1047A is sent to a non-inverting Op Amp with a gain of 2 and then sent to RA3, the third AD converter input port. The PIC AD converter converts this to 1024 levels, or a 10 bit digital output. This output is available on the ADRESH and ADRESL registers. ADConvert Use the following ADConvert subroutine to get the output from the Temperature sensor into the new variables T1HIGH and T1LOW. Note that the AD conversion from the Bar Chart and Bar Intensity conversions used left justification, but you will need right justification for the temperature sensor or you will need to shift the data appropriately. Decimal Format Once the temperature is detected and AD converted, the resultant output must be converted to decimal format, and displayed on the LCD screen provided. This is accomplished by repeatedly dividing by 10 and saving the remainder of the division. Each such remainder is one digit of the final decimal result. Temperature mode in main A new mode, Temperature, must be inserted into the main subroutine for the present lab. Thus the Enter Key sequence will be Press Enter->Name->Character->Temperature->Name. For extra credit, Temperature can be displayed in Celsius, Kelvin and Fahrenheit units simultaneously. Conversion Relations The basic equation for the TC1047A temperature sensor is: mV Vout = 10 o T + 500mV C ! With the A/D converter operating with a 5.00 Volt nominal reference [7805 voltage regulator], each step is about 4.8828 mV, or about .25 [actually .244]°C. The temperature sensor is rated conservatively at +/- 2 °C over its entire operating range, but it is significantly better than that in the range of 0-40 °C, where the typical accuracy can be expected to be about .2 °C. We need to find integer relations for converting the AD converter output to degrees in the Celsius, Fahrenheit and Kelvin scales. ! Calculations From the above equation, each step represents (5000/1024)/2/10 = .244141 °C. Then we can readily derive the Eq. below to represent the temperature in Celsius, where N is an integer from 0 to 1023, representing the ADC output: V " 500mV T = out mV 10 o C N # 5000mV " 500mV = 1024 # 2 mV 10 o C = .244N " 50 = .244(N " 205) Since you don’t have fractional numbers on the microcontroller, it will be easier to do the calculations in milliCelsius degrees. Thus the equation becomes T=244(N-205). Because the number will be large, you will need to declare the N and T variables as unsigned shorts. In order to keep the displayed temperatures consistent, it is suggested that you calculate the Celsius temperature and then multiply by 18 and add 320 to get Fahrenheit times 10. Kelvin can be obtained by adding 273 to the Celsius value New Variables Declare the following new variables: unsigned char T1HIGH // Temperature High Byte unsigned char T1LOW // Temperature Low byte Discussion and Conclusions This is a very important lab because it introduces some vital capabilities of microcontroller systems. The main concepts introduced by this lab include the following: 1. Use of an external sensor to provide data to microcontroller. 2. Use of integrated Math subroutines for advanced math operations, and to convert raw sensor data to format for display. 3. Use of integrated display capabilities to provide a complete measurement system. Keep all other functions operational. Thus BarChart, BarIntensity, DisplayV should continue to operate. If your code exhibits difficulties, set up a watch window and use the ICD to debug. Demonstrate your project and hand in your well-commented C code by Tuesday.
© Copyright 2026 Paperzz