Sign in to follow this  
Followers 0
angeraer

How do flags work in a program

6 posts in this topic

Hello, I'm trying to understand how and when flags (P_EQ, P_LT, ...) are set in a program. If you look at the attached code. The CMP instruction is being used. Imagine DM54 has value 1. The first compare instruction returns false so flag P_EQ is false. (P_EQ=255.06) The second compare instruction returns true so flag P_EQ is true. The third compare instruction returns false so flag P_EQ is false. How will this be handled in the PLC? Since it is always the same flag, will output bit LR10.01 be true at the end of the cycle or will it never be true because the last CMP returns false? How would you code this? (I know flags are being reset by the END command.) Thanks, Andy.

Share this post


Link to post
Share on other sites
Condition Flags are reset at the end of program scan and are set by the Comparison Instructions. Each time the Comparison Instruction is executed, the Condition Flags are reset from their previous conditions and assume the value of the new Comparison. More discussion can be found in the Omron Tech and Application notes @ MrPLC.com Using Compare Instructions with Omron PLCs @ MrPLC.com

Share this post


Link to post
Share on other sites
Hello Andy, Swap to a CS / CJ CPU and use the inline comparison instructions Seriously though, in your example, LR10.01 would be on until the scan encountered the same rung, and P_EQ was not true. In other words, LR10.01 would remain ON until switched OFF by the corresponding Flag. The flags, as you point out, are set after each instruction, but the logic does not then reverse itself to switch off previously set coils. The way that you have programmed the instructions is fine, although I probably would have put each Compare Instruction (and its corresponding Flag) and output coil on individual rungs. Edited by anonymous

Share this post


Link to post
Share on other sites
Thanks for the reply, makes it clear now. Any benefit of using individual rungs? Andy.

Share this post


Link to post
Share on other sites
Probably for clarity... but if you know how to read omron ladder logic then it shouldn;t be a problem. I have attached a nested cmp rung for a CAM postiioner based on a CPM which uses an absolute encoder for interest to really throw your head in a spin. But if you read through it logically it makes sense. The first compare tests if the start pos is less then the stop pos (you have to be able to have the start greater then the stop in some instances OR the start less then the stop (for example .. turn on at say 350 deg and off at 25 degree. OR turn on at 100 deg and off at 180 degree). NewPLC1_NewProgram1_Section1.pdf

Share this post


Link to post
Share on other sites
Hello Andy, Yes, as Sleepy pointed out, just for clarity really!

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