Jump to content

Recommended Posts

Good day, please i have been having problem with a program am writing just because i believe it too long so i split it into subroutine but still not working. i checked and followed examples on the program but trying to use it on mine but still not working. Please i need someone to enlighten me on this subroutine, making call and returning to the initial program.

Thanks

Link to comment
Share on other sites

  • MVP 2023
3 hours ago, alagbawale said:

still not working.

This doesn't actually describe the problem.  Your post reads as if the program didn't work, so you split it up and it still doesn't work. We need to know what is not working in order to offer advice. 

cheers, Aus

Link to comment
Share on other sites

  • MVP 2023

1) If you want "main display" at startup, rename the default "Start-Up Display" to "main display" and use that. Don't use SB 2 for your start-up display.
2) Do NOT have conditional subroutine calls. It is poor programming practice and will likely cause logic issues because coils will be left in limbo.
3) Do not place coils in the same ladder rung after a subroutine call. Place the coil at the end of the subroutine itself.
4) You're using MLs for numbers that shouldn't exceed 1000 (percentages). Not harmful, but why?
5) Do NOT do conditional returns in a subroutine! That is asking for a Watchdog Timer error.
6) Avoid using GoTos. This is poor programming practice in nearly all programming languages, but especially so in PLC Ladder Logic.

These are just the immediate problems I see. I haven't attempted to evaluate the logic.

  • Upvote 1
Link to comment
Share on other sites

  • MVP 2023

Get some training. Unitronics has an entire Youtube channel. There are numerous example projects that came with your VisiLogic installation. Study them. Read the Help file that came with VisiLogic.

Think of ladder logic as one continuous series of instructions executed from top to bottom and endlessly repeating. Ladder Logic is not like regular computer programming where you are executing some instructions and go off to do a subroutine from time-to-time when conditions present themselves. Subroutines in Ladder Logic are to break up the code into manageable chunks for easy readability, but all of them should be executed on every scan. The Main Routine should merely be all the Power-Up conditions and then each subroutine is called in the order you want to execute them. Nothing else there.

Regarding the MLs. An ML is a 32-bit signed integer. The range of values is −2,147,483,648 to 2,147,483,647. An MI is a 16-bit signed integer. Its range of values is -32768 to 32767. Like I said it's okay to use an ML when only an MI is needed - I just wondered why.

One technique to help avoid the need for conditional subroutines is called the "State Machine". Our resident super genius, Joe Tauser has kindly written an example for us to learn from:

 

Link to comment
Share on other sites

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.