CheckTemp: ;Check Battery Pack temperature routine (Multiple DS18B20 I2C Sensors) Once per minute
`The owout lines become TempSensor,%1001,($55,xx,xx,xx,xx,xx,xx,xx,xx,$44) where xx = decimal serial no's for the I2C chips
`Sensor 1 (Front Battery Block)
owout TempSensor,%1001,($55,40,16,70,22,1,0,0,170,$44) ;Send ‘reset’ then ‘Match ROM’
pause 1500 ;Wait 750ms (8mhz) with strong pullup
owout TempSensor,%0001,($55,40,16,70,22,1,0,0,170,$BE) ;Send ‘reset’ then ‘Match ROM’
gosub calculatetemp ;Gosub Calculate Temperature routine
poke Temp1, CountE ;Store Front Battery Temperature in Temp1 Ram Byte
poke Temp1S, CountA ;Store Temperature Sign byte (+ or -)
`Sensor 2 (Rear Battery Block)
owout TempSensor,%1001,($55,40,14,45,234,0,0,0,75,$44) ;Send ‘reset’ then ‘Match ROM’
pause 1500 ;Wait 750ms (8mhz) with strong pullup
owout TempSensor,%0001,($55,40,14,45,234,0,0,0,75,$BE) ;Send ‘reset’ then ‘Match ROM’
gosub calculatetemp ;Gosub Calculate Temperature routine
poke Temp2, CountE ;Store Rear Battery Temperature in Temp2 Ram Byte
poke Temp2S, CountA ;Store Temperature Sign byte (+ or -)
return ;Return to main program loop
;**************************************************************************************************************
CalculateTemp:
owin TempSensor,%0000,(b16,b17) ;Read temp sensor result into w8 (b16,b17) PackTemp12
If PackTemp12 > 2047 Then ;If PackTemp12 > 2047 then temperature reading is Negative
PackTemp12 = PackTemp12 ^ $ffff + 1 ;Take twos complement of reading
CountA = 45 ;Set CountA to 45 (-) if temperature is negative
else
CountA = 43 ;Set CountA to 43 (+) if temperature is positive
endif
`Convert 12bit DS18B20 value to a valid temperature reading
CountW = PackTemp12 * 6 ;TC = value * 0.0625
PackTemp12 = PackTemp12 * 25 / 100
PackTemp12 = CountW + PackTemp12
CountE = PackTemp12 / 100
` CountE = 47 ;Test Temp Over Max
` CountE = 55 ;Test Temp Over AbsMax
if CountE > AbsMaxPackTemp then ;If Temp > AbsMaxPackTemp set Alarm Bit
Alarm4 = 1 ;Set Alarm4 Bit to 1 (Indicates Temp over AbsMax Temp condition)
endif
if CountE > MaxPackTemp then ;If Temp > MaxPackTemp set Warning Bit
Warn3 = 1 ;Set Warn3 Bit to 1 (Indicates Temp over Max Temp condition)
endif
return ;Return to CheckTemp