Please help me figure out differential temp controller
SG09
Posts: 11
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, [noparse][[/noparse]"P0", "W0cc", "S044"]· 'perform temp meas
·········································· ' note strong pullup
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"P0", "W0cc", "W0be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]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, [noparse][[/noparse]"P1", "W1cc", "S144"]· 'perform temp meas
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"P1", "W1cc", "W1be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R1"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R1"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]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, [noparse][[/noparse]"P0", "W0cc", "S044"]· 'perform temp meas
·········································· ' note strong pullup
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"P0", "W0cc", "W0be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]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, [noparse][[/noparse]"P1", "W1cc", "S144"]· 'perform temp meas
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"P1", "W1cc", "W1be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R1"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R1"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]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:
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Tank = 71.6Pump is ON
Pump is OFF
······· Panel = 71.6
Pump is OFF······· This just repeats....
Although the temperature will change , I don't know how to write the program to do what I want.· I can change the IF THEN parameters and place my finger on the sensor to change the temp; it doesn't seem to affect the text that is displayed to the debug screen.
This is the logic you want, I think.
IF (degF1 >= (degF2 + 10)) THEN
goto StartPump:
elseif (degF1 <= degF2) THEN
goto StopPump:
endif
goto agn
StartPump:
DEBUG "Pump is ON", CR
high pumppin
goto agn
StopPump:
DEBUG "Pump is OFF", CR
low pumppin
goto agn
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
This gives the error "expected ':' or end of line
This is where I got stuck before. Thanks!
Note that my code snippet is using a different variation of the the IF-THEN command.
The code snippet runs on my machine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
ELSEIF (degF1 <= (degF2 + 10) THEN StopPump
ENDIF
GOTO agn
Now I'm getting "ELSEIF must be preceeded by IF". I don't understand?
goto StartPump goes on the next line.
Look at the Helpfile for the IF statement and its two variations as was pointed out previously.
IF (degF1 >= (degF2 + 10)) THEN
goto StartPump
ELSEIF (degF1 <= (degF2 + 10) THEN
goto StopPump
ENDIF
GOTO agn
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
I cleaned up your code routines for you a little and it now·compiles
One ·Note· You have '·· {$PBASIC 2.0}·you should use ·'·· {$PBASIC 2.5}
Also you should when you have a small routine that repeats it self you have it as a sub routine
calculations:
········· ' now do the calculations
····· x = x * 5·· ' multiplication works okay in twos complement
········ 'Now show degrees Fahrenheit
··· degF1 = x + 178 * 9 / 5
··· PAUSE 2000 ' wait 2 secs
··· RETURN
I hope this helps
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
I know I'm not explaining well. Thanks again.
Bill
Thank you for doing this for me. Looks great all cleaned up and organized. I will load it and give it a test. Eventually, I would like to be able to log the data 24/7 for analysis and get my 12 yr old son to help with a VB interface. Sooo much more to learn and little time!
Bill
It take time to get where you can write neat and· organized code
When I frist have a ·my code look a mess and I have to take time to clean it up
Meaning: That small routine that are repeated are put in sub routines and·VAR ,CON, I/O· are put in there place
I am still learning how to write good working code
I hope this helps hang in there
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam