Subroutines: Micrologix 1500, RSLogix 500

How will U:3 go low in the next scan? I thought that U:3 will be scanned until given a true 'return from subroutine' instruction?
 
Replace all instances of O:2.0/3 with for instance say B3:2/0 (named Down Command 60Hz or whatever)

Then use this bit in the main routine to turn bit O:2.0/3 on

Do this for the second ote and use say b3:2/1 and put that in the main routine as a branch to turn output O2.0/3

If you see what i mean !

Not got a lotta time, doing diy before missus gets back home!
 
Well I see what you mean, but I think my interpretation of how these subroutines work is totally wrong.

Basically, the AB program control instruction manual is totally useless.

Know where I can get a good rundown on how exactly the subroutines work?
 
perhaps I should outline my problems a bit better.

Say, I use the code that I posted previously.

I pressed the button for the 1st floor goto. that sends me to subroutine U:3. The drive is going at 60Hz.

According to my code, when the elevator reaches prox 2, it should unlatch the bit for 60hz and latch a bit for 35hz, but instead the elevator continues to travel at 60Hz.

Any suggestions to the problem.. I really dont have a clue how I am supposed to program this for subroutines other that what I have done. Maybe I'm stupid, I dont know, but this isnt making much sense.
 
Merganzer said:
Maybe I'm stupid, I dont know, but this isnt making much sense.

Caution....it may be ME o_O

I have never seen it done like this...I will try it and get back to you, do have a processor there? if so set a bit in U:3 see if it stays hi, if it does then I'm the stupid one...but we will both learn something
 
Let me guess - you have previously programmed in other languages - such as BASIC. In that language, once a subroutine is called the program continues to execute within that subroutine until it specifically exits. FORGET ALL THAT!!!!!

The processing of a PLC program is, for the most part one pass through the code, followed by another pass about 1/100th of a second later and on and on.

The code, for an AB PLC, in ladder 2 is the ONLY code executed unless a JSR instruction is true. In tht case the code inside the subroutine is then also executed at the point the subroutine is called. But it is also only passed through ONCE (unless there are special backward stepping instructions which you don't have and should be avoided at this stage of the game). The execution then continues on with the code just after the point where the subroutine was invoked. The RET you have within the subroutine is to terminat execution of the subroutine early during this pass through and return immediately to the calling code.
 
actually, this is my first time using subroutines.. ive used Siemens plcs before, but havent got that far into it.

But what your saying bernie, makes perfect sense

So i need to latch a bit that will cause the processor to scan a particular subroutine over and over again until everything in that subroutine has been done? then unlatch that bit once that subroutine is done.?
 
Merganzer,

OK tried it, now that we are NOT (neither one of us) stupid...but as Bernie has pointed out only ladder 2 will continue to scan without a JSR

Your 0;2/3 will never go low and B3;0/0 will always be hi...but it will not show up that way unless you toggle the bit.

I think you got the picture, good luck
 
In most PLC's outputs are frozen in the last state they were in when you exited the subroutine. You cannot change the output from outside the subroutine when it is inactive.

This type on conrtol would be better suite to stage programming methods or sequencial chart programming.
 
i believe that maybe the reason why the 60Hz bit wouldnt not unlatch is because the first rung of a subroutine is always evaluated as true. The 60Hz output is in the first rung.. therefore its on for eternity. I believe this is what my AB instruction set manual says. Maybe it isnt useless.

thanks all.
 
And just to add in some additional clarification... Someone earlier mentioned not using multiple OTE's.... It's very good advice when using an AB processor. This is my interpretation of how things work... Your milage may vary.....

The OTE command -( )- , basically, is a direct reference to a specific place in the processor memory. Whether the subroutine is being called or not, it's still referencing the SAME EXACT MEMORY LOCATION in the processor in every single subroutine. There is no dynamic memory allocation, or anything like that in these machines. So, in addition to the fact that when you stop calling a subroutine everything that was referenced by that subroutine stays in the same state you left it... You also have the problem that you are refencing the same address in multiple locations.

So.... Although I've been told you can do it, the idea of calling subroutines to execute various sections of code isn't really a great idea in AB land. Don't get me wrong... You CAN do it, and there are some applications where you might HAVE to do it that way, but this one isn't one of them(IMO)

In a more object oriented language, you could totally get away with doing things this exact way. But RS500 doesn't have enough flexibility.

Strange things can happen.
 
tom_stalcup said "And just to add in some additional clarification... someone earlier mentioned not using multiple OTE's.... It's very good advice when using an AB processor."

It is NEVER acceptable to use multiple OTE's on the same output in any processor in my book. Someone mentioned earlier in this topic about using an OTE on seperate bits, then using those individual bits to fire your output with an OTE.That is definately the way to go. The multiple OTE's on an output will cause problems that are hard to figure out/track down as well as cause a major headache while debugging the program.
Also, I have only used "subroutines" to organize the program, not really to change the "Flow".Most of this has probably already been said but this is just my 2 cents on how I do things.
 
I think you also may be overthinking the problem.

You want the motor at 60 hz when it is between the originating and destination proximity switches, regardless of direction, correct?

from start to prox, or prox to stop, you want 35 hz.

You can use latching bits to set the origin, direction, and destination, and then clear them once the destination is reached.

I don't see how a subroutine will help, here. However, as a rule, in my SLC500's I use the Main routine as an organizer, and put all the logic in non-conditioned subroutines.

You might have one sub for determining direction, one for uptravel, one for downtravel, and one for alarms.

Keeping what you want to do separated also helps organize your thoughts. And is easier to diagnose.

I have subroutines with one rung simply because the logic doesn't belong anywhere else. The cost in scan time for small programs is negligible.

oh, and the (RET) commands aren't necessary unless you are doing conditional returns.
 

Similar Topics

Hello, Basic question i believe: Is it possible to create functions/loops/subroutines that can be used on different data files. Example: I have...
Replies
3
Views
2,435
I have been asked to extensively modify a piece of machinery that is very mission critical to the operation, thus not allowed much downtime or...
Replies
4
Views
2,290
We have an application where we need to indicate a piece of machinery needs maintenance. I have created a routine which resets a value of "days...
Replies
12
Views
3,733
Hi all. Please see attached. Tried to google the error with absolutely no results. I did the same at payed version and real PLC so I'm almost...
Replies
7
Views
2,341
hello all is there a rule of thumb as to using or not using subroutines when writing a program ? i am using an Allen Bradley slc 500 thank you...
Replies
5
Views
1,738
Back
Top Bottom