You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 19th, 2018, 07:32 PM   #1
cd36
Member
Canada

cd36 is offline
 
Join Date: Nov 2018
Location: Mb
Posts: 3
Reducing Repetitive Code

Hey,

I am working on a project that is a bit more involved than past ones I have done. It will be using a CompactLogix PLC, and I'm using Studio 5000 v30.

Some parts of my code are going to be very repetitive, for example I will have to control 12 gates, all 12 gates will require the exact same logic, the only thing that will change is the I/O's that they use. In the past I would just brute force this, as I was never dealing with so many repeat instances, but I'm looking to simplify my code.

Essentially I'm wanting two subroutines, one to Open the gate, and one to close the gate. All 12 gates will be controlled independently from one another, but their logic will be the exact same. Each gate has an Open Limit Switch, Closed Limit Switch, Full Bin Sensor (don't open gate if bin is already full), and an output to Open, one to Close, then just some status indicators (Opened, Closed, Transit).

Now my big question, can I write a subroutine, with the generic logic that would control all gates, and when my main routine calls that subroutine, have it pass all the appropriate I/O's to the subroutine so it opens whatever gate the user is requesting? This would be in place of have potentially 24 different subroutines (Open and Close subroutine for each gate).

Thanks for any help you may be able to provide. And I'm sorry if this is a basic question, I haven't been able to find information on how to do exactly what I'm wanting yet. Thanks,
  Reply With Quote
Old November 19th, 2018, 07:44 PM   #2
bkottaras
Member
United States

bkottaras is offline
 
Join Date: Oct 2005
Location: Chicago
Posts: 1,647
I'd look up AOI if I were you.
Write it, test it and if it works as intended, roll it out for all 12 gates.
  Reply With Quote
Old November 19th, 2018, 07:52 PM   #3
collinsd70
Member
United Kingdom

collinsd70 is offline
 
Join Date: Feb 2014
Location: UK
Posts: 29
As bkottaras said you could create an add on instruction, especially as your using Studio 5000 you have more functionality as to what you can pass into your AOI (structures, gsv module names etc).

Once your AOI is working OK- then just use your AOI as a multi-instance- and declare them as an array (or individually if you want better naming conventions).
  Reply With Quote
Old November 19th, 2018, 08:28 PM   #4
ArtWalls
Member
United States

ArtWalls is offline
 
Join Date: Apr 2016
Location: Miami, Arizona
Posts: 25
Add-On instructions are a bit safer as well, I’ve faulted processors with mismatched calling parameters on JSR’s.
  Reply With Quote
Old November 19th, 2018, 08:45 PM   #5
cd36
Member
Canada

cd36 is offline
 
Join Date: Nov 2018
Location: Mb
Posts: 3
Wow, just quickly read through AOIs and that's exactly what I'm looking for. Between them and UDTs I should be able to clean up my program quite a bit. Thanks for the quick help!
  Reply With Quote
Old November 19th, 2018, 10:30 PM   #6
RET
Member
United States

RET is offline
 
Join Date: Feb 2015
Location: Houston, TX
Posts: 224
Quote:
Originally Posted by ArtWalls View Post
Add-On instructions are a bit safer as well, I’ve faulted processors with mismatched calling parameters on JSR’s.
True. I learned that the hard way too.
__________________
This statement is false.
  Reply With Quote
Old November 20th, 2018, 02:48 AM   #7
cardosocea
Member
United Kingdom

cardosocea is offline
 
Join Date: Nov 2016
Location: Fields of corn
Posts: 1,115
Quote:
Originally Posted by cd36 View Post
Wow, just quickly read through AOIs and that's exactly what I'm looking for. Between them and UDTs I should be able to clean up my program quite a bit. Thanks for the quick help!
Do remember the caveat that these cannot be modified online... and how some places specify that no AOI's will be allowed.
  Reply With Quote
Old November 20th, 2018, 12:26 PM   #8
nehpets
Member
Wales

nehpets is offline
 
nehpets's Avatar
 
Join Date: Mar 2009
Location: Wales
Posts: 367
Failing that you could use a subroutine with a 'struct' passed to it as a parameter and the result passed back to the calling routine.
This can be modified online.

Steve
__________________
Why do programmers get confused between Halloween and Christmas - OCT31 = DEC25
  Reply With Quote
Old November 20th, 2018, 01:17 PM   #9
cd36
Member
Canada

cd36 is offline
 
Join Date: Nov 2018
Location: Mb
Posts: 3
Thanks for the alternative option. Editing online isn't a requirement, so I'll look into AOIs. I appreciate everyone's help!
  Reply With Quote
Old November 20th, 2018, 03:49 PM   #10
Vlad Romanov
Member
United States

Vlad Romanov is offline
 
Join Date: Sep 2017
Location: Los Angeles
Posts: 49
To add to the points mentioned above, the FOR instruction can also be utilized in conjunction with AOIs and UDTs to eliminate repetitive AOI calls. I've actually become very frustrated with AOIs which I had to create a lot of rungs for (for each alarm) and just added a single rung which was cycled through by a FOR loop.
__________________
I'm looking for PLC work... http://solisplc.com/
My Allen Bradley PLC Course: PLC Programming
  Reply With Quote
Old November 20th, 2018, 05:37 PM   #11
jstolaruk
Member
United States

jstolaruk is offline
 
Join Date: Dec 2004
Location: Detroit, SouthEast Michigan
Posts: 3,280
Quote:
Originally Posted by Vlad Romanov View Post
To add to the points mentioned above, the FOR instruction can also be utilized in conjunction with AOIs and UDTs to eliminate repetitive AOI calls. I've actually become very frustrated with AOIs which I had to create a lot of rungs for (for each alarm) and just added a single rung which was cycled through by a FOR loop.
Yes, but depending on who will be maintaining the code, there is no better way to mess with a sparkie's head then to put some looping code for him to follow. Impossible to debug. I stick with the brute force method; duplicate till the cows come home but he'll have no problem following it and I won't get that late night phone call.
__________________
"You can live to be a hundred if you give up all the things that make you want to live to be a hundred." Woody Allen
  Reply With Quote
Old November 20th, 2018, 05:46 PM   #12
Vlad Romanov
Member
United States

Vlad Romanov is offline
 
Join Date: Sep 2017
Location: Los Angeles
Posts: 49
Quote:
Originally Posted by jstolaruk View Post
Yes, but depending on who will be maintaining the code, there is no better way to mess with a sparkie's head then to put some looping code for him to follow. Impossible to debug. I stick with the brute force method; duplicate till the cows come home but he'll have no problem following it and I won't get that late night phone call.
That's a fair point, but if you already have AOIs / UDTs, you might as well go all the way; from my experience, technicians either know everything or struggle with XICs/XIOs.

I do agree that it makes it more difficult to troubleshoot, so use with caution...
__________________
I'm looking for PLC work... http://solisplc.com/
My Allen Bradley PLC Course: PLC Programming
  Reply With Quote
Old November 20th, 2018, 07:57 PM   #13
Maxkling
Member
United States

Maxkling is offline
 
Join Date: Mar 2011
Location: Atlanta
Posts: 193
Quote:
Originally Posted by jstolaruk View Post
Yes, but depending on who will be maintaining the code, there is no better way to mess with a sparkie's head then to put some looping code for him to follow. Impossible to debug. I stick with the brute force method; duplicate till the cows come home but he'll have no problem following it and I won't get that late night phone call.
Agree. Using text files with find and replace makes duplicating rungs very easy.

“Common” routines make troubleshooting very difficult.
  Reply With Quote
Old November 21st, 2018, 03:13 AM   #14
cardosocea
Member
United Kingdom

cardosocea is offline
 
Join Date: Nov 2016
Location: Fields of corn
Posts: 1,115
Quote:
Originally Posted by nehpets View Post
Failing that you could use a subroutine with a 'struct' passed to it as a parameter and the result passed back to the calling routine.
This can be modified online.
The question then becomes, can it be viewed online. My understanding is that Rockwell is a bit behind when it comes to online view of subroutine instances (or whatever they call them).

On the one hand, the code is no longer repeated, on the other the code can't be viewed online.
  Reply With Quote
Old November 21st, 2018, 07:10 AM   #15
jstolaruk
Member
United States

jstolaruk is offline
 
Join Date: Dec 2004
Location: Detroit, SouthEast Michigan
Posts: 3,280
Dealing with both RA & Siemens daily, it a little easier to get to view the running logic of a specific instance of an AOI than Siemen's with a FB but both are basically equivalent. I have to go jump through a few more keystrokes to pull it up in Step 7 than the one mouse click in Studio. Though maybe its easier in TIA Portal, customers are sticking with Step 7 for the logic side.

Now, if your making multiple calls in Studio to the same sub-routine with different parameters, that's going to be tough. You'd have to disable all but the one call you're insterested in debugging to see that.
__________________
"You can live to be a hundred if you give up all the things that make you want to live to be a hundred." Woody Allen

Last edited by jstolaruk; November 21st, 2018 at 07:14 AM.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
transfer data code from pc to omron plc ahmed yousri LIVE PLC Questions And Answers 0 March 13th, 2008 08:43 AM
Advice needed for learning how to properly write plc code for machine control SilverLoop LIVE PLC Questions And Answers 18 June 6th, 2006 11:38 AM
About off-line programming? mayhem LIVE PLC Questions And Answers 18 May 23rd, 2006 05:46 PM
Sub-routines - general question burnerman LIVE PLC Questions And Answers 25 March 2nd, 2006 10:56 PM
How to simulate a FOR..NEXT loop? New2PLCs LIVE PLC Questions And Answers 26 May 9th, 2002 01:36 PM


All times are GMT -5. The time now is 10:13 PM.


.