Automatic_Sequence

You can use a single timer for delays and timeout functions by having your state set the timer value and then re-trigger the timer on a state change. This can be achieved by comparing the input state with the output state: if they are equal then the timer runs, if they are not equal then the timer is re-triggered and will start with the value set in the transition to a new state.

Nick
Could you explain more about this ??
 
No need to worry about same steps in same scan unless Your PLC uses a sync I/O update (easy to get round by mapping, however, it will not cause a problem well never has for me, and one scan is not going to make any difference, even if you wait for next scan it is usually so fast (example reversing a motor) you would put a delay in. I have used the above technique for over 35 years never had any problems, generally you have transitions between steps anyway i.e. settle times especially in batching, it's the same as using steps with bits but not unsurmountable by calling the step change at the end of scan or at the start of scan.
The point is as you rely on perhaps in a sequence for a proximity to make after an output has been energised this would not be instant and one scan is not to be considered anything more than a step transition in one scan and is not going to happen. Also many step changes may only be moving a value into a word like incrementing a recipe block.
As for the state skipping in one scan explain to me where this would cause a problem.

ielkhatib: Things like home sequence is just another range of values.
Let me explain, You have a process that for example is a batching process.
You split the values into areas like
10-100 Initialisation
1000-1999 is water addition
2000 -2999 is starch addition
3000- 3999 is mixing sequence (i.e. run a mixer & perhaps a blender for a time)
4000-4999 is operator checks
5000- 5999 is discharge to line
so for example you start the process and it runs through initialisation what ever that is, it then sets the sequence word to 10000 so you create a program that runs when the sequence is 10000-10100(move first stage into running recipe area (the values that stage needs).
This then checks what type of addition is i.e. 1. = water, 2 = starch 3 =mix
so if the recipe stage requires starch then it moves 2000 into the sequence word, next scan it calls the starch sequence code based on the sequence word is between 1000 & 1999.
So in simple terms
assume sequence = 0 then it is idle
Operator presses the start button, it moves 10 into the sequence word
a block of code is called conditionally when the sequence word is between 10 & 100
When the initialisation has been done that bit of code writes 10000 into the sequence word, this then enables the call to the recipe stage load logic, in there it copies the recipe stage into the running recipe stages then compares what type of process it needs to do i.e. it is water addition so moves 1000 into the sequence, the next scan of the PLC the water addition block of code runs as it is enabled because the sequence word is between 1000 & 1999, this code then increments the sequence in increments of say 10, so 1010 is store the weight of the vessel, 1020 is open the main feed valve, 1030 is check added weight, if weight is within 10kg of target, move 1040 into sequence close main feed valve, open trickle valve, 1050 is check for target weight, when target reached move 1060 into sequence word, settle time, move 1070 into sequence, check weight = recipe, complete move 1000 into sequence to call the increment recipe stage.
It may seem complex but if you write out the steps or stages and give them a range of numbers then it becomes easy.
Here is a sample, however, it is too large to post so only shows the main cooker sequence that calls the various additions, note: there are two sequences as I use one for the main task that takes care of handling alarms & holding the process on an alarm and the other is the control sequence word.
 
As for the state skipping in one scan explain to me where this would cause a problem.

If, for example, sequence A is waiting for sequence B to be at state 10 but sequence B skips from 8 to 11 in the same scan then sequence A waits forever. There are ways around this of course; it's only a matter of style and preference.

Nick
 
Attached is an example of a design translated into an actual sequence. It was programmed in TIA Portal but the principles remain the same regardless of platform.

Nick
 
Nick: perhaps you are talking about multiple sequence words, or have I got it wrong.
Also if Why would it skip from 8 to 11, if programmed to go to to step 9 then 10 ? I really do not understand what you are trying to get at & would one scan make any difference as on the next scan if it was possible it would go from 8 to 11 in any case.
 
@Parky I was referring to multiple separate sequences within the same machine. As I said, it’s a matter of style and preference.

Have a great weekend all,

Nick
 
Yes I understand now, I have done similar in a couple of ways, In multiple sequences (using more than one sequence word) I would move both the A seq. and the B seq. Or move 10 into A seq. and what ever B seq. number and wait until B has moved a confirmation value into it before A continues to next transition, this only takes one scan if there are no logical conditions between transitions so it is impossible for it to Skip in one scan, however, this is rare as usually a transition from one step to another is either purely moving data or a logical operation where something external has to happen and that almost certainly will not happen in one scan.
 
Looks fancy but could you elaborate more, may be with some examples for better illustration ??

Attached is a screenshot of a simplified version. I've seen others use multiple arrays instead of putting it all into one big 2D. I don't know the right or wrong answer to that. Documentation is key with this method regardless.

The array row is the section of the sequencer, in this example I just used the row numbers, but I have used an integer tag as well such as "Input" and elsewhere set that equal to decimal 1 or 20 or whatever you want. In this example row 1 is the input/boolean mask and row 2 is the current input/bool state. When these are equal that portion is satisfied. The bools are shown on rung 1&2 with the compare on 3.

Row 3 of array is TMR set points, the single timer is on rung 10. Counter is row for and Rung 11. Outputs are row 6 and rungs 12 and 13.

Row 5 has an integer value for motor amp input. This is one case where multiple arrays could be useful. Motor amp input may be a float and in PSuite arrays can only be one data type. Instead of an amp float, ill just do a mA int and thats good enough. The extra condition makes sure this is only evaluated when on a step requiring motor check. I showed this two ways, one where the motor check step is defined separately and another where it breaks the int32 into two int16 and uses the MSW to control what should be evaluated and the LSW as the value. Just a way to have a bit less "stuff" as a 32 bit int value probably isn't needed.

When everything is happy, the step advances. If a pause is needed, the current step is copied to another tag, then the system is stopped by advancing to the configured holding step. There could be multiples of these as you may want different outputs on depending on the reason for the pause. When resumed, the last step is copied back and everything continues on.

It's not perfect, but it's been working better for me than the built in sequencer instructions which had too many limitations and were hard to "watch". This approach does require a lot of documentation outside of the ladder. Use excel or something to generate all of the values and keep a record.

2D Array Seq.jpg
 
Sequencing

There are some discussions of how to do sequencing in ladder in the PLC class outline on corsairhmi.com.

I'll second the motion to do it in SFC whenever possible.
 
IMO it's hard to go wrong with the ol' IF condition THEN MOVE step_number IN step_register. I've tried a few variations of the ladder state machine pattern and that is always the one I come back to. I find it much more flexible than shift register or counter-bases approaches and it is more readable. You can't do a direct Grafcet "AND-divergence" because you can't have two step_numbers held in the same step_register but then you can just make a branch of the divergence a subsequence.

For race conditions, I split requested_step and actual_step and just have them flip at the end. I'm then guaranteed one step a scan.

In platforms that support them I much prefer using enums instead of numbers. I think it makes code much more readable and easier to extend as well because you don't have to care about leaving space in for steps you might add in future.

Not that big a fan of the SFC implementations I've worked with, though I heavily use the symbols on paper.
 
Here is an example that I wrote last night and currently debugging. It mostly works, but it is an example of sequence steps. This is for my project of a model railroad layout controlled with a PLC. I am doing this as a learning tool.



This program senses the direction the train is moving along the mainline track. When a train is on a section of track it is sensed as a "block detect" I had thought of using a bit shift left or right to sense direction but it was not possible since there are block occupancy detectors on track that is not part of the main line and depending on the length of the train, more then one block would be active at a time. It breaks down into steps conditions where it sees the train and then looks for a second condition to confirm direction. It allows 10 seconds to sense it otherwise the routine sets an alarm code.


A short video showing the HMI display showing the blocks of track (lights up with green bars) is here:


https://youtu.be/ELYgD5Nberg


Mike
 
Going back to multiple sequence control, perhaps I did not make it clear, if sequence A initiates sequence B at some point I always have handshake, i.e. if sequence B needs to start on sequence A being at step 10 then sequence B compares Sequence A step, moves it's own sequence to say 2, sequence A checks that sequence B is on step 2 before incrementing it's own step, this makes good programming practice so if A relies on B but B faults before starting then A stays where it is, there is no need to do things at end of scan or the possibility of skipping steps before the other sequence sees the required step.
This technique is used in communications between systems i.e. ENQ> returns ACK, etc.
I have only had one instance where this happened, this was in one sequence.
The problem was I was given the wrong address of an alarm, so due to a fault where a proximity on a cylinder had gone short, the alarm was generated but was not in the map for that sequence so when the sequence was supposed to be wait until the cylinder reached full extent it skipped strait through to the next step as there was no alarm to hold the process.
 
I will have to find some examples if I can, but here are my thoughts:

I tend to use a seal circuit bit for sequencing (NOT Set/Reset). This is for two reasons:
(1) if the machine loses power, the sequence drops out, and the machine will 'home'. This is usually desirable in most of my applications - but may not be desirable in yours.
(2) With a bit, I can theoretically insert an infinite amount of subroutines or new steps between two steps in the logic.

I know many people on this board prefer to use a pair of integers.
(an AT state and a TO state - compare them both at the top or bottom of a scan and move TO into AT at the end. Use AT ints as inputs and make your logic change the TO int. This usually guarantees one scan will process in the AT state before changing).

The integers have a few advantages:
(1) You can make a graphic in your HMI that tells you exactly what step you are at in your sequence and what you are waiting on to change to another step.
(2) It takes up less room than the bits in memory / less tags to deal with.
And a couple of disadvantages:
(1) Even if you skip 10 numbers between each step, you will someday have to add 11 steps in between. You are setting a finite number of changes you can make (rare – but it does happen) in which case you make a new INT anyway.
(2) If you have maintenance people (not PLC programmers) in your logic, they tend to understand NO, NC and Coils – numbers can sometimes make them see cross-eyed in my experience.

I will semi-disagree on the timers comment above. I find it good practice to bring all inputs to a timer – even if it is 100ms or less. However, DON’T use a timer in your sequence unless it is for something specific (like bake for 10 minutes, or a dwell time, etc). Rather than use the direct I/O input (on a cylinder prox switch, for example) use the timer. It ensures that cylinder landed in the proper spot and did not give a ‘false’ positive. (this is called de-bouncing if you are not familiar) It also allows you to test a machine SLOWLY during debug time to make sure nothing will crash (or at least give you a chance at avoiding it).

I’ll typically set all of my timers to about 2 seconds on an assembly machine to test the assembly and then start dialing back the timers for cycle time.

The best logic looks like it was written by an 8 year old!

Good luck!
 
Last edited:

Similar Topics

I have a job utilising an S7 400 plc which requires a no of automatic sequences to occur.I have some nice timing diagrams from the customer but I...
Replies
2
Views
1,587
Hello, I need to create an automatic transfer panel that connects to the generator when the mains power is cut. I can draw up to 60kW and draw up...
Replies
0
Views
80
Hello everyone, I'm having trouble solving this one and was hoping someone could help. I have a AB CompactLogix L16ER PLC connected to a AB...
Replies
2
Views
580
Hello everyone, I was hoping someone with a lot of experience with Automatic Device Configuration would chime in with any of your thoughts on this...
Replies
6
Views
1,826
Hello. At my job I get from clients lists of their inputs and outputs (hundreds of them) and what they want the program to do. So I have to type...
Replies
2
Views
1,333
Back
Top Bottom