DigiThermo 0-100.0 °C

Wichit Sirichote, kswichit@kmitl.ac.th

Build your own a laboratory instrument for measuring time and temperature. The DigiThermo demonstrates the use of 20-pin microcontroller, c language, a dual-slope converter, LCD interfacing, and digital filtering.


DigiThermo is a device designed for measuring time and temperature used in chemistry laboratory. The circuit of Digithermo is built with a 89C4051, 20-pin CMOS Microcontroller. The microcontroller has 4kB code memory. Temperature was measured by LM35D, National Semiconductor Temperature sensor. It has the output of 10mV/°C. The CA3162, 3-digit DVM converts dc output provided by LM35D and sends BCD output to port1 (P1.0-P1.3). The firmware was written with c language. The program reads BCD output from the A/D converter, performs digital filtering, 10-point moving average and sends the readings to LCD display. A 10ms cputick was used as a timebase for producing 1 second counting. The LCD displays time in 1 s and temperature in 0.1°C resolutions.


 

Hardware:

Figure 1 shows the complete circuit diagram of the DigiThermo. The MCU is 89C4051 CMOS Microcontroller with 4kB code memory, 128 bytes On-chip RAM and 8-bit Port1 and Port3. The A/D chip is HARRIS CA3162, 3-digit DVM. The A/D converter is dual-slope integrator. It provides 10Hz sampling rate. Digital output sent to MCU is multiplexed four bit BCD started from MSD, LSD and NSD respectively.

The MSD signal was tied to P3.7 indicating the first digit to be read. Integrating capacitor is a 330nF Polyester type. The 10k POT connected to pin13 is for gain adjustment and 50k POT to pin 8 and 9 is for zero adjustment. The input of the converter is true differential having pin 11 for HI and pin 10 LO signal. Temperature was measured by a precision solid-state sensor LM35D. The output signal is 10mV/°C.

Since the A/D converter is capable of providing 0-1000mV readings with 1mV resolution, thus the converter can resolve 0.1°C (not absolute accuracy). The 100k and 0.02uF capacitor forms the first order low-pass filtering. The 16x1 line LCD is connected in 4-bit interfacing to P1.4-P1.7 with control signal RS and E to P3.4 and P3.5 respectively. The +5V power supply uses a 78L05 TO92 case with external +9V adapter. FB is ferrite breed used to provide hi-impedance path from digital power supply.

Figure 1: Circuit diagram

Software:

The program thermo.c was written in ‘C’ language and was compiled by Micro-C Compiler from Dunfiled Development Systems. The memory model is TINY. The hex file of thermo.c suitable for downloading by Easy-Downloader V1.1 is thermo.hex. Variables and stack use the area of 128-byte on-chip RAM. Figure 2 shows pseudo code of the control program.

Figure 2: Pseudo code of program thermo.c

Main program separates tasks into four tasks, i.e., time( ), putxin( ), puttemp( ), and puttime( ). These tasks were executed every 100ms. Time( ) set FLAG1 bit0, bit1 and bit2 when time has elapsed 100ms, 1st 10 count, and 1s respectively.

Putxin( ) shifts a converted digital word to LSW of 10-word registers performing 10-point data moving.

Puttemp( ) computes average value of 10-sample and put to LCD buffer.

Similarly puttime( ) writes variable count to LCD buffer.

The device driver routines are readadc( ), read BCD from CA3162, LCDINI( ), initialize LCD, LCDWI( ), write LCD instruction, LCDWD( ), write ASCII code to LCD buffer, pulseE( ) generates Enable pulse, and delay(n), delay n milliseconds.

As can be seen in the listing of thermo.c program, some function has embedded assembly code because of time critical requirements. Variable ACC and temp are used to pass value to and from ‘C’ program. Please study in details writing style and variables usage.

Zero and Gain of A/D Adjustment

Before inserting LM35D, A/D needs a bit adjustment by adjusting ZERO which done by short pin HI and LO to GND. Then adjust 50k POT at pin 8 and 9 until temperature reading is 0. Put the reference voltage source 500mV to input of the A/D, adjust 10k POT until display shows 50.0.

Calibrating Temperature Reading

Although the LM35D is calibrated to Celsius, gain of the CA3162 may influence directly to accuracy of the reading. It is good idea to make calibration with standard thermometer. Theoretically, the standard thermometer to be used as a reference should provide more precision at least one order. Suppose we want to calibrate our Digithermo with precision of 0.1 °C, the standard reference should have precision at least 0.01 °C. Not easy to find the reference right? Assume you may get one but having only 0.1 °C resolution for our calibration. First you need to have a temperature reservoir to put the reference thermometer and LM35D probe together. Ensure both are at the same temperature. Let the temperature range to be calibrated is 0-20.0 °C. Start records both readings from 0 to 20.0 by slowly warming the reservoir. An exemplary (not real measurement) of such recording data would be as shown in Table1.

TABLE 1 Recording of Temperature read by DigiThermo and Reference Thermometer

Sample DigiThermo 

Reading('C)

Reference 

Reading('C)

1 0.0 0.1
2 1.0 0.9
3 2.0 2.1
4 3.0 3.2
5 4.1 3.9
6 5.2 5.0
7 6.0 5.9
8 6.9 7.1
9 8.0 8.3
10 9.3 9.1
11 10.2 10.5
12 11.0 11.2
13 12.1 12.6
14 13.3 13.0
15 14.6 14.2
16 15.5 15.1
17 16.8 16.3
18 17.1 17.3
19 18.0 18.4
20 19.1 19.5

To find the correlation between our instrument and the reference may easily done by using linear regression function in Excel spreadsheet. Plot the reading of the Digithermo in X-axis and reference in Y-axis. Plot trend line using linear least square, we get the correlation equation as Y = 1.0053X - 0.0115. With this equation, reading from Digithermo is then easily be adjusted to the value read as read by reference thermometer. However the 1st version of DigiThermo does not provide such equation in the source program. Student should try insert the equation with some adaptation, since Micro-C math provides only integer mathematics.


Build Your Own uC Projects

22 October 1999

Recovered 18 December 2015