Jump to content

Avoid overwhelming a ladder with Set/Reset coils ?


Recommended Posts

Hi everyone,

I am currently working on a small project, in which i am automating the movement of a small "train" of boxes that i am filling with stuff. The train has two commands (move forward / backward) and three sensors (homing_position, box_is_full, box_detection).

I control my train with three modes : Homing, Auto and Manual.

My problem is the following :

In order to move my train, i need to call the commands forward/backward multiple times in my routine in several rungs. I already know i can't use multiple direct coils because only the last direct coil state remains.

On the other hand, if  i write my code with a lot of set/reset coils, it becomes a bit hard to read. Do you have any suggestion or trick on how i could turn my code so that it remains readable without using set/reset coils ?

I wrote TWO versions of my code :

 -> "train project.vlp" which i know is WRONG, but it is written with direct coils to illustrate how i would like the rendering of my ladder to be.

-> "train project with set reset.vlp", which, i hope, is performing well although readability is worse.

Cheers,

Sideway.

PS I presented here a small project, but i have also been working on bigger projects, with, say 8 or 16 outputs all working together. And you can lose yourself easily with all the set/reset coils invading the project.

train project with set reset coils.vlp train project.vlp

Link to comment
Share on other sites

  • MVP 2023

After reviewing your projects, I came to the conclusion that you were trying to use a State machine.

However, I can say that you have a little bit of your own perception of the idea that is embedded in the State machine. In each state, you try to take action immediately, that is, send a control signal.

However, the main thing in the State machine is:

1) create a subroutine INPUTS in which to assign the value of physical inputs to logical variables MB or XB. This will help you  simulate the operation of the State machine. In the online simulation mode, it is not possible to change the state of the physical input, an intermediate variable is required.

2) capture states, switch them by  input variables (timers, outputs, ect) and generate appropriate bit variables indicating that the state is active - that is, each such bit is a unique coil - (    ) MB(N).

3) in a separate place (subrotine OUTPUT) determine which of the above bits activate the movement forward or backward of the motor, which bits of the state include loading or unloading, ect.

That is, in this version of the program you must have N steps  of the State machine, that activate N unique coils  -(  ) that control movement or other actions. That is, for example, variables that are activated in steps 4,6,9 - control the movement forward output. Accordingly, others for example 3,5,11 - control the movement backwards output.

Such a program is well readable and you can immediately see that at some step something is wrong.

And most importantly, in this case you can make absolutely convenient and comfortable manual control of any output signal.

Link to comment
Share on other sites

  • MVP 2023

While typing this I see a reply from kratmel, who always offers excellent advice. I'll leave mine up to provide some additional general information.

==========================

No time at the moment to go through your project(s) in detail, so I'll just share my approach. When I have multiple situations that require activating a coil, I will identify all those situations and place them in a single ladder rung so that I can use a single coil without sets & resets. Sometimes each of those situations are too unwieldy for a single ladder rung, so then I create intermediate coils that will substitute for each unwieldy situation. Then each of those intermediate coils can be placed in parallel to activate the final coil needed.

Set & resets I use for latches and sometimes to provide the opportunity for an HMI button to turn something on and off manually that will also be controlled by the PLC.

You are correct that you can lose yourself with too many sets & resets, so for that reason I avoid them except for the items mentioned above.

Link to comment
Share on other sites

Hi,

Thank you for your replies. I tried to adjust my program (quickly though), to understand the essence of state machine.

Since i did slight adjustments, i did not manage to have one coil per state machine step (since some steps do not interact with my outputs at all).

Also, consider XB100 - 199 to be my external inputs (sensors) and XB200 - 299 to be my external outputs (i am using CAN open so i retrieve these bits in a structure, not shown in that small program)

I would like to practice on this small program to make it as clean as possible, to use it as a reference for future projects.

 

Cheers,

Sideway.

train project v2.vlp

Link to comment
Share on other sites

  • MVP 2023

Hi, you did a good homework!

To further simplify (or possibly complicate) it is to create two (or more)  simultaneously operating State machines.

The first for movement - the other for loading and unloading.

In the second version of your program, everything became much clearer, but the loading and unloading processes should be allocated to a separate State machine.

You can run it separately for test, then implement it to main program.

 

Link to comment
Share on other sites

Hello !

Thank you for your kind reply !

I will work on it and try to make it even better ;)

One thing though : i am currently working on the big project (which includes the small train routine, that i left as is : i didnt change anything in it yet).

This program is a lot more complex, and i really struggle architecturing it properly, especially with the I/O module which is mostly setting pneumatic actuators (that can be set/reset for a long period of time, thus i find it hard to use anything else than Set or Reset coils).

The problem is : i have a lot of inputs (XB 1xx) and outputs (XB 2xx) from a WAGO external I/O module, CANopen communication with a servoDrive, HMI menus and navigation etc.

I used "kind of" state machines for each region of my program (ie. i have like 5 subroutines for the Automatic mode only !), but unfortunately it's a real mess to manipulate, update and debug.

Do you have any insight on how i could deal with such a big project or any architecture plan i could follow for really complex projects (in general) ?

 

Cheers, 

Sideway.

 

P.S. : Though the program isnt written in English, the idea here is to talk about the architecture of the program. No need to really understand what it's doing, only knowing which pieces it is made of is sufficient, i guess...

CE prog v2.4 2022-05-20 .vlp

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...