RSLogix 5 Passing Parameters to a Timer in a Subroutine

nrwicks

Member
Join Date
May 2010
Location
Wilson
Posts
8
I am trying to create a common "motor control" subroutine in RSLogix5. I would then "jsr" with parameters once for each motor. No problem so far.

How would I include a timer "TON" for example within the subroutine, and pass the timer parameters which may be different for each motor.?

I have tried passing .ACC .PRE. .EN and .TT, but it does not work correctly.

I do this regularly in RSLogix5000, but then the whole timer is being passed as a parameter. Any Ideas?
 
Are you trying to write to a timer within the subroutine? Or are you just trying to pass a timers values to the sub.?

If just passing a timers info then move them to an integer first then pass them.
 
Yeah, not having UDT's really sucks....

You cannot pass a timer as a parameter to the subroutine, and just passing a PRE and an ACC value to be put into a timer in the subroutine will lead to innacuracies. Just be aware that timers are not real timers, they are simply instructions to the processor to calculate how long has elapsed since it was last scanned, and update the .ACC accordingly. You need to use a separate timer address for each motor.

The best appraoch would be to pass a pointer to the timer to be addressed.

For example, you have 30 motors - so create a timer file eg. T20:0 to 29. You pass the timer number into a SBR parameter, say N7:100

The logic in the subroutine would then indirectly address the relevant timer with T20;[N7:100] Not sure of the syntax, i think you can drop the : but not sure.

Been a while since i worked on PLC5

hth
 
first of all, welcome to the forum ...

I've just gotta ask: have you given any consideration as to how difficult this arrangement is going to be to troubleshoot? ...

(sorry if I've misunderstood what you're trying to set up here, but based on what you've posted so far, this thing sounds like a NIGHTMARE in the making) ...

rungs are cheap ... troubleshooting time is expensive ... trying to make JSRs act like UDTs is not something I'd recommend ...

think about what a technician is going to see when he looks at this program in operation ... troubleshooting why MOTOR_X won't run is going to be impossible - if your ONE subroutine is also controlling MOTOR_A through MOTOR_Z ... in simple terms, the rung conditions won't "stand still" long enough to be interpreted ...

(once again, I apologize if I've misunderstood what you're up to here) ...

party on ...
 
Last edited:
We have one particular integrator that is very JSR happy - they have a subroutine for every digital input, digital output, analog input, output, valve type x, valve type y, z, motor, vfd wire controlled, vfd DNET controlled, and on and on and on...

One way that we have found to make trouble shooting easier is to copy the logic in the generic subroutine to a "test" sbr and redirect the device in question to it so that WYSIWYG.

We're working on creating AOI's but it's going to take a while.
 
Greetings steveb1475 ...

One way that we have found to make trouble shooting easier is to copy the logic in the generic subroutine to a "test" sbr and redirect the device in question to it so that WYSIWYG.

thanks for your input ... actually that's EXACTLY the method that I've used before when troubleshooting a programmer's single "ultra-elegant" rung ... this arrangement was transmiting a large number of network messages by looping repeatedly over just one MSG (Message) instruction - and having the ladder logic change the MSG parameters "on the fly" ...

I think I can already guess the answer - but I've got to ask anyway ... is it possible for you to post (or email) an example of that program you're talking about? ... collecting things like that is sort of a hobby of mine ... just ignore this request if it's out of line - I assure you I'll understand ...
 
daba - Yes "not having UDT's really sucks...." - Thanks for the hint on the indirect addressing etc

Ron - Thanks for the welcome. I get your point about the trouble shooting. I do this regularly within the Logix, where I may call the same subroutine a few hundred times, once for each motor. But then at the end, I call the same subroutine with a user defined index (motor number). The subroutine is then WYSIWYG for that motor. When I do this, I always provide extended diagnostics in the HMI for the entry level technicians who may not understand the concept of changing the index number before fault finding.

steveb1475 - I guess this is similar to your test subroutine, but I make it a permanent part if the program. Yes, one motor is always called twice each scan, but this is not a problem.

Thank you all for your input - I guess I will now simply do it the old way and quit trying to make the PLC5 work like a Logix
 
But then at the end, I call the same subroutine with a user defined index (motor number). The subroutine is then WYSIWYG for that motor.

now that's an interesting approach – and one that I've never run across before ... this is probably going to be my "learn something new" trick for today ... I'll definitely make a note of it for future consideration ...

I guess I will now simply do it the old way and quit trying to make the PLC5 work like a Logix

I know that I'm old-fashioned – but for my money, that's probably going to be the best way in the end ... it sounds like you've got a handle on the situation – so I'll just mention the following for any newer readers who might pass this way in the future ...

the main idea that many programmers miss when they set up a "looping" routine is that the processor (bless its little heart) still has to execute just as many XICs and OTEs, etc. as it would if the logic were spread out over many separate rungs ... PLUS ... the processor ALSO has to execute the "looping" instructions (example: LBL and JMP) and the "incrementing" logic and the "do until" decision logic - all in addition to the TOTAL number of "control logic" instructions ... ALSO, if processing time is indeed an issue, indirect addresses are somewhat costly to execute ...

in short, most "ultra-elegant" recursive loops save nothing in terms of processing time – and in fact, they invariably cost MORE time and processing horsepower ... and worst of all, they can make troubleshooting very challenging – mainly because the logic won't "stand still" while troubleshooting any particular "problem" device – since all of the other devices in the loop must still be continually controlled ... (of course the approach outlined above by nrwicks would go a long way towards solving the potential troubleshooting argument) ...

notice that I am NOT saying that "loops" and JSRs don't have their place – but in many cases a simpler approach of just Copying-and-Pasting in a proven "cookie cutter" pattern of rungs (and then "tweaking" the addresses) would turn out to be much easier to implement ... and much easier to live with as time goes by ... and probably save some processing time and horsepower – assuming that those are valid concerns ...
 
I have fought this more than once. The first time I did this I ran across a PID loop(s) 18 of them JSR with par. The programmer said it works faster that way. I built an identical 18 loop PID with his logic but without JSRing anything.
I used excel to spit out the logic in less than 5 min. So the development time issue is out. He spent 4 hours to build the loop.
I don't have the scan time numbers any more but it was faster by a little.
 
The JSR is a big scan time hit, as well as the return, JMP and LBL are too. Especially when parameters are passed. And indirect addressing always increases scan time.

I don't recall the numbers but a JSR takes something like 15 times what an OTE instruction takes in a PLC-5 in CPU time.

I have used "common driver code" when there are dozens of iterations though.

I don't put the JSRs inside the loop though, rather loop a pointer through an array of UDTs...yes, you can make a UDT in RSLogix5, you just gotta do it by hand. I never put real I/O inside the loop. Map the Inputs and Outputs externally so you can see them in a static fashion, and perform re-assignment for quicker maintenance if necessary.

Once you get the algorithm and is options nailed down, there is nothing wrong with looping through them and using indirect addressing, and then copying one of them to your HMI faceplate data area.

If there are less than a dozen or so, or if they might need to have unique functions later, and you don't mind editing each instance individually to make changes, then just use the brute force method. It will always run faster, and you can put a page title at the beginning of each motor control section.

Then for ease of navigation in RSLogix 5, you can take advantage of Advanced Diagnostics (CTRL+D) to make finding the code very easy.

I have not used parameter passing with a PLC-5 except for conditional JSRs for special math or data manipulation.

Yes, getting carried away jumping back and forth 100 times to 10 and twenty rung SUBs is a waste of horsepower.

On the other side of the debate, If you have scan time to spare for indirection, using common driver code can make handling lots of equipment (think 100 pumps with the same feedback switches) easier on the programmer, and free up instruction space for data collection. In a PLC5, though, would do it with JMP and LBL, with a pointer control like a FOR NEXT loop.
 
Last edited:
Learn something new every day.

I can check my list off for today I learned something new.

Paul I have never used that CTRL+D before. I like that. Thanks
 
We have one particular integrator that is very JSR happy - they have a subroutine for every digital input, digital output, analog input, output, valve type x, valve type y, z, motor, vfd wire controlled, vfd DNET controlled, and on and on and on...

actually that's EXACTLY the method that I've used before when troubleshooting a programmer's single "ultra-elegant" rung ...

you know... if we find this hypothetical ultra-rung programmer, there'll be a line of people waiting to slap him silly. Utah now, Steve? I'm on the way. You have described my current nightmare program to a "T". I wonder if there's a school teaching this nonsense.
 
I wonder if there's a school teaching this nonsense.
I mean no disrespect to anyone with this post. If you take it wrong try to stop and look at it from the guy at midnight that has been in the plant since 8:00 AM and is banging his head on the keyboard cussing at the original programmer because he didn’t put any diagnostic code in there.

I like to follow what Peter Nachtwey once posted, that around 40% of his code was diagnostics. I may have mis-read that post but I try to make sure that if something happens that the code can detect, it does and notifies you.

I bet this is learned in the school of "I have never to troubleshoot anything before, I just write the code."

I would ASSuME there is a college teaching this.
I have a good friend that teaches PLCs. He is one of the guys that has been in the trenches and tries to teach how to get out of them. SO not all of the guys that teach this are bad but a lot of them can’t program their way out of a paper bag.
 
I wonder if there's a school teaching this nonsense.

probably a lot of them ...

my personal theory is that most of these "ultra-elegant" types of programmers are people who have recently graduated from college with a degree in "computer programming" ...

and now they're out there in the real world - trying to shoehorn the PLC's ladder logic into the same patterns of execution that they learned with PASCAL, C++, FORTRAN, or whatever other programming language they studied in school ...

I think that when the dust finally settles on this particular thread, the general consensus will be:

(1) if you have a VALID reason for "looping" or "subroutine-ing" or "whatever" – then the programming approach is fine ...

on the other hand ...

(2) if the ONLY reason is to establish "bragging rights" on being able to cram as much logic as possible into as few rungs as possible – then the approach is questionable (at best) ...

personally I always fall back on the idea that rungs are cheap - troubleshooting time is expensive ...
 
Last edited:

Similar Topics

Though i was working with add-ons for a lot of times recently i am stuck in a simple proble. I have a TAG READ_DATA[502]-INT ARRAY R/W I am...
Replies
2
Views
1,871
Hello, I am trying to read a barcode scanner input using a cognex dataman 280 barcode reader, store it another string, the compare with another...
Replies
1
Views
45
Hi Everyone, I am not proficient in RSLogix 500 so I have a question regarding the evaluation of N7:0 data as an input. So as I understand in...
Replies
1
Views
93
Hi folks, in the alarm manager of Rslogix 5000, the tag-based alarm has been created. But when I tried to change the condition, it was found the...
Replies
2
Views
165
I have a little bit of experience with Allen-Bradley. I have a Micrologix 1500 (RSLogix 500) and a PanelView Plus 7 (FactoryTalk View Studio ME)...
Replies
3
Views
192
Back
Top Bottom