Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Digital Thermometer Ds1620&amp Pic

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

digital thermometer

It would be all too easy to describe the 081620 as a simple temperature sensor: in the present circuit, the device doubles as a thermometer with a wide temperature range, and a programmable thermostat with switching outputs and hysteresis. The 081620 is coupled to a Pie microcontroller which is programmed to store the digitized temperature, send it to an R8-232 interface, and show it on a bright LEO display.
Essentially, the
circuit consists of a microcontroller type

PIC16C54 and a digital thermometer/thermostat IC type 051620 frorn Dallas Semiconductor. Depending on the programnung of the microcontroller; a plethora of functions and applications is available. Here, the main task of the microcontroller is to look after the serial data traffic with the sensor. The main additional functions provided by the microcontroller program are:
in-circuit programming of the tem-

Specification
Thermometer

V V V V V

Two-digit display Adjustable range lrom - 40 to +80C Error smaller than 0.5% (-10 to +80C) Adjustment-Iree MiniMax lunetion RS-232 output, temp. in steps 010.5 K

perature switching threshold, storJng the minimum and maximum measured temperature, periodic
Design by G Sttppler outputting of measurernent values

Thermostat v Upper and lower switehing levels Ireely adjustable v Two relay outputs, 5 A, 2 x cto

14

Elektor Electronics

4/97

via a simple RS-232 interface, and, last but not least, indiceting the temperature on a two-digit LED display. Moreover, the present circuit enables any DS1620 chip to be programmed for stand-aJone as a thermostat (i.e., without a CPU).

Tabte 1. 051620 Command Overview


Value (Hex) Command Write Config Write TL Write TH Read Contig Read TL Read TH Read Temp Description Write contiguration data into Contig Register limit into TL Register limit into TH Register limit trom TL Register limit trom TH Register

oe
02 01 Ae A2 AI
AA

Write low temperature Write high temperature Read configuration Read low temperature Read high temperature

data trom Contig Register

THERMOMETER AND THERMOSTAT IN ONE Figure 1 illustrates that modern temperature sensors such as the D51620 consist of more than just an integrated temperature sensor. As you can see, the D51620 contains a series of functional groups which allow many applications to be realized without complex and extensive peripheral circuitry. 11,e DS1620 has two modes of operation. In stand-alone mode. the sensor lC operates as a simple thermostat, requiring the upper and lower ternperature limits (switching levels) to be programmed, along with a coupie of other parameters, before i t can be used. The parameters are stored in a non-volatile memory, where they are safe against any interruption of the supply power. In theory, this mode allows the 051620 to be employed without any additional external components (weil, except a supply). In practice, drivers (buffers) may be useiul at

Je

Reads fast measured temperature nom Temperature register measurement measurement

EE
22

Start Convert T Start temperature Stop Convert T Sfop temperature

Tabte 2. Configuration Byte 5tructure


Bit 8 DONE Zero: conversion aetive, One: eonversion done Temperature-High Flag goes to 1 when the limit is equal to, or exceeds, the temperature, and remains at 1 until the memory loeation is overwritten with a zero, or the supply power is switched off. Temperature-Low Ffag goes to 1 when the limit is equal to, or sma/ler than, tne temperature, and remains ar 1 until the memory loeation is overwritten with a zero, or tne supply power is switched off. no function Zero: Stand-alone mode, Pin 2 - Cl5NV with RST zero at the same time; One: 3-wire mode with CPU, Pin 2 = CLK. CPU bit stored in EEPROM. Zero: eontinuous temperature measurement; One: single temperature measurement controlled by CONV (START Convert T), then return to stand-by state. Wait 10 ms after writing to EEPROM.

Bit 7

THF

Bit 6

TLF

Bit

5, 4, 3

Bit 2

CPU

Bit 1

ISHOT

D51620

CONV/CLK

ADDRESS

AND
RESET

RST

954076-12

tion in this rnode, and is held at OV A negative pulse at pin2 (CONV) causes a temperature measurement to be started, while a continuously low level at the CONV pin selects permanent operation as a thermostt. In 3-wire mode the 051620 may be eoupled to a mtcrocontroller; Only this mode allows the JC registers to be accessed by reading and writing. The R5T terminal Is the active-Iow reset input of the chip; CLK, the clcck input, and OQ the port through which data may be read or written. A data transfer via the DQ port eonsists of two bytes. The first, the protocol byte, identifies the meaning of the data of the second byte. As shown in Table 1, three write commands are available, and four read commands. Furthermore, the last two commands enable a temperature measurement to be

the outputs, as well as relays, overvoltage protectors, acoustical or optical alarm actuators, or opto-isolators. Such devices are also used in the present circuit. The measured and digitized temperature is compared by a seetion called digital comparatorllogic. The cornparison is against two Iimi ts called high temp trigger (TH) and IOlU temp trigger (TL). Depending on the actual situation, the comparator output actuates
Elektor Electronics 4/97

Figure 1. Internat organization the 051620 thermostat/thermometer IC.

0'

Tabte3. Temperatureldata retation


Dig;tal Temperature MSB LSB Value

nexeaecsmet
OOFA 0032 0001 0000 01FF 01eE 0192

+ 125 "C one of three outputs: TH when the temperature exceeds the upper limit, TL when the temperature drops below the lower Iirnit, and TCOM, which eouples TH and TL to give a hysteresis function. The R5T connection has no func+25 -c +0.5C

011111010 00011 0010 000000001 000000000

o -c
-0.5

-c

111111111
111001110 1 1001 0010

-25 -c -55 -c

15

5V

5V

1N41480

K'

'i'

"

er

" " '" "

ca

J!0Gn
(;)
' 2 00 IC2
CLK OS

TI<

~ ~

RST1620

...

rc s

TI.

IC3a

lN4148

ts>
5V

+
re

@j

0J

" , te

..
re

(;)
IC,

".
'" '"
,

(;)
IC5

ra e tz

".
2700 210n 2700 2700 2700 271m 2700

,., '" PIC16C54 Ra3 '" , MCLR '" '" "


srcc
oscr

'"

6 8 74lS247 D to

"

<y-

6V6

".
'"

rs
G

"

:; 0:0 :: a=o ;:0=00 ;: 0:00 ,


'"a
HD1105

'"

'"

HOll05

@)--7V
@)--9V4

@)-SV

C9t!:) @:>

GV
O/SV

OlOV8 SIOV6

CE>-

IC3 '" 74L500

r I
IC3 96011211

Figure 2. The digital thermometer/thermostat is controlled by a PIe microprocessor.

started or stopped, without the need

for a second byte to foUow the protocol byte. The configuration byte in the register called stutus register & controllogic has special significance. Bit 2 of this

byte. the CPU-bit, determines whether the 051620 operates in stand-alone mode or 3-wire mode. In fact, the CPUbit determines the function of pin 2: CONV or CLK. The other bits of the configuration byte describe the status of the DS1620, and are only of interest for read operations. Their exact meaning is given in Table 2. Because a measurernent range of - 55C to +125 "C means that 360 discrete temperature

steps have to be displayed, aresolution of nine bits is required. According to the protocol byte, all commands that concern input or output of a tempereture have nine instead of eight bits. and are transmitted LSB-first. The relation between temperature and transmitted data is shown in Table 3. The value rtses from OOOOH 0 "C to OOFAH at at 125 "C. The negative part of the range is outpur as a two's comple-

Table
300 310 320 330 340 350 360 370 3BO 390 392 396 420 430 440 450 460 470 4BO

4_

Temperature Acquisition in BASIC


bit

CLS:CLOSE:DEFINT A-Z:FALSE=O:TRUE=NOT FALSE:DEFSNG T:ON ERROR GOTO 460 XOFF$=CHR$(19):XON$=CHR$(17) OPEN "com1:1200,n,8,l" AS #1 '1200 Baud, no parity, 8 data bits, 1 stop OPEN "scrn: "FOR OUTPUT AS #2 "sc reen as file LOCATE ,,1:PAUSE=FALSE B$=INKEY$:IF B$ <> "" TEEN PRINT #l,B$; IF EOF(l) THEN 350 'check input if no characters IF LOC(l) > 128 THEN PAUSE=TRUE:PRINT #l,XOFF$; 'buffer > half full A$=INPUT$(LOC(l) ,#1) 'read buffer contents TEMP=ASC{A$):HG=TEMP AND &H80:MINUS=TEMP AND &H40:TEMP""TEMP AND &H3F IF HG=128 THEN TEMP""TEMP+.5 IF MINUS=64 THEN TEMP=TEMP* -1 PRINT "Temperature: ";: PRINT USING "###. #" i TEMP i :PRINT " degrees C at "; :PRINT TIME$ IF LOC{l) > 0 THEN 370 IF PAUSE THEN PAUSE=FALSE: PRINT "# I, XON$; GOTO 350 REM Error processing RESUME

END

16

ElektorElectronics

4/97

ment: - 0.5 C corresponds to OlFFH. The lowest temperature that can be measured, - 55C, then produces an output value of 0l92H. In this arrangement, the ninth bit (M5B) becomes the sign bit.

THE

PIe

MICROCONTROLLER The measured value is to be transmitted via the R5-232 interface as an 8-bit dataword. A complete cyde starts with a read access to the ni ne bits of the temperature register of the D51620. This happens so fast (approx. 100 kHz) that the R5-232 interface (set to 1200 baud) does not res pond. Next, CLK goes high, causing the DQ out-

put to switch to the high-impedance state. The value read is shortened to eight bits, and subsequently transmitted via the R5-232 interface, using the protocol: 1200 baud, no parity, 8 databits, 1 stop bit. The syncopation to eight bits causes the measurement range to be reduced to - 40 to +80 "C. The order of the databits is also changed: the first seven bits indicate the temperature (in whole degrees centigrade), where bit 7 acts as the sign bit (+ or - ). The eighth bit is the halfdegree bit. The simple GW-BA5IC terminal program shown in Table 4 uses these values to compute the corresponding temperature between - 40 and +64C at aresolution of 0.5 "C, and sends it to the PC display to-

gether with the current time. Extending the temperature range to +80C is relatively easy by processing the double function of bit 7, which is at logic 1 at temperatures below 0 C and above 63 "C, If bit 7 changes from 0 to 1, the software should be able to interpret the trend to tell which of these temperatures is being measured.

INTERFACES Disregarding, for the moment, the D51620 and the microcontroller, then it is fair to claim that nearly all components that go into the present thermostat/thermometer are part and parcel of some kind of interface. The physical structure of the R5-232

I Figure 3. pes

artwork.

COMPONENTS LIST Resistors:


R1 ,R2,R3,R5,R7-R1 0,R12 = 10kQ R4,R6,R13,R14,R15 = 680Q R11,R16-R22 = 270Q

Capacitors:
C1,C2,C8 = 100,uF 25V radial C3,C4 = 100nF C5,C6 = 22pF C7 10,IF 63V radial C9 = 100,uF 10V radial

Semiconductors:
01,02,04,06 = 1N4148 03,05 = LEO 010 = 1N4001 07 = LEO, rectangular model T1,T2 = SC547S T3,T4 = SC557S IC1 = LM741 IC2 = OS1620 (Oallas Semiconductor) IC3 = 74HCTOO or 74LSOO IC4 = PIC16C54, programmed, order code 966501-1 IC5 = 74LS247 IC6 = 7805

Miscellaneous:
K1 = 9-way sub-O socket, PCS mount, angled pins K2,K3 = 2-way PCS terminal block, pitch 7.5mm K4 = mains adaptor socket S1 = Push-button, make contact S2,S3 = Oigitast press-key with internal LEO Re1,Re2 = Siemens V23127-A1A101 (6V) or V23127-A8-A101 (5V) X1 = 4MHz quartz crystal ~01 ,L02 = H01105 (Siemens) Enclosure: size approx. 145x95x34mm (Pactec) PCS and programmed PIC: set order code 960112-C (see Readers Services page)

Elektor Electronics

4/97

17~

Interface is both simple and unusual. Even the familiar MAX232 which would be expected here was considered a superfluous luxury. Because the interface has a transmit path only, and does not make use of areturn channel, the simplest of all Ks, the LM741, is adequate for our purpose. The positive supply voltage of the Ie is derived from the DSR line on the RS-2J2 interface, while the negative bias is obtained from the inactive transmit line, RxD. The non-inverting input of lCl being held at a potential of 2.5 V, the output will swi.ng between the two extreme RS-232 voltage levels in accordance WiU1 databits supplied by the PIe the This creates a simple seria.llink without a special symmetrical supply. Returning to the PIe, pcrt lines RBO-RB3drive a two-djgit display via a 4-bit-to-7-segment decoder (le5). The display is multiplexed via port RB7, lC3, T3 and T4. The sign is handled by

latter two switches. The LEDs have double end even triple functions, however. When the circuit is switched on, the display first reads 00 for few seconds, then the first measured temperature appears. Keeping the TH key pressed for a while causes the integral LED to light, and the value representtng the upper temperature limit to appear on the display. Release U1ekey: the LED will continue to light, and the highest ternperature measured since resetting the circuit is displayed for a few seconds. To program a new upper Iimit, keep TH pressed, and step to the desired value by repeatedly presstng the TL key. At a setting of 80 "C, the displey jumps to - 40 "C, If the desired value is reached, keep the TL key down, release TH, and then TL. The new

port RB6 which controls a reetangularface LED, D7. This indicator is fitted to the left of the displays, and indicates a minus sign when lit. The two relays are controlled by the thermostt outputs on the DS1620, with the help of drivers. The relays may switch loads up to 5 A. The type indicated in the parts list is a 6-volt relay. A better alternative, although harder to find, is the corresponding 5volt version (V23127 A8 AIOl), also from Siemens. The status of the LEDs is indicated by LEDs D3 and D5. The TC (hysreresis) terminal is not used here. ff you need it for switching purposes, however, stmply gtve it a driver and a relay just as the TH and TL outputs.

OPERATION

The operator controls and indicator elements of the thermostt are U1ethree push-buttons, Reset. TH and TL, and the integral LEDs, D8 and D9, in the
Elektor Electronics 4/97

value is then programmed, and will remain on the display for a few seconds. If you do not press TL, the old value is retained. The lower switching limit is changed likewise, with the functions of the TH and TL keys interchanged, of course. To clear the min./max. memory, or set it to the current temperature, press TH and TL simultaneously. This action is recommended when the unit is first switched on, because the minimurrt value displays 00 until the first frost occurs. To switch the DS1620 to thermostat mode, keep the TL key pressed while you press the Reset key. In this way, the Cf'Ucbit in the status register is changed. Also, the controller enters the sleep mode, reducing the current consumption to that of the LEDs and the relays. Pressing Reset egain switches on the thermometer function again. The display will then read '00' initially.

It is recommended to first decide on the actual application you have in mind for the thermostat even before you start buytng components. 1f it is required that the circuit remeins fully operational even at very low temperatures. then parts with an extended temperature range speci.ficationshould be purchased. The PIe controller supplied by the Publishers (see Readers Services page) is progra.mmed for a temperature range of -40 to +85 "C. Purchasing parts for the project becomes easier if you expose the circuit to temperatures below 0 >;OC thermoin stat mode only, when most of the circuitry is 'asleep'. Populating the large and c1early leid out printed circult board should not cause undue difficulty. TI1e track layout and component mounting plan are shown in Figure 3. Like the PIe controller, the board is available fram the Publishers. Start by fitring the six wire links on the board, so that these are not forgotten later. Sockets may be used for a11lCs, but do bear in mind that they may cause problems in humid or very cold conditions. The LEDs, displays and press-keys are fitted at the same height, so that they rise above the other parts (in particu1ar, the peB terminal blocks and the connectors). Havtng finished the work on the board, give it a thorough visual inspection. lf everything appears to be okay, you may connect a 9-V mains adaptor to K4 (watch the polarity). Next, check the presence of the +5 V supply voltage on all re supply pins (directly on the IC pins, not at the 501der side of the board). Assuming that '00' is being displayed, the current consumption of the circuit amounts to about 80 mA. If the display remains dark, you should first check whether the programmed PIC operates properly Pin 13 (RB7)should supply a rectangular signal with a rcpeat rate of 1.6 ms. This is the display multiplextng signal. Next, use an oscilloscope to check for oscillator activity at pin 15 of the PlC (the measured level should be about 2 V). A properly working PIe supplies clock pulses at 5-second intervals on pin 1 (RA2). The DS1620 responds to these dock pulses by issui.ng data at pin 1 (DQ). This Is readily traced with a digital oscilloscope, but not so, unfortunately, with an analogue scope or a DVM. If everytlung works, the circuit may be fitted into a weather-proof case. A few ventilation holes, protected against water ingress, may be dnlled near the sensor Ks. (960112)
Note: datasheet extracts of the 051620 may be found in the January 1997 issue, pages 69/70.

19

You might also like