Digital Thermometer

The thermometer is capable to measure the air temperature in degrees Celsius or Fahrenheit with resolution of 1° and accuracy provided by the sensor IC of type LM60. The temperature readings on display is updated every 0.45 seconds. It is assumed that the measured temperature is above the freezing point, so no negative temperatures are displayed in °C.

Schematic Layout

Hardware

The thermometer consists of two main blocks connected to the microcontroller: the sensor and the display module. The analog sensor output voltage is measured by the ADC built into the microcontroller. The temperature scale (F/C) is alternated by the button. The button is connected to a pull-up resistor inside the microcontroller.

The display is driven in a multiplex mode so that only 1 digit is displayed at each moment of time. Each digit on displayed for 5 msec providing the display refresh rate of about 66 Hz. The microcontroller oscillator runs at 1 MHz frequency.

The unit is powered from a 9V external power supply. The 7805 chip converts it into 5V needed for the controller board. The 10K resistor turns microcontroller in active mode upon powering it up.

Software

The software starts with configuring the ports and setting up ADC. We use internal 1.1V ADC reference, which allows to measure the temperatures below the boiling point. The ADC has a 10-bit resolution. The conversion is performed with 125 KHz frequency, which is provided by a 1:8 system clock pre-scaler.

After all needed setup is over, the program enters the main loop. The loop starts with turning on digits 1, 2, and 3 on display. The first two digits show the temperature, while the last one indicate the scale (F/C). Each of the digits is turned on for 5 msec. After displaying all 3 digits we increment the counter time. As the counter reaches the value 30, which happens every 450 msec, the program checks the button state and selects the scale respectively. After this an ADC conversion is performed followed by a display update.

According to the sensor data-sheet, its output voltage in mV is

V = 424 + 6.25·T

where T is measured in °C. On the other hand, the ADC code, corresponding to 1100 mV voltage reference and 10-bit resolution, and its input voltage are related as follows:

V = (1100 / 1024)·ADC

(here 1020 = 210). Combining the last two equations we get

(1100 / 1024)·ADC = 424 + 6.25·T

Solving this equation for T results in

T = (44·ADC) / 256 - 1696/(25·256)

This equation is not convenient to program, so we modify it by multiplying both parts through by 256. This way we obtain:

256·T = 44·ADC - 17367

where the constant 17367 is rounded off value 17367.04. The advantage of the modified equation is that multiplication by 256 in binary is done by shifting the value 8 bits to the left. Therefore, to obtain the value of T we just can ignore the least significant byte of the right-hand side of the formula. This way even no shift operations are needed to extract the value of T out of a 16-bit value computed by the formula. The RHS of the formula involves only integer operations. Multiplication by 44 is performed by first multiplying the value by 11 and then shifting the result 2 bits to the left. Multiplication by 11, in turn, is done by multiplying ADC by 8 and by 3 and adding the results.

If the Fahrenheit scaled is selected, the value obtained above is further modified according to the formula

F = 9·C/5 + 32

by using a straightforward division algorithm. After this is remains to extract the tens and units of the temperature and store them in variables tens and units for displaying.

To keep this demo code simple I assumed that the temperature is above the freezing point (32°F or 0°C). Processing of negative temperatures still needs to be implemented. It is also assumed that the temperature in Fahrenheit does not exceed 99°F (= 37.2°C).

Downloads


Last modified:Mon, Jan 23, 2023.

00458