Jump to content

Recommended Posts

  • MVP 2023
4 minutes ago, Jamie123 said:

The program has thrown out some weird behaviour (timers not resetting, coils remaining energized, cycle 1 works cycle 2 doesn't )

This is why I said conditional subroutine calls are dangerous. You can inadvertently leave coils hanging in limbo and get unexpected results.

 

6 minutes ago, Jamie123 said:

Is the correct way therefore to call all subroutines in the main program and use the index coil to activate each rung of the subroutine you want to execute?

Yes, that's the way I do it. I usually don't use separate subroutines for each step of the state machine, but if each step is complex or lengthy, separate subroutines might be the way to go.

Link to comment
Share on other sites

  • MVP 2023

+1 to what Flex says.  If I may elaborate-

If you stop calling a subroutine everything in it stays the way it was in the last call.  So coils get left on, timers don't reset, etc.  You have to be very careful cleaning up after yourself if you use conditional subroutines.

This is why my State Machine example uses a common pointer (MI 0) with Equal blocks and has all the logic in one subroutine.  If you need more space for a given step you can set a coil that is only true while the pointer is equal to a given value (like MB 0 in the first net).

With the pointer method, only a small amount of a larger subroutine will solve at any given time.  The rest won't because the Equal blocks won't let them.

For the next level of State Machine programming, I also usually put all my output coils in their own subroutine which is called all the time.  Then I can put them in order and use the internal coils I set in the sequence subroutine to control them.  If an output needs to be on for more than one step, just add additional contacts in parallel-

image.png.ed10002fff1e2c316ede1f881dd8fcbb.png 

This makes control and troubleshooting much easier.  It puts me in charge of the program, not the other way around.  I'm not guessing what other logic may exist that I may not of thought of and now I have to make a mish-mash of logical ANDs and ORs to get the output to work right.  I call this method "bit-banging".  And it's a nightmare to figure out someone else's bit-banger.  It's like trying to dance to jazz music. 

If you post your program we can have a look.

Joe T.

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...