# Essay on Microprocessor: Temperature Sensor

Submitted By zhennan
Words: 1870
Pages: 8

Temperature measurements using sensor on the STM32F4DISCOVERY board

Lab Report

Group 17
Usama Haq: 260368376
Varun Jain: 260315399
Table of Contents 1.0 Abstract 3 2.0 Problem Statement 3 3.0 Theory and Hypothesis 3 4.0 Implementation 4 5.0 Testing and Observations 6 5.1 Performance Testing 6 5.2 Code Verification 6 5.2.1 Moving Window Tests Verification 6 5.2.2 Temperature Verification 6 5.2.3 Convergence 8 6.0 Conclusion 8 7.0 Appendix 8

1.0 Abstract
This experiment is to get familiar with the STM32F4DISCOVERY board and use the Kalman Filter (embedded C code) developed in Lab1 to take temperature measurements. During the run of the experiment, the first Analog to Digital Converter on the board was initialized on channel 16 to allow us read the voltage values from the temperature sensor. This was then scaled to its actual value and through the Kalman filter we were able to filter out white noise from the values obtained. It was concluded that in controlled environment, the Kalman filter is a very accurate filter, converging to the actual value very quickly and being able to filter out erroneous values as well.

2.0 Problem Statement
The end goal of this experiment is to develop code that repeatedly samples the processor’s internal temperature sensor, converts measured values into degree Celsius and outputs the direction of change through the 4 LED diodes present (shown in Figure 9 of Appendix) on the board by passing it through the Kalman filter.
3.0 Theory and Hypothesis
The temperature sensor helps measuring the ambient temperature of the device. The input channel ADC1_IN16 converts the sensors output voltage into a digital value. The following formula (Figure1) is used calculate the temperature in Celsius:

Figure 1: Formula for temperature calculation
The following values were taken from the manual (Figure2) to get an accurate conversion for the Temperature in Celsius. Since we were working in volts, to keep values consistent we took the average slope as 0.0025V.

Figure 2: Temperature Sensor Characteristics
Once we obtain the value from the board, it has to be scaled to an actual temperature. Since the value is a 12 bit unsigned number, it has to be divided by 212 to get a fractional value. The range of the sensor is from 0-3 V, so this fractional value is then multiplied by 3 to get a voltage value on the scale (Assumption: The scale is linear from 0-3 V). The value we obtain can then be inserted directly into the formula for correct temperature calculation.
The color coding is described in Table1 below. We divide the temperature in 3 regions of less than 30 degree Celsius, between 30 and 40 degree Celsius and greater than 40 degree Celsius. Now depending on the trend (the direction in which temperature moves), up or down, we move in either clockwise or counterclockwise rotation to show in which region it lies.

Table 1 : Color coding scheme for the LEDs Temperature (degree C) | Change Trend | Color | Rotation | <30 | Down | Green | Clockwise (G,B,R,O) | 30–40 | Down | Orange | Clockwise (O,G,B,R) | >40 | Down | Red | Clockwise (R,O,G,B) | <30 | Up | Green | Counterclockwise (G,O,R,B) | 30-40 | Up | Orange | Counterclockwise (O,R,B,G) | >40 | Up | Red | Counterclockwise (R,B,G,O) |
4.0 Implementation

Moving Window Algorithm
In order to get a precise value of the temperature, we decided on the following moving window algorithm (Figure 3). In the initialization step, we first get the 10 readings from the temperature sensor, store it in an array and calculate its total sum. After that, instead of going through the entire loop again, for each iteration, we subtract the total sum by the last value and add the new value to get the new total sum. We can now calculate the mean by dividing the new total sum by 10 and do this step repeatedly for any new values.

Figure 3 : Moving Window Algorithm
Example of our moving window…