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 May 26th, 2017, 11:47 AM   #1
DaveLM
Member
United States

DaveLM is offline
 
Join Date: May 2017
Location: Indianapolis
Posts: 2
FOR instruction help in Studio 5000

Hi! I am trying to use a FOR instruction in Studio 5000 for the first time but can't figure out how to make it work as I'd like. The instruction is arriving at the terminal value nearly immediately after calling the FOR loop. I would like the FOR instruction to index only when the subroutine is complete.

I have a main routine with the FOR instruction calling a subroutine. My index tag data type is set to DINT, initial value =1, step size = 1. Terminal value is whatever (larger than 10). Any timer delays before or after the FOR instruction don't seem to affect the speed at which the instruction indexes. I also tried controlling the rung-condition-in to only be true after the subroutine is complete. No joy.

The subroutine has a sequencer moving from one rung to the next, basically it is toggling a string of lights in sequential order. I would like the sequence to be executed by the FOR instruction, so that the string of lights flashes "x" number of times.

Can anyone lend insight into this? What is the proper way to set up a FOR loop in Studio 5000? Outside literature is also welcome. I've read the programming manual and the instruction help in Studio 5000. Even the examples there haven't helped me understand.

Thank you for any insight!
Dave
  Reply With Quote
Old May 26th, 2017, 12:05 PM   #2
keshik
Lifetime Supporting Member
Canada

keshik is offline
 
Join Date: Jun 2011
Location: Portland, OR
Posts: 401
The FOR loop/subroutine is going to try and execute itself as fast as possible, just like the rest of your code. You could make the FOR loop subroutine execute some complex instructions to give it a delay but that is going to lock up your processor while it is processing that and would be poor practice to do.

If you want there to be more of a time element (each light on for a second or whatever) you would be better off not using the FOR instruction and instead do it long hand. If you have multiple instances of this logic an AOI might be a better choice as well.
  Reply With Quote
Old May 26th, 2017, 12:18 PM   #3
Gomez_
Lifetime Supporting Member
United States

Gomez_ is offline
 
Join Date: Sep 2014
Location: California
Posts: 177
Yeah I agree with keshik, a loop wont work the way you want. You are better off using timers and counters, or a periodic task.
  Reply With Quote
Old May 26th, 2017, 01:56 PM   #4
DaveLM
Member
United States

DaveLM is offline
 
Join Date: May 2017
Location: Indianapolis
Posts: 2
OK, thanks for the replies. I had a long-hand method in mind before I discovered there was a FOR instruction and thought that it might be a more elegant way to accomplish the goal. No worries, now that I see there isn't an easy way I'll just do it the hard way
  Reply With Quote
Old May 26th, 2017, 02:17 PM   #5
Paully's5.0
Lifetime Supporting Member
United States

Paully's5.0 is offline
 
Join Date: Jan 2006
Location: WI
Posts: 2,053
Look at using the SQO instruction. Search the forums you'll find examples.
  Reply With Quote
Old May 26th, 2017, 03:07 PM   #6
widelto
Member
Colombia

widelto is offline
 
widelto's Avatar
 
Join Date: Jul 2005
Location: barranquilla
Posts: 2,595
DaveLM I have used the For instruction, in my case I have to get the name of the product based on their code number, in my case i have more than 500 code numbers and i got the result almost instantly.
The FOR subroutine only runs when necessary.
I can provide you with an example if you need them.
__________________
My two cents.
  Reply With Quote
Old May 27th, 2017, 04:07 AM   #7
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,387
Quote:
Originally Posted by widelto View Post
DaveLM I have used the For instruction, in my case I have to get the name of the product based on their code number, in my case i have more than 500 code numbers and i got the result almost instantly.
The FOR subroutine only runs when necessary.
I can provide you with an example if you need them.
I am slightly at odds with that statement, perhaps you just worded it badly....

The FOR subroutine will execute as many times as programmed in the FOR instruction...

FOR {index} = {initial value} to {terminal value} step {step_size}

All of this will happen within the program scan, only moving on to the next instruction after the FOR when it has completed.

The only way to stop a FOR loop executing the programmed number of times is to program a BRK (Break) instruction in the subroutine called, which sets the index value to the terminal value... The FOR sees this, and ends.

I often do demos where I want a longer scan time than my demo code gives, so use a FOR calling an empty subroutine many thousands of times to simulate that longer scan time... (useful in demonstrating that "toggle bit" actually works...).
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old May 27th, 2017, 10:27 AM   #8
widelto
Member
Colombia

widelto is offline
 
widelto's Avatar
 
Join Date: Jul 2005
Location: barranquilla
Posts: 2,595
This is a system that looks for truck capacity (metric tons) by reading the plate.
After the plate is read this rungs are enable and truck capacity is fetched from an array.
Daba, you are right. The right word would be to enable FOR instruction not to enable subroutine.
This is a system to dispatch Crude Palm oil, we have custody flowmeters to fill truck according to its capacity.
Attached Images
File Type: jpg For_Instruction.jpg (30.7 KB, 25 views)
__________________
My two cents.
  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
Studio 5000 V24 compatibility with 1769-L35E jdbjdb LIVE PLC Questions And Answers 3 November 6th, 2016 05:29 PM
RSLogix & Studio 5000 shazad5444 LIVE PLC Questions And Answers 3 September 11th, 2016 12:05 PM
Studio 5000 logix Designer CliveBaker LIVE PLC Questions And Answers 2 April 11th, 2016 03:31 PM
New guy here, question about 1756-L72 and studio 5000 Jasondelane LIVE PLC Questions And Answers 8 March 12th, 2015 05:10 PM
RSLogix 5000 V15 Features Samneggs LIVE PLC Questions And Answers 18 April 20th, 2006 06:45 PM


All times are GMT -5. The time now is 03:35 PM.


.