Sign in to follow this  
Followers 0
Sunbic

Out of curiosity, is there a way to make ladder execute in steps, linearly?

9 posts in this topic

If you manage data you end up manipulating it, moving it here and there, splitting and stitching, and due to the nature of ladder I wonder how high is the probability of race conditions happening. I have yet to see an in depth explanation of this, of how the processor handles threads and what gets the biggest priority. I have never felt confident modifying the same data twice when both instructions are executed by the same trigger.

You can always use SFC - not an option where I work though - or make a timer after each execution, but that's just a nasty way to do it, and gets extremely bloated really quickly, more if you are using differentials. Is there a real way to make the PLC execute A THEN B in ladder without using these? I have wondered this for years.

By the way, what is the use of P_Step?

Edited by Sunbic

Share this post


Link to post
Share on other sites

If the same bit triggers action on the same variable in two different locations, the first instruction reached will happen and then the second will occur. 

In other words, if you had this:

j8i8HqEKKLmhwAAAABJRU5ErkJggg==

 

The value in D0 would always be 2 when viewed online or used at any point after rung 2.  If you were to insert a comparison between these two MOV statements, the value of 1 would be in D0 at that point.  This shows it more clearly:

wGPWfma8X1BrAAAAABJRU5ErkJggg==

Notice how both coils are green, even though the line leading to W0.01 is not.  The line shows the state of the comparison at the end of the scan, therefore it looks like it is off.  The coil however is indeed on since it was true when the logic hit rung 1. 

The above order of scanning is ALWAYS true.  The code scans left to right and top to bottom.  If you program your code properly, you can most definitely avoid race conditions.

1 person likes this

Share this post


Link to post
Share on other sites

That's exactly what I needed to hear, Michael, thanks. I did not know about using different rungs. Is this something you have learned over the years or is there an official paper on this? I have read some docens of Omron manuals and I have never come across this.

Edited by Sunbic

Share this post


Link to post
Share on other sites

General statement:  In literally the first sentence out of the instructor's / mentor's mouth when talking about programming a PLC, he/she will likely say the word "rung" (it is ladder programming, so therefore, it needs rungs, just like a real ladder).  I am not trying to be sarcastic here.  Just communicating that it is one of the very first things that you learn about PLC programming.  No offense meant...

Share this post


Link to post
Share on other sites

They also say the whole program is executed in parallel.

It's clearly not true but it's enough explanation for most users. But what if the PLC is actually managing CPU threads? How does one know if there's nothing to either deny or confirm the way the PLC handles the program execution?

If it does not use multithreading and it's just a whole single I/O operation thread, it is completely sequential and each step is executed after and only after a former one finishes. Writing an instruction under another should be enough since both can't be executed at the same time. Turns out I should not be doing that.. so either the CPU handles instructions faster than the memory updates or that statement is false. It is more complex than classroom material.

Share this post


Link to post
Share on other sites

 

 

Maybe something that would help you understand the PLC scan:

The basics

Capture.JPG

Share this post


Link to post
Share on other sites

I use a custom state machine function that is essentially a comparison function with some additional functionality allowing the stepping control of code rungs. This method utilizes a register for each sub system in the machine design. Below is a snapshot of the SM_100 (Int Tag) state machine which  can hold an integer value between 100 and 199. This encapsulates the code so that only the rung of code which matches the current state value can execute. The first rung will execute only when SM_100 = 145. Once the transition conditions are true the state of the control register will increment the state register (SM_100) to the next state. Interaction between unique state machines is seen in the last rung where state machine SM_400 must be equal to 430 before the rung will execute the "R4_Pick_150" function block. Through this approach the amount of time along with time stamps for all of the state machines in the project are recorded with each state change.Very useful for isolating code execution delays.  This particular project has 17 different sub systems each with an unique state machine range.

PLC.jpg.c37bf1f5655b1d95a1997f4fff51b392

 

 

Share this post


Link to post
Share on other sites

But can the average technician troubleshoot it?? :shrug:

Share this post


Link to post
Share on other sites

Actually that was one of the drivers of this approach. Especially for complex automation controls. This project  has three 6-axis robots, 3 Cognex camera systems, a lathe (rotation & translation), 2 index tables,  4 indexer peripheral stations, and five additional independent motion axes. This system forms, handles, inserts, and swages a rivet that has a shank diameter of 0.008", so the product itself is very difficult to see. The status of each state machine is part of the HMI display so the current state of each sub-system is displayed for the tech. The encapsulation of code in this manner effectively eliminates 99% of the code. The deterministic nature of state machines allow only one state to exist for a particular state machine at any given time. For example if tech walks up an Robot 1 has stopped at the Rivet forming table, the tech would see that the current state of Robot 1 (SM_100) is equal to 147.

By going to section s_145, which houses states 145 thru 149, of  POU 'pg_sm_100_Robot_1 (SM_100)

section.jpg.0f03fac805cc7a975a273cc1aedb

The tech will find the following

StateTS.jpg.8bef5205bc28a4298faf131a9fa4

The the rung controlled by state 147 has one contact needed to complete the transition condition to execute the robot pick program (PRO12). In this example this contact is SMc[430], so the robot is waiting for SM_400 to reach state 430. Using the same method the tech traces why SM_400 is stuck at 425.

I use ladder for the majority of the code sequencing and ST (Inline) for math and text manipulation.

The techs I work with love it. The bigger challenge is the training to use SYSMAC Studio.

Another nice feature of the NJ is the ability to protect program code as read only. Invaluable in FDA regulated industries.

There are also a variety of benefits for implementing manufacturing intelligence and machine performance monitoring.

 

Edited by PLCSteam

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