PLC sensor status logic

Efried

Active Member
I'm using this code and can't find why this fires on start-up of the board:
 
AND TS1 TS2 VAR6
CZ VAR6 MAILERR
 
The subprogram mails me that everything is ok. Is this may be an timing issue of the board? Should there be some delay before polling TS?
thanks
  
 
When board just started, all the temp sensor status are initialized to unbound. It may take up to 2 seconds for all the temp sensors reading back. Then good temp sensor will have value 1.  In PLC logic, unbound sensor will return 0, same as bad sensor. 
 
Some user put a 2 seconds delay after START, then put a label warmup there, before END, they added
goto warmup
 
CAI_Support said:
Some user put a 2 seconds delay after START, then put a label warmup there, before END, they added
goto warmup
Thanks . since the START END loop is the same all the time, how to distinguish between a cold start and that normal looping?
thanks
 
Efried said:
Thanks . since the START END loop is the same all the time, how to distinguish between a cold start and that normal looping?
thanks
 
As was said.... use a goto to loop
 

Code:
start
    delay 5000
loop:
   do stuff
   goto loop
end
 
Efried said:
since the START END loop is the same all the time, how to distinguish between a cold start and that normal looping?
In my case I set a flag the first time through the loop. WebContol sets VARS and RAM to 0 at power up. If is is 0 you know this is the first time though the loop, then set it to some other value. 
 
If power up delay is only an issue with the status of the temperature sensors you can also denounce the status flag. This will eliminate spurious bad temp emails if there is a momentary problem with one of the sensors you are monitoring.
 
/tom
 
CAI_Support said:
Could you please elaborate in detail how to " denounce the status flag"?
Oops sorry about that, meant debounce.
 
When a temp sensor failure is reported, set a counter that is decremented each pass through user code. Notification email is sent only if sensor remains bad continuously until count reaches 0.
 
Here is the code fragment from my wood heat project:
 
TSENSOR:
    SET    VAR8 1
    AND    TS1 VAR8 VAR8
    AND    TS2 VAR8 VAR8
    AND    TS7 VAR8 VAR8
    BZ    BADSENSOR
    SET    VAR7 200
    RET

BADSENSOR:
    TSTEQ    VAR7 201
    RET

    DEC    VAR7
    TSTNE    VAR7 0
    RET
    
    EMAIL    EM3
    SET    VAR7 201
    RET   
 
 
Here is the entire project on my site:
http://www.tschmidt.com/writings/2ndgen_woodheat_controller.pdf
 
/tom
 
really great project but I do not unterstand the code:
AND    TS7 VAR8 VAR8  puts zero in VAR8 if there is one error
BZ BADSENSOR acts on what info, the internal logic bit from the AND command?
otherwise you could write:
AND TS7 VAR8 VAR8
CZ VAR8 BADSENSOR
 
or
CZ TS7 BADSENSOR
That's exactly what does not work with me :-(
 
A call would return Setting VAR7 to 200. I only want that to happen if all the temp sensors are good. That is the counter that is decremented to 0 debouncing the temp fail flag.
 
VAR 7 1-200 continue through loop until decremented to 0
VAR 7 0  send email
VAR 7 201 email is sent.
 
Once mail is sent temp sensors must report as good to restart the cycle.
 
Hope that helps.
 
Also, I'm also a little vague about exactly when the zero flag gets set, so I tend to test it directly. If I was more experienced with WebControl I could probably write tighter code.
 
/tom
 
Tschmidt said:
Also, I'm also a little vague about exactly when the zero flag gets set, so I tend to test it directly. If I was more experienced with WebControl I could probably write tighter code.

 
/tom
The mailing logic I understood but not the AND logic with the branch. What do you mean by test it directly. Is my CZ TSn BADSENSOR not good? Apparently it fires always.
 
Efried said:
The mailing logic I understood but not the AND logic with the branch. What do you mean by test it directly. Is my CZ TSn BADSENSOR not good? Apparently it fires always.
Not sure I understand your question.
 
I'm testing multiple temp sensors, if any one is bad, VAR8 gets set to 0, and code branches to  BADSENSOR.  In BADSENSOR VAR7 is tested. If it is 201 means email has been sent so just returns to main. VAR7 is decremented and returns to the main loop if it is not yet decremented to 0.Once VAR7 hits 0 it means temp sensor has been bad for a "long" time and email is generated then VAR7  is set to 201 indicating mail has been sent and returns to main loop.
 
If all sensors are good, loop counter VAR7 is set to 200 to be ready it for the next time a sensor is reported as bad and then returns to main loop. Any time sensor status becomes good the sensor fail loop counter is set to 200. This way a monetary report of a bad temp does not generate failure email.
 
If I used a CZ rather then BZ BADSENSOR would always return to the next instruction and SET VAR8 to 200 - that is not the correct behavior for my implementation.
 
/tom
 
HI Efried,
 
BNZ, BZ, CNZ, and CZ require to have two parameters, the first is the value to check, the second is where to branch.
However, if there is only one parameter and that only parameter is the branch location address, then those four compare commands will look the zero bit from last operation to determine wither to branch.
Any command operation result in zero will set the zero bit for subsequent compare command to use, if compare command does not have a value to compare.
 
Hope this clears some confusion.
 
CAI_Support said:
BNZ, BZ, CNZ, and CZ require to have two parameters, the first is the value to check, the second is where to branch.
Thanks - I forgot those instruction can do an immediate test of a variable in addition to checking the zero flag status from previous operation.
 
I though the question was about the using jump vs call.
 
/tom
 
Thanks, Tom.
in this question there is something about " CZ TSn BADSENSOR" may need little clarification. When board just started, the CZ checking may got value not truly reflect sensor status, since it will take up to 2 seconds to get sensor status updated.  Your project showed how to avoid those problem by goto another label in the code.
Now, I think he wants to explain how your code handle only sending one email at a time.
 
Back
Top