PLC for CAI Webcontrol

Hi can someone help me with a simple PLC code im running a thermostat on a base if T1 is bigger then T8 turn TTL 1 on 
 
 
START    
    CALLSUB SOLAR   
        END    
 
SOLAR:
    TSTGT T1 T8  
    SET OP1 1  
    TSTLT T1 T8  
    SET OP1 0  
    RET   
 
but  i get relays constantly turning on-off when the temp are the same +,-  0.1 what i need is a line added with a few degrees °offset.
 
Thanks for help
 
snowfly said:
Hi can someone help me with a simple PLC code im running a thermostat on a base if T1 is bigger then T8 turn TTL 1 on 
 
 
START    
    CALLSUB SOLAR   
        END    
 
SOLAR:
    TSTGT T1 T8  
    SET OP1 1  
    TSTLT T1 T8  
    SET OP1 0  
    RET   
 
but  i get relays constantly turning on-off when the temp are the same +,-  0.1 what i need is a line added with a few degrees °offset.
 
Thanks for help
 
"Hysteresis" is what you want.
Something like this (adapt to suit) would work better
 
 
Code:
start
  sub 5 t1 ram1    # take half a degree off t1
  tstgt ram1 t8
  set op1 1
  add ram1 10 ram1    # add half a degree off original t1
  tstlt ram1 t8
  set op1 0
end
 
Ross is correct, if you plan to use relay to control valve or motor, it is important to set a range, so that only reached at the upper limit and lower limit of that range your code will switch it on or off.  In your case, T1 and T8 could be about same temperature when your system just started, with T1 and T8 both bouncing slightly all the time, directly compare T1 and T8 could bounce too fast for your relays/valves/motors.
 
Hi "rossw" finaly got it tested and for some reason the code doesn't want to work the only difference i made was replaced ram1 for ram3 due to ram1 being used already. After that i have tried just
TSTGT T1 T8
SET OP1 1
 
just to se if temp sensors, op1 is working correctly and it was so it must be something within the code any ideas?
 
Thanks for your help
 
If T1 and T8 are different a lot, this could work. With T1 and T8 are very close, you will see OP1 bouncing ON and OFF. This is something could "bouncing". In the logic, you will need to check T1 and T8 must be different greater than a range, than you turn on OP1.
 
snowfly said:
Hi "rossw" finaly got it tested and for some reason the code doesn't want to work
 
Some more specific detail about the manner in which it "doesn't work" might help!
Is the output constantly toggling? Always on? Always off? Turns on but won't turn off? Etc.... more detail, more chance to work it out.
 
The output is constantly off, does nothing. The way im testing it is i have 2 other temp sensors one outside temp ( at the momont around 5 degrees celsius) and secon one is water heater so the temp diference is easily over 80 degrees C . Im not sure if its conected but
i cant even turn the output on manualu through the output control as if the plc code was preventing so.
 
Pick a point in the program where you think you might have problems. Put a SET VARx X  and increment as you use them or use the ORB if your firmware is newer. This will let you now which areas of the code ran and which were skipped.  Also pay attention to your returns and ends. As an example
 
TSTEQ T8 870
BZ SUMTHIN
ORB VAR3 1VAR3     If var3 bit 0 is set  to 1 then we hit this point.  
SET OP1 1
OUTSOFF:      If T8 is 87.0 then the next line will run and set OP1 off. The above should end with a jump, return or end unless you want to run the next lines.
SET OP1 0      You can have more than 1 end.
ORB VAR3 2 VAR3     If bit 1 is set to 1 then you've obviously been here.
SUMTHIN:
xxxxx
xxxxx
ORB VAR3 4 VAR3  if bit 2 is not set then the program branched before this point.
 
 
If you can't manually toggle an output to one state or another then it is because the program is controlling it. Look for the step that is turning it off.
 
I think i got it worked out "rossw" 's code was all corect part from the first line where there was SUB 5 T1 RAM1 this puts the result to - , in fact it should be SUB T1 5 RAM1 
I haven't tested when the hysteresis kicks in yet but im sure it will work.
 
Thank you all
 
snowfly said:
in fact it should be SUB T1 5 RAM1
 
Doh!  Sorry about that. I've been coding in a bunch of different stuff and at the time was working on something else that used the opposite order.
I looked and looked at the lines I posted you and couldn't even SEE the mistake.
 
Glad you got it sorted!
 
Hi guys can you please help me out with this code basicly i want the TTL 8 to be turned on when the time is between 18:00 and 18:30 and temperature T2 is less then 80C i think the problem is in AND line but don know why . 
Thanks 
 
 
GAS_HEATER:
                       TSTGE CT 18:0:0 RAM4
                       NOP
                       TSTLE CT 18:30:0 RAM5
                       NOP
                       TSTLE T2 800 RAM6
                       NOP
                       AND RAM4 RAM5 RAM6 OP8
                       RET
 
You cannot AND 3 values together. You would have to do

AND RAM4 RAM5 RAM5
AND RAM5 RAM6 OP8

But you could also not use RAM and do:

GAS_HEATER:
TSTGE CT 18:0:0
TSTGT CT 18:30:0
GOTO HEATER_OFF
TSTGT T2 800
GOTO HEATER_OFF
TSTLE T2 790             //you probably want to maintain at least 1 degree buffer so that the heater is not switching on/off too rapidly
SET OP8 1
RET
HEATER_OFF:
SETOP8 0
RET
 
Back
Top