Description: 1k DQ CLK RST GND VDD T (Hi) 1
Description: 1k DQ CLK RST GND VDD T (Hi) 1
The digital thermometer on a chip, capable of replacing the normal combination of temperature sensor and analog-to-digital converter in most applications. It can measure temperature in units of 0.5 Centigrade (C) from 55 C to +125 C. [In Fahrenheit (F), units of 0.9 F and a range of 67 F to +257 F.] Temperature measurements are expressed as nine-bit, twos complement numbers. The thermometer communicates with a microcontroller such as the PIC or Stamp through a three-wire serial connection. The thermometer can also operate as a standalone thermostat. A temporary connection to a controller establishes the mode of operation and high/low-temperature setpoints. Thereafter, the chip independently controls three outputs: T(high), which goes active at temperatures above the high-temperature setpoint; T(low), active at temperatures below the low setpoint; and T(com), which goes active at temperatures above the high setpoint, and stays active until the temperature drops below the low setpoint.
Hardware interface
The thermometer interfaces with controllers through a three-wire connection, consisting of a data input/output line (DQ), a synchronizing clock line (CLK) and a reset/select line (RST). The figure shows how to connect the thermometer to the PIC or Stamp for the demo programs. Do not omit the bypass capacitornot even if you feel that your power supply is solid and well-filtered. Locate that cap as close as practical to the supply leads of the thermometer. Although the 1k 3 resistor is not strictly necessary as long as the firmware is functioning 2 correctly, its best to leave it in. In the event that both the controller (PIC or Stamp) and the thermometer try to drive the data line at the same time, 1 the resistor limits the amount of current that can flow between them to a safe value.
+5
1k
0.1F
DS1620
PIC
Stamp
1 2 3
Software interface
From a software standpoint, using the thermometer boils down to this: (1) Activate RST by taking it high. (2) Send an instruction (protocol) to the thermometer telling it what you want to do. (3) If you are reading data, shift it into the controller (PIC or Stamp). (4) If you are writing data, shift it out to the thermometer (5) Deactivate RST by taking it low. The program listings and data sheets show these processes in detail.
:loop
; * Note that the thermometer can only perform one conversion per second. ; With a 4-MHz clock, this demo routine reads it about five times a ; second. This doesn't do any harm, since the thermometer provides the ; old reading until a new one is available, but it doesn't do any ; good either! In an actual application, you'll want to read the 'thermometer ; only as often as appropriate.
:begin :loop
mov mov movb setb rr clrb movb mov snz snb setb djnz ret
!ra,#DQout bits,#9 c,sign RST DSdata CLK DQ,c w,--bits clk9 CLK bits,:loop
; Set to output. ; Set up for 8- or 9-bit transfer. ; Put bit8 (sign bit) into carry. ; Activate the thermometer. ; Rotate bit0 of DSdata into carry. ; Set up for clock pulse ; Move carry bit to input of thermometer ; Pulse the clock line for each of ; first 8 bits. On the ninth bit, ; pulse the clock only if clk9 = 1. ; Finish the pulse if conditions are met. ; Loop 9 times.
:loop
; Set DQ to input. ; Nine-bit transfer. ; Clear carry bit. ; Move carry into bit7, shift bits right. ; Clock in the bit on falling edge. ; Get the bit ; Finish the clock pulse. ; Loop 9 times. ; Deactivate the thermometer
; General-purpose delay routine (200+ ms at 4 MHz). ; Not required by thermometer rutines per se, but used to wait for EEPROM ; programming cycles to finish (50 ms max) and to wait an interval ; between temperature readings. delay djnz djnz ret temp1,delay temp2,delay
' The loop below continuously reads the latest temperature data from ' the thermometer. The 'thermometer performs one temperature conversion per second. ' If you read it more frequently than that, you'll get the result ' of the most recent conversion. The 'thermometer data is a 9-bit number ' in units of 0.5 deg. C. See the ConverTemp subroutine below. Again: pause 1000 let DSout=Rtemp gosub Shout gosub Shin low RSTn gosub ConverTemp gosub DisplayF gosub DisplayC goto Again
' Wait 1 second for conversion to finish. ' Send the read-temperature opcode. ' Get the data. ' Deactivate the thermometer ' Convert temperature reading to absolute. ' Display in degrees F. ' Display in degrees C.
' If temp > 0 skip "sign extension" procedure. ' Make bits 9 through 15 all 1s to make a ' 16-bit two's complement number. ' Add 110 to reading and return.
' Subroutine: DisplayF ' Convert the temperature in DSabs to degrees F and display on the ' PC screen using debug. DisplayF: let w1 = w0*9/10 if w1 < 67 then subzF let w1 = w1-67 Debug #w1, " F",cr return subzF: let w1 = 67-w1 Debug "-",#w1," F",cr return
BASIC Stamp I (BS1-IC) and BASIC Stamp Ver. D Program Listing: Thermostat
' Program: DS_STAT.BS1 ' This program interfaces the Digital Thermometer to the ' BASIC Stamp to configure it for thermostat operation. A PC ' running terminal software, should be connected to the Stamp ' with data out to pin 4 (through a 22k resistor) and data in ' to pin 3: ' ' ' ' Function GND Transmit Receive DB25 Pin DB9 Pin Stamp Pin 7 5 GND 2 3 4 3 2 3
' Hardware handshaking must be disabled in the terminal software. ' Communication format is 2400 baud, no parity, 8 data bits, ' 1 stop bit. The Stamp prompts the user for the high and low ' temperature setpoints, then copies these to the registers of the ' thermometer. The setpoints _must_ be preceded by the appropriate sign ' (+ or -). The program does not assume that "78" means "+78." ' Once the thermometer is programmed, the circuit should be turned ' off, and the thermometer removed for installation in its standalone ' thermostat application. ' ===================== Define Pins and Variables ================ SYMBOL ComIn = 4 ' Serial communication input pin. SYMBOL ComOut = 3 ' Serial communication output pin. SYMBOL DQp = pin2 ' Data I/O pin. SYMBOL DQn = 2 ' Data I/O pin _number_. SYMBOL CLKn = 1 ' Clock pin number. SYMBOL RSTn = 0 ' Reset pin number. SYMBOL DSout = w0 ' Use bit-addressable word for DS1620 output. SYMBOL DSin = w0 '" " " word " " input. SYMBOL clocks = b2 ' Counter for clock pulses. SYMBOL config = b3 ' Copy of the DS1620 configuration bits. SYMBOL setTemp = w2 ' Copy of the temperature setting. SYMBOL comData = b6 ' Serial input data. SYMBOL index = b7 ' Temporary counter used in prompts. ' ===================== Define DS1620 Constants =================== ' >>> Constants for configuring the DS1620 SYMBOL Rconfig = $AC ' Protocol for 'Read Configuration.' SYMBOL Wconfig = $0C ' Protocol for 'Write Configuration.' SYMBOL CPU = %10 ' Config bit: serial thermometer mode. SYMBOL NoCPU = %00 ' Config bit: standalone thermostat mode. SYMBOL OneShot = %01 ' Config bit: one conversion per start request. SYMBOL Cont = %00 ' Config bit: continuous conversions after start.
' Send read protocol to the thermometer. ' Get the data. ' Deactivate 'thermometer. ' Compare to the value written. ' If they're different, print "fail" msg. ' Now set up to prompt for lo temp.
' ..compare it to value sent. ' If they're different, print "fail" msg. ' Else, print "OK". ' Stop until power cycles.
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 18
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 19
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 20
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 21
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 22
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 23
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 24
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 25
sales / technical support (916) 624-8333 fax (916) 624-8003 [email protected] [email protected]
Page 26