Jump to content

Recommended Posts

  • MVP 2023
Posted
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.

  • MVP 2023
Posted

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

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
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.