Popnfrsh24

Help with IR loop dilemma

11 posts in this topic

Hey there,

 

So at my job, we use a lot of IR loops.  It's pretty much the only way I know how to do "for loops" in PLC code.  So I am very familiar with how we use them.  But, I'm trying to develop some new code, and it made me realize that maybe I don't know as much as I thought....

So, my idea is that I have a range of numbers that I have stored in a range of D memory.  My idea is that these numbers take up the entire word of D memory.  So I have a list of 100 numbers that start at D30000 and end at d30099.

 

My idea was to use a free IR register and start it at D30000, and increment it by a complete word for each loop (#10).  Then in my code, whenever a certain condition is met, I want to move the entire word that is in this index register to another free word in D memory.

What I've never noticed is that any time I'm doing coding inside of the Index register loop, you always use the ',' to point to the specific bit of that word.  So 8,IR1 is looking at the 8th bit of IR1.  That's where I am getting in trouble...even though I am incrementing the Index register by a whole word, it seems like I can't reference the whole word inside of the IR register...I always have to reference the individual bits?

Does anybody know if I can reference the entire word in the index register?  I tried doing a MOV command and Move the entire word of IR8 to a new D word, and it wouldn't let me.  Is there a way to get around this?  

I guess I could potentially just use the Mov command and do 16 individual commands that span from 0,IR8 to 15,IR8 to move the whole word to a new location?

 

Thanks,


Pop

Share this post


Link to post
Share on other sites

can you post what you have done?

Quote

What I've never noticed is that any time I'm doing coding inside of the Index register loop, you always use the ',' to point to the specific bit of that word.  So 8,IR1 is looking at the 8th bit of IR1.  That's where I am getting in trouble...even though I am incrementing the Index register by a whole word, it seems like I can't reference the whole word inside of the IR register...I always have to reference the individual bits?

This is dependent on how the IR is loaded.

If you MOVR W100.00 IR0, it will load the index as bits. So +8,IR0 will look at W100.07

If you MOVR W100 IR0, it will load as word, then +8,IR0 will reference W107

 

Have you looked at my example in this post, it may answer your questions.?

http://forums.mrplc.com/index.php?/topic/38647-nested-loop-increment-word-address-and-not-the-contents/

1 person likes this

Share this post


Link to post
Share on other sites
3 hours ago, Popnfrsh24 said:

My idea was to use a free IR register and start it at D30000, and increment it by a complete word for each loop (#10).  Then in my code, whenever a certain condition is met, I want to move the entire word that is in this index register to another free word in D memory

Be careful with this memory area.  D30000 is the area that CPU Bus units (usually communication modules, EIP21, ETN21, CLK21, etc) use for their settings in CS and CJ processors.

2 people like this

Share this post


Link to post
Share on other sites
4 hours ago, lostcontrol said:

can you post what you have done?

This is dependent on how the IR is loaded.

If you MOVR W100.00 IR0, it will load the index as bits. So +8,IR0 will look at W100.07

If you MOVR W100 IR0, it will load as word, then +8,IR0 will reference W107

 

Have you looked at my example in this post, it may answer your questions.?

http://forums.mrplc.com/index.php?/topic/38647-nested-loop-increment-word-address-and-not-the-contents/

Yes I understand the difference between defining between W100.00 and W100.  I have tried doing it both ways with no luck.

 

Here is a screenshot of what I am doing.  Here's the initial part where I am defining it...and then here is how I am referencing it in the loop.  It does not seem to like me referencing it competely as IR8.  As soon as I add a , to go to bit level, it is happy.  Is there maybe another instruction block I need to use?

plc.png

Share this post


Link to post
Share on other sites
5 hours ago, Michael Walsh said:

Be careful with this memory area.  D30000 is the area that CPU Bus units (usually communication modules, EIP21, ETN21, CLK21, etc) use for their settings in CS and CJ processors.

Take heed of this advice. I see you may of changed it to D20000, from memory this is still an area to avoid unless you know explicitly that the area is not in use.

 

Quote

As soon as I add a , to go to bit level, it is happy. 

Are you wanting bit reference, or word reference? 

In your example, what actual address are you wanting to reference based on your condition? Do you want D20000.xx (bit offset), or D2000x where x is 0-9 (word offset)?

 

Share this post


Link to post
Share on other sites
20 hours ago, lostcontrol said:

Take heed of this advice. I see you may of changed it to D20000, from memory this is still an area to avoid unless you know explicitly that the area is not in use.

 

Are you wanting bit reference, or word reference? 

In your example, what actual address are you wanting to reference based on your condition? Do you want D20000.xx (bit offset), or D2000x where x is 0-9 (word offset)?

 

I would like to reference the entire word that is stored in D20000.  My idea is that my HMI program is actually loading in integer values into D20000-D20100.  So for example, D20000 could have a value of 7 (&7) and D20001 could have 11 (&11).  What I want to do is to scan thru this whole list, and if a specific condition is met, I would like to move this value into a new spot in D memory.  

 

So my thought was...set IR8 to start at D20000 and loop for 100 times, see if IR8 = (whatever condition I have) and if so use MOV to move that entire word to a new D memory location.  Can I not do this?  Do I have to use a function block with structured text intsead?

Thanks,

Share this post


Link to post
Share on other sites

If your wanting the value IR8 is pointing to you need ,IR8 not IR8.

IR.png.f88ac736c1d1dbb98ac172476701b27a.

Share this post


Link to post
Share on other sites

Posted (edited)

Quote

My idea is that my HMI program is actually loading in integer values into D20000-D20100

Remember that it could be risky using this area.

Quote

So my thought was...set IR8 to start at D20000 and loop for 100 times, see if IR8 = (whatever condition I have) and if so use MOV to move that entire word to a new D memory location.  Can I not do this

Yes, easily. I think your dilemma is how you are increment IR8.

Quote

My idea is that my HMI program is actually loading in integer values into D20000-D20100

Is your HMI table in blocks, or individuals? ie. is there 100x values you want to reference, or only 10? If individuals, then it is easily done, but if an index in a block you would need to specify the offset.

IR8 can be incremented by any value, then you just use that MOVE ,IR8 D5280 if your conditions are met.

 

Quote

 Do I have to use a function block with structured text intsead?

No.

 

How are you incrementing IR8? 

Edited by lostcontrol

Share this post


Link to post
Share on other sites
21 hours ago, chelton said:

If your wanting the value IR8 is pointing to you need ,IR8 not IR8.

IR.png.f88ac736c1d1dbb98ac172476701b27a.

So...I thought that if I put in ,ir8 it would only reference bit 0 of IR8.  I am incrementing by an entire word at the end of my IR loop so by #10.  I think you guys were onto something by not using D30000 and D20000....I moved it to like D600 and it works now!  I added that comma and now it works and looks like it is shoving the right value in the right spots!  thanks for the help

Share this post


Link to post
Share on other sites
1 hour ago, Popnfrsh24 said:

So...I thought that if I put in ,ir8 it would only reference bit 0 of IR8.  I am incrementing by an entire word at the end of my IR loop so by #10.  I think you guys were onto something by not using D30000 and D20000....I moved it to like D600 and it works now!  I added that comma and now it works and looks like it is shoving the right value in the right spots!  thanks for the help

How are you incrementing the index register?

To increment by 1 word you can do:

,IR8+    This will read the value at the pointer first then increment or,

,+IR8 This will increment the IR first then read the value at the pointer

 

Share this post


Link to post
Share on other sites

You could also just use offset addresses if that makes it easier. For example if D0 contained &8 D100[D0] would actually reference D108.

Here's an example of comparing a single word D21 with a range of words D30-D39 if a match exists set a bit.

5ebc6fe553042_AddressOffset.thumb.png.21 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now