FOR instruction help in Studio 5000

DaveLM

Member
Join Date
May 2017
Location
Indianapolis
Posts
2
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
 
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.
 
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.
 
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 :)
 
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.
 
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...).
 
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.

For_Instruction.jpg
 

Similar Topics

I am using Studio 5000 Version 30 and Compactlogix. I have a recipe created in a UDT structure, with a string value called name. There are 50...
Replies
7
Views
5,371
I've been beating my head :bonkhead: in all day trying to figure out why the FSC instruction isn't working in my Program. I Created a 1500 Recipe...
Replies
13
Views
6,934
Hi guys, beginner here. I need to be able to stop an incremental MAM instruction in Studio 5000 and then start it back. But the catch is I...
Replies
8
Views
263
I have a DCS instruction, that is set up for an E-STOP. I have the restart type and cold start type both set as automatic. I can test the e-stop...
Replies
2
Views
353
Hi everybody, I'm working on a 5069-L306ERM CPU with 1732E-OB8M8 output module. I'm trying to produce cam signals with MAOC command. I have a 842E...
Replies
2
Views
1,214
Back
Top Bottom