Sign in to follow this  
Followers 0
TheFox

FB structured text

6 posts in this topic

Okay, Basically my first time playing with Omron so this may be a simple question. I have written some structured text that will compare a temperature to a setpoint with deadband (all REALS). Basically when enabled and the temperature < SP+DB then turn on output 1 and turn off output 2. Keep output 1 on until the temperature > SP+DB then turn off output 1 and turn on output 2 and vice versa. Now my problem is if they disable the FB I want to set both outputs to 0. Here is my text: (*Compare two real values to see if A > B or A < B*) (*If A > B latch on until A < B, and if A < B latch on until A > B*) H_DB:= VALUE_B + DB; L_DB:= VALUE_B - DB; IF VALUE_A > H_DB OR (A_GT_B AND NOT (VALUE_A < L_DB)) THEN A_GT_B:=TRUE; ELSE A_GT_B:=FALSE; END_IF; IF VALUE_A < L_DB OR (A_LT_B AND NOT (VALUE_A > H_DB)) THEN A_LT_B:=TRUE; ELSE A_LT_B:=FALSE; END_IF; Now what I need to do is on the first run of this set the A_GT_B and A_LT_B to FALSE. Is there a first run bit? I tried P_First_Cycle but that didn't work. I also set the initial values to False for the outputs but it doesn't seem to reset with the enable/disable bit? It only resets with power on/off.

Share this post


Link to post
Share on other sites
So I figured this out by adding a reset input. It is not my favorite thing in the world so if anyone has a cleaner solution let me know. Basically before I had a selector switch as my FB EN bit. Now I have CF113 (always on) in that place and I use a N/C contact on my selector to a reset bit. Here is the structured text: (*Compare two real values to see if A > B or A < B with a H_DB*) (*If A > B latch on until A < B, and if A < B latch on until A > B*) H_DB:= VALUE_B + DB; L_DB:= VALUE_B - DB; IF RESET =TRUE THEN A_GT_B:=FALSE; A_LT_B:=FALSE; ELSE IF VALUE_A > H_DB OR (A_GT_B AND NOT (VALUE_A < L_DB)) THEN A_GT_B:=TRUE; ELSE A_GT_B:=FALSE; END_IF; IF VALUE_A < L_DB OR (A_LT_B AND NOT (VALUE_A > H_DB)) THEN A_LT_B:=TRUE; ELSE A_LT_B:=FALSE; END_IF; END_IF;

Share this post


Link to post
Share on other sites
If you declared your BOOLEAN variables A_GT_B and A_LT_B as Internals then changing the Initial value to FALSE should do the trick. You could also add these two lines at the beginning of the function block:- A_LT_B:=FALSE; A_GT_B:=FALSE; This will make the outputs false. Subsequent ST statements will be evaluated and turn ON [TRUE] the desired BOOLEAN flag. The function block must always be enabled by P_ALWAYS_ON for this method to work. Edited by BITS N BYTES

Share this post


Link to post
Share on other sites
When I see the code, I would have done it in ladder.... (or nested FB ST and ladder)

Share this post


Link to post
Share on other sites
Not sure if this is what your after, and I may be bit late in posting, but I have done something similar. (* Calculate Low / High Deadband Values based on PV & Deadband Value *) DB_Low := SV - Deadband; DB_High := SV + Deadband; (*Enable Cooling Output*) Cool := ( PV >= DB_High ) or ( Cool and ( PV > DB_Low) ); (*Enable Heating Output*) Heat := ( PV <= DB_Low ) or ( Heat and ( PV < DB_High) ) ; This code basically swaps between heating & cooling modes, based on the setpoint & feedback values. This can easily be done in ladder also, by doing in ST makes doing the math calcs easier.

Share this post


Link to post
Share on other sites
Hello TheFox, Just a bit of info... The "P_First_Cycle" flag will not work within a FB, as during the first cycle, the FBs are being initialised, therefore, any internal operation within a FB will not take place until the second scan! Also, as I'm sure that many of you already know ( but is probably worth re-iterating ), switching OFF the EN parameter, does not reset anything within a FB. I.e. the state of all data within the FB is retained. Hope this helps

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0