PDA

View Full Version : DS1620 temperature sensor in high resolution mode



crodan
- 13th March 2007, 05:01
Hello has anyone got any code examples to use the DS1620 in hight res mode and displaying the result on a 16x2 LCD. I have been trying to modify the melabs ds1620 example using an example of basic stamp code for high res mode and I keep on getting very strange results.

Here is the code example from melabs
http://www.melabs.com/resources/samples/x1/pbp/temp3x.bas

Here is the code from the high res basic stamp (About half way down the page
http://www.emesystems.com/OL2d1620.htm


Any help you be much appreciated as I have been trying most of last weekend and I feel like riping my hair out. :)

crodan
- 14th March 2007, 05:14
Here is the code I have mashed together using the BS and Picbasic examples. I keep on getting very strange numbers in the 1000's. I have allready set the registers in the DS1620 eeprom.

Here is the app note from dallas about the increased res functions of the ds1620
http://pdfserv.maxim-ic.com/en/an/archive/AN68.pdf


Define LOADER_USED 1

Include "MODEDEFS.BAS"

' Define LCD pins
Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 5

' Alias pins
RST var PORTA.0 ' Reset pin
DQ var PORTA.1 ' Data pin
CLK var PORTA.2 ' Clock pin

' Allocate variables

j var byte
i var word
x var word
remain var word
slope var word
degC var word


Low RST ' Reset the device


PAUSE 500

Low PORTA.4 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start

Lcdout $fe, 1, "Temp in C" ' Display sign-on message




mainloop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0

Pause 1000 ' Wait 1 second for conversion to complete

RST = 1
Shiftout DQ, CLK, LSBFIRST, [$AC] ' Send read command
Shiftin DQ, CLK, LSBPRE, [x] ' Read 9 bit temperature
RST = 0
IF x.bit7=0 then pause 1000






RST = 1
Shiftout DQ, CLK, LSBFIRST, [$AA] ' Send read command
Shiftin DQ, CLK, LSBPRE, [x\9] ' Read 9 bit temperature
RST = 0

x.byte1= -x.bit8 ' extend sign
degc=x*5 ' compute to 10ths, +/- 0.5 degree C

RST = 1 ' get the count remaining DS1620
shiftout DQ, CLK,lsbfirst,[$A0]
shiftin DQ, CLK,lsbpre,[remain\9]
RST = 0



RST =1 ' get the counts per degree
shiftout DQ, CLK,lsbfirst,[$A9]
shiftin DQ, CLK,lsbpre,[slope\9]
RST =0

x=slope-remain*10/slope ' compute 1/100ths degree
degc=degc+550/10*100+x-552 ' adjust temperature to 1/100ths
pause 1000


' Display the decimal temperature


LCDout $fe, 1, rep "-"\degc.bit15,dec abs degc/10,".",dec1 abs degc
goto mainloop ' Do it forever

End

crodan
- 15th March 2007, 04:01
Double post sorry

crodan
- 15th March 2007, 04:03
I'm not sure but I have been modifying the code and I think the problem is displaying the temp on the lcd and I am not displaying/changing it correctly

From dallas app note 105

DS1620, DS1623, and DS1625:
1. Issue Start Convert protocol (EEh).
2. When conversion is finished, read 9–bit temperature value (AAh).
3. Truncate half–degree bit from reading.
4. Convert truncated value from 2’s complement to signed integer (named temp_read).
5. Read 9–bit counter value (A0h; named count_remain).
6. Send undocumented Load Counter protocol (41h).
7. Read 9–bit counter value (A0h; named count_per_degree).
APPLICATION NOTE 105
4 of 20
8. Calculate high–resolution temperature using the high resolution temperature equation given in the
previous section.

The equation is tempreture=˝ LSB = 0.25.temp_read-1/2 LSB + (count_per_degree - count_remain)/count_per_degree


When I use the code on the lcd
Lcdout $fe, 1, dec (degc >> 1), ".", dec (degc.0 * 5), " degrees C"

The lcd displays 2562

When I use the code on the lcd
Lcdout $fe, 1, rep "-"\degC.bit15,dec abs degC/10,".",dec2 abs degC

The lcd displays 51.24

My maths is quite bad and some parts look very alien to me so if anyone has got any sugestions on what I can try.