For Next Loops

jimf

Member
Join Date
Feb 2009
Location
Boise Idaho
Posts
2
Hello All. My name is Jim and hooked on PLC's.

Unfortunantly, I don't know much about them. But what I lack in knowledge I will make up with tenacity.

Anyway, I have a question. I have a AD DL-06DR PLC and the Direct Soft 5 program. I am trying to write a program for the PLC.

I would like to do a for next loop and check the status of X0 - X7 without having to write a seperate rung for each input.

Is there a way to incriment the input number programatically?

So what I mean is; the first time I exicute the loop, I would like to check if X0 is open or closed and then set C0 on or off based on what X0 is.

Then the next time through the loop I would like to check the status of X1 and set C1 to a value and so on and so on.

What do you think? Is there a way to do it?

Thanks for any help you could give me with this.
 
Keep in mind that a PLC operates in a continuous loop running through the whole ladder diagram every few milliseconds.

If you are just experimenting for the sake of learning, then what you want to do will require indirect addressing. Since you want the same rung to reference different points depending on the value of the index in your loop counter.

I am not familiar with AD PLCs so I can't help with the specifics.

Paul
 
Some PLCs will do for/next loops. However any for/next loop has an overhead penalty. Its just eight rungs. I wouldn't bother with a for/next loop for only 8 rungs.

As for learning about for/next, search the forum for some examples of for/next loops.
 
Last edited:
In my opinion A/D has some quirks that do not make it a good learning PLC. While the hardware is priced right, the software is a bit lacking compared to others.

Some examples:
1. addressing is octal (enough said).
2. your program is one big ladder (no sub routines)
3. very easy to overlap address locations if your not careful
4. weird bug (when I was testing it anyway) that if you use unlatch instruction, it unlatches that bit even if rung is not true.
5. you have to draw all the wires for the ladder using shift arrow keys.
 
You are essentially tranferring the state of X0 through ?? to C0 to ??. Of course this can be done in one rung with LD VX0, OUT VC0. But that's no fun.

The DL06 does allow 'bit of word' addressing (B40400.0 = X0) but it doesn't allow the bit, the part after the '.' to be a variable. So that's out

So one method is to load the inputs as a word (LD VX0), then AND it with a value (lets say V2000) which has one bit set, that bit being shifted one place to the left each scan. (I'll let you figure out how to do the bit shifting stuff.) That would give you a word which either has no bits set (the selected input was off) or one bit set (the selected input was on).

So now you have a word. Let's temporaly store this in V2002. How are you going to get it into the C0 to C15 word? (You haven't said if you want to retain in VC0 the bit you read on the previous scan but I'll assume you do.)

First we have to pick up the previous state of the 'C' bits and, just for a moment, turn off the bit we are interested in. Start with your selection word we used above (V2000). Use the invert (INV) command to make a word where all the bits are the opposite of V2000. Now AND this word with VC0. The result is the original contents of VC0 but with your selected bit off.

Now perform an OR (look in the 'Logical' section of the instructions) with your bit word you stored in V2002. This will turn on just the one bit (if it was on) leaving the other bits alone.

Finally store this back to VC0.
 
Last edited:
For/Next Help

Thank you all for the great help! I really appreciate you taking the time to help me with this.

I will take some time and carefully study your responses. I'm sure it will lead me in the right direction.

Jim
 
Greetings Jim ...

and welcome to the forum ...

if you’re doing this just to “learn” then by all means party on ... but – just because you CAN do it, doesn’t mean that you should ...

just think how hard this “for/next” loop is going to be to troubleshoot for someone in the future ...

rungs are cheap ... there’s nothing wrong with using them for the sake of readability ...

plus – the program that you’re planning to write will execute much slower than one written with separate rungs ... reason: the processor still has to examine each “input” bit – and write to each “output” bit just like before ... PLUS! ... the processor will ALSO have to negotiate the looping action – AND the indirect addressing ... this all takes EXTRA time to execute – not less ...

now don’t get me wrong ... there ARE good uses for a For/Next loop arrangement ... but the scenario that you mentioned just doesn’t happen to be one of those uses ...

have fun ...

hint: if your model of processor supports “stage” programming look into that too ... I just KNOW that you’ll like it ...
 
from SCADA Dude ...

4. weird bug (when I was testing it anyway) that if you use unlatch instruction, it unlatches that bit even if rung is not true.

you might want to take a look at this thread when you have a chance ...

basic idea: the NUMBER/ADDRESS of the bit determines whether it acts “retentive” or not ...
 

Similar Topics

From memory in C I would have done something like this: char * a = (char*) malloc(1024 * sizeof(char)); char * b = (char*) malloc(1024 *...
Replies
4
Views
4,918
Hi I am starting to look into S7 pointers I have 3 data blocks in which i wish to compare bits. Below (ladder logic made to source file) is a...
Replies
8
Views
4,612
I've got this start screen where the user has to enter their username and password. The username and password feature works fine. However, I want...
Replies
7
Views
1,482
Anyone know what the little green triangle on SCREEN 3 means ? See picture Thanks
Replies
2
Views
474
What do you guys think of this representation for on/off contacts? C003 is on, then others are off. I have never seen the logic represented in...
Replies
5
Views
1,812
Back
Top Bottom