Jump to content

Recommended Posts

Say you have a 3 screens/modes, Manual, Semi and Automatic.

1) Would it be kosher to have a sub routine strictly to that screen/mode in focus to save scan time?
2) Under that circumstance would it still be bad practice to reuse coils that were in another routine even though they cant be called at the same time?
3) I would fear doing what I am saying would leave coils set when you change screens. I would have to write one long line of resets upon leaving? 
 

Thanks in advance.

Link to post
Share on other sites
1 hour ago, Ausman said:

Visco, Joe recently answered this quite well here: http://forum.unitronics.com/topic/7081-subroutines/?do=findComment&comment=28796 

The rest of the topic is a good read as well.

Subs can be very tricky to implement properly unless you follow sequencing like he mentions.

cheers, Aus

 

It sounds like he is doing something similar to me. In my mind subroutines seem so organized, but the more I read ,the more they seem like a pain in the aperture within the gluteal folds of ladder logic

Link to post
Share on other sites

My personal policy is to ALWAYS avoid conditional subroutines. There just isn't any good reason for them. Write your code so that every ladder rung is executed on every scan and you will avoid unnecessary grief.

17 hours ago, viscoelastic said:

Under that circumstance would it still be bad practice to reuse coils that were in another routine even though they cant be called at the same time?

In VisiLogic with Vision PLCs, you have 8192 coils. Are you running out?

Link to post
Share on other sites
7 hours ago, Flex727 said:

In VisiLogic with Vision PLCs, you have 8192 coils. Are you running out?

No but you only have so many outputs. It just seems to get overwhelming and confusing have multiple coils calling one Output coil.

Link to post
Share on other sites

There's no law that says you can't do it and the program will compile without errors, it just that experienced programmers consider it poor programming practice. There's a reason for that, but it doesn't mean it's impossible to be successful reusing coils in conditional subroutines. When you're the programmer you get to create your own style and technique.

Link to post
Share on other sites

Everyone in the process of building a program in the Visilogic comes to their own style of writing.
Therefore, we can come to the same action in our programs in completely different ways.

In most cases, I have to test the program without having the whole system at hand.

Therefore, for almost all types of panels, I wrote "my standard" routines for polling inputs and output control.
This led to the idea that the activation of the output should be only in one place in the program - in this case, the subroutine OUTPUTS.
Input polling is similar in another subroutine INPUTS.
Values from inputs are overwritten into variables and used later in the program code. In this case i can add tesing MB for manual activation of input via online simulation.
Each subroutine generates its own variable which should activate the output in the OUTPUTS subroutine only when the desired screen is active or the required condition is met.
It is especially useful to see that the output is turned off by an emergency button or subroutine in one place.

INPUTS.jpg.528c15001ae35ef927e329a4671cd9da.jpg

OUTPUTS.thumb.jpg.f4bc02b9ff32fc6550d36c6ebbb29a87.jpg

  • Like 1
Link to post
Share on other sites

For what it's worth, I (almost) never use conditional subs.   I only use subs to break up the Main Module into easily recognisable controls.  Each one of these subs will likely generate quite a few MBs which relate to actual outputs, and I combine them in that sub  to just one that is used further down in my outputs sub.  Edit...The reason I do lots of MBs is so that I can actually see far more easily what is going on.  If I use a common MB that is referenced many times through the ladder then it is a lot harder to find what is actually creating the condition it is currently in.  Many people DO use the same MB to keep things "simple", but I often have so many things relating to a single output that without the separate MBs and conditions it can be very hard to track, as you only get to see the end result when online. 

I have said this before about programming, but Excel is your friend.  It is easy to generate sheets with numbers, and it makes it much easier when you have such a ready reference.  The descriptions in the sheet are more thorough than what is in my project.  I describe them with both their name and a more complete "what, how, where" if necessary.

However, conditional subs relating to screens do have their place if done properly.  A crucial page to remember in help is this one.

cheers, Aus

subs.jpg.a466dde64dfb9011623e2f656c0ae806.jpg

Link to post
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...