BITS N BYTES

NJ State Machine

11 posts in this topic

Am working hard to learn and get proficient with this great new platform. Any suggestions how best to implement a state machine in the NJ controller that would function in a similar fashion to the STEP/SNXT instruction set in the CJ series PLC's. Any ideas most welcome.
1 person likes this

Share this post


Link to post
Share on other sites
In general I really love the STEP/SNXT functionality in Omron controllers, I just don't understand why other manufacturers do not support something similar, i.e. ladder representation of SFC. That just significantly reduces code responsible for the state machine mechanics. Anyway, I believe that the most popular pattern for implementation of state machines it to program two dependent layers: one layer responsible for the state machine mechanics (i.e. you map the step number to corresponding coil that executes some actions, while also managing transitions from step to step) and the other responsible for the above mentioned actions - i.e. when step coil is active make some movement, turn on the pump etc. Once you get the picture it is quite efficient. On the other hand I've seen some state machines programmed in structured-text FB's (e.g. using case statement), but I'm not really a fan of such solution. Though, maybe somebody else knows something about more efficient ways of programming state machines in PLC-s, also taking into account the new capabilities of NJ-series. Edited by Eradicated

Share this post


Link to post
Share on other sites
I've used the Case method in ST for simple state machines and sequences, but once it starts to become large or complex it becomes hard to follow in my opinion. For larger sequences I have used ladder and used a simple step counter variable, comparing the value to determine which output to drive, transitions to check for etc.

Share this post


Link to post
Share on other sites
I have a method that I have settled into after 20+ years of programming. I use the same method regardless of what type of Omron PLC (CP1L, CJ2M, CS1, NJ, etc) I am using. I define a register (or Tag in the case of the NJ) as a 'sequencer'. On startup, I move a value of &100 into the sequencer. That indicates that I am in a power up state, but nothing has happened yet. From there, I use comparison (=) instructions to check the current state, and MOV instructions to command the next state. I always start out incrementing my sequencer values by 20, so I can easily add steps in between. This makes debug very simple. If your machine gets 'stuck', you can look at the sequencer and see where it is stuck. It also makes jumping back to previous steps for 'retry' operations very simple. If I have subprocesses (robotic interface, etc), I spawn a subsequencer (different register) and use comparisons to determine when the subsequencer is finished.

Share this post


Link to post
Share on other sites
PMCR thnx for feedback. Yes I am very familiar with this sequencer method and seen it used in many applications. Its BIG drawback as far as I am concerned is that all you see when programming/debugging is a change in the state number. SO, you have to have an external document referencing each state number to what each state actually does. With the STEP/SNXT method since each state is Boolean a unique name can be assigned to every state. See my post : http://forums.mrplc.com/index.php?showtopic=26261&st=0&p=125846&fromsearch=1entry125846 Now maybe there is a method in the NJ using a Structure, Union, Enumerations OR a combination of one or more of them that allows a unique name to be assigned to each numeric state!! Will take a look and see. If you can come up with one so much the better.

Share this post


Link to post
Share on other sites
Agreed. Using individual bits has documentation advantages. You can use an enumerated data type to help shed light. I typically just use rung comments. Enumerations seem like extra work to me. I may try enumerated sequencers on my next NJ project, which will be mid August.

Share this post


Link to post
Share on other sites

This came up in another discussion as well, so I thought that I would post this here. Let's say that we are trying to sequence a very simple tray sealing application for the food industry and this is the simple process: Process: 1) Close tool with tray inside. 2) Vacuum out air inside tray to a setpoint. 3) Inject Gas. 4) Vent 5) Open tool You might build an enumeration that looks something like this: You might then have ladder that looks like this: The trickiest part of the whole thing is to remember that the variable Current_Step needs to be created with type "Sequence" (same name as the enumeration) to work.

post-19500-0-87374500-1405366593_thumb.jpost-19500-0-22633700-1405366616_thumb.j

Share this post


Link to post
Share on other sites
CJ is very oriented to Ladder In NJ Ladder and ST are at same level, I assume you are taking advantage of InLineST function?... ST language has a very nice instruction ... CASE that is ideal for implementing STATE MACHINES... Please, check all the possibilities of CASE instruction... , and if you are Ladder fan... I suggest you to combine The CASE with InlineST instead of making 100% ST prog Additional tip... You can use ENUMERATION datatype in your CASE starement to define fhe state... So will make your prog easy to understand
1 person likes this

Share this post


Link to post
Share on other sites
On 14-7-2014 at 9:37 PM, Michael Walsh said:

This came up in another discussion as well, so I thought that I would post this here. Let's say that we are trying to sequence a very simple tray sealing application for the food industry and this is the simple process: Process: 1) Close tool with tray inside. 2) Vacuum out air inside tray to a setpoint. 3) Inject Gas. 4) Vent 5) Open tool You might build an enumeration that looks something like this: You might then have ladder that looks like this: The trickiest part of the whole thing is to remember that the variable Current_Step needs to be created with type "Sequence" (same name as the enumeration) to work.

Hello, 

I cant see the sample of this comment. Where can i find them ? 

 

Share this post


Link to post
Share on other sites
On 12/22/2017 at 7:54 AM, Gotyaa444 said:

Hello, 

I cant see the sample of this comment. Where can i find them ? 

 

@Gotyaa444:

The website was updated a while back and some of the attachments were removed.  They need to be repaired one by one as they are found.  I have repaired the post.  

1 person likes this

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