Shop OBEX P1 Docs P2 Docs Learn Events
Please help me figure out differential temp controller — Parallax Forums

Please help me figure out differential temp controller

SG09SG09 Posts: 11
edited 2009-11-01 13:13 in BASIC Stamp
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:

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-10-31 04:20
    What does it write in the debug statements? Reduce your code to reading one sensor and writing the value to the debug screen. Once you get correct data add the second sensor and get the two values.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • SG09SG09 Posts: 11
    edited 2009-10-31 12:12
    I am able to get both values, it's just that I can't get·beyond there.· This is the output to the debug screen:
    Panel = 71.6

    Tank = 71.6Pump is ON

    Pump is OFF

    ······· Panel = 71.6
    Tank = 71.6Pump is ON

    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.


  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-31 12:29
    In the section where you make the comparison, you have no way of getting out if the temperature statement is false. It always goes to the startpump: label.

    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
    ·
  • SG09SG09 Posts: 11
    edited 2009-10-31 12:58
    elseif (degF1 <= (degF2 + 10)) THEN StopPump:

    This gives the error "expected ':' or end of line

    This is where I got stuck before. Thanks!
  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-31 17:27
    Make sure you're using PBASIC 2.5 ( click on "Directive" and choose the Stamp type you're using and PBasic 2.5). You may need to download the free upgrade of the software. You also have an open "DO" without the required closing "WHILE". Your code will run without it.

    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
    ·
  • FranklinFranklin Posts: 4,747
    edited 2009-10-31 17:32
    Are you sure you want the : in the GOTO statement?
    IF (degF1 >= (degF2 + 10)) THEN
    goto StartPump:
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-31 19:32
    You're right...hazard of cut and paste!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • SG09SG09 Posts: 11
    edited 2009-10-31 20:07
    IF (degF1 >= (degF2 + 10)) THEN StartPump:
    ELSEIF (degF1 <= (degF2 + 10) THEN StopPump
    ENDIF
    GOTO agn

    Now I'm getting "ELSEIF must be preceeded by IF". I don't understand?
  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-31 23:56
    You're going to have to look at the the IF statement. It stops at THEN.
    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
    ·
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-11-01 01:46
    I have no way of testing this code for you

    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·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • SG09SG09 Posts: 11
    edited 2009-11-01 02:27
    It works!!! Thanks for your patience, Tom. I was trying to make it more complex than it really was. The problem was that I was telling the program to proceed to the label (and then I had the label with a colon, followed by the instructions), instead of just immediately listing the instructions after the label.

    I know I'm not explaining well. Thanks again.

    Bill
  • SG09SG09 Posts: 11
    edited 2009-11-01 11:51
    Sam,

    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
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-11-01 13:13
    Bill

    It take time to get where you can write neat and· organized code

    When I frist have a idea.gif·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·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.