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.
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.
init variable
init LCD module
put title message to LCD buffer
do forever
{ do the following tasks every 100 ms;
time(); /* update time base */
putxin(); /* put converted digital data to 10-word FIFO buffer */
puttemp(); /* put temperature reading to LCD */
puttime(); /* put second counter to LCD */
}
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.
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.
22 October 1999
Recovered 18 December 2015