SG09
10-31-2009, 09:14 AM
Below is a program I am trying to run to control the operation of my solar thermal heating system.· The intro describes how it might operate.· Thanks to the good people of this forum and the sample code from PH Anderson (vendor for the one-wire interface), I was able to actually measure and display the temperatures measured by the DS18S20s.· I am trying to write the code that actually compares the two temps and then takes action (haven't gotten to the actual relay control stuff yet).· The way I have the IF THENs written, the program seems to ignore the values of the two temps and simply writes the debug statement to the screen.· I tried looking for examples, but I am lost!· Please help, it will be cold soon.
Thanks!
' {$STAMP BS2}
' {$PBASIC 2.0 }
'This program measures the temperatures of the solar thermal panel and the storage tank.· When the panel is ten or more degrees warmer than the storage tank,
'a signal will be sent to start the circulating pump.· When the temperature of the panel cools to the temperature of the tank, a signal will be sent
'to stop the pump.· Controller will then continue to monitor·both temperatures.
··· BaudMode· CON· 84········· '9600 True
··· X VAR Word
··· Y VAR Word
··· degF1 VAR Word
··· degF2 VAR Word
··· SignBit VAR Byte
··· Whole VAR Byte
··· Fract VAR Byte
··· DIR7 = 0· ' serial input
··· DIR8 = 1· ' serial output
··· OUT8 = 0· ' be sure SerOut pin is stable at zero
··· 'Measure temperature on Channel 1 (Panel Temperature)
··· PAUSE 1000
DO
AGN:
··· SEROUT 8, BaudMode, 10, ["P0", "W0cc", "S044"]· 'perform temp meas
·········································· ' note strong pullup
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, ["P0", "W0cc", "W0be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, ["R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, ["R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [DEC X.HIGHBYTE]
··· PAUSE 100
········· ' now do the calculations
····· x = x * 5·· ' multiplication works okay in twos complement
········ 'Now show degrees Fahrenheit
··· degF1 = x + 178 * 9 / 5
··· DEBUG REP "-"\degF1.BIT15, "Panel = ", DEC ABS degF1/10, ".", DEC1 ABS degF1, CR
··· PAUSE 2000 ' wait 2 secs
··· '-----------------------------------------------------------------------------------
··· 'Now measure temperature on Channel 2 (Tank Temperature)
··· SEROUT 8, BaudMode, 10, ["P1", "W1cc", "S144"]· 'perform temp meas
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, ["P1", "W1cc", "W1be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, ["R1"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, ["R1"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [DEC X.HIGHBYTE]
··· PAUSE 100
···················· ' now do the calculations
····· x = x * 5·· ' multiplication works okay in twos complement
········ 'Now show degrees Fahrenheit
··· degF2 = x + 178 * 9 / 5
··· DEBUG REP "-"\degF2.BIT15, "Tank =· ", DEC ABS degF2/10, ".", DEC1 ABS degF2
··· PAUSE 2000 ' wait 2 secs
··· '_________________________________________________ ________________________________
··· 'Now compare the two values and turn pump ON if conditions are true
····· IF (degF1 >= (degF2 + 10)) THEN· StartPump:
··· StartPump:
··· DEBUG "Pump is ON", CR
····· IF (degF1 <= degF2) THEN StopPump:
···· StopPump:
··· DEBUG "Pump is OFF", CR
···· Timeout:
GOTO AGN:
Thanks!
' {$STAMP BS2}
' {$PBASIC 2.0 }
'This program measures the temperatures of the solar thermal panel and the storage tank.· When the panel is ten or more degrees warmer than the storage tank,
'a signal will be sent to start the circulating pump.· When the temperature of the panel cools to the temperature of the tank, a signal will be sent
'to stop the pump.· Controller will then continue to monitor·both temperatures.
··· BaudMode· CON· 84········· '9600 True
··· X VAR Word
··· Y VAR Word
··· degF1 VAR Word
··· degF2 VAR Word
··· SignBit VAR Byte
··· Whole VAR Byte
··· Fract VAR Byte
··· DIR7 = 0· ' serial input
··· DIR8 = 1· ' serial output
··· OUT8 = 0· ' be sure SerOut pin is stable at zero
··· 'Measure temperature on Channel 1 (Panel Temperature)
··· PAUSE 1000
DO
AGN:
··· SEROUT 8, BaudMode, 10, ["P0", "W0cc", "S044"]· 'perform temp meas
·········································· ' note strong pullup
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, ["P0", "W0cc", "W0be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, ["R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, ["R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [DEC X.HIGHBYTE]
··· PAUSE 100
········· ' now do the calculations
····· x = x * 5·· ' multiplication works okay in twos complement
········ 'Now show degrees Fahrenheit
··· degF1 = x + 178 * 9 / 5
··· DEBUG REP "-"\degF1.BIT15, "Panel = ", DEC ABS degF1/10, ".", DEC1 ABS degF1, CR
··· PAUSE 2000 ' wait 2 secs
··· '-----------------------------------------------------------------------------------
··· 'Now measure temperature on Channel 2 (Tank Temperature)
··· SEROUT 8, BaudMode, 10, ["P1", "W1cc", "S144"]· 'perform temp meas
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, ["P1", "W1cc", "W1be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, ["R1"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, ["R1"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [DEC X.HIGHBYTE]
··· PAUSE 100
···················· ' now do the calculations
····· x = x * 5·· ' multiplication works okay in twos complement
········ 'Now show degrees Fahrenheit
··· degF2 = x + 178 * 9 / 5
··· DEBUG REP "-"\degF2.BIT15, "Tank =· ", DEC ABS degF2/10, ".", DEC1 ABS degF2
··· PAUSE 2000 ' wait 2 secs
··· '_________________________________________________ ________________________________
··· 'Now compare the two values and turn pump ON if conditions are true
····· IF (degF1 >= (degF2 + 10)) THEN· StartPump:
··· StartPump:
··· DEBUG "Pump is ON", CR
····· IF (degF1 <= degF2) THEN StopPump:
···· StopPump:
··· DEBUG "Pump is OFF", CR
···· Timeout:
GOTO AGN: