MartyB

Nested loop, increment word address and not the contents

10 posts in this topic

Hello,

CJ2M CPU-32 to IAI motion controller through ethernet/ip

I'm working on programming electric actuators to pick up parts from a tray. I will have x (row) and y (column) coordinates that I need to update to move the actuators. So to go through the whole tray I would have to use nested loops. (below what i'm trying to achieve if i was doing it in C++)

                                          6 Rows and 6 Columns, palettizing

                                          data rows&columns DWORD (Row1,row2,row3...row6; col1,col2...col6)

                                          c++ code

                                          for i=0,i++,i<6;
                                              rowData = row
                                              for i=0,i++,i<6;
                                                  colData = col
                                                  execute movement
                                                  wait for confirmation
                                              end
                                          end

I have a way of doing it but it will require a lot of repetitive lines and typing every step, and I was wondering if there is a way on every iteration to increment the data location instead of the contents.

In the picture below you can see the example where the goal is to copy data from D8100 to D8000, then in next step from D8102 to D8000, then from D8104 to D8000 and so on. So far in the documentation I was only able to find how to increment contents. Is it even possible to do what I want to?

Annotation 2020-05-06 150752.png

Share this post


Link to post
Share on other sites

Have you talked to Joshua Martin at GA Automation?  He would probably have a good idea.

Share this post


Link to post
Share on other sites

Thanks for the suggestion. He's actually the guy who we buy all Omron stuff from. 

Share this post


Link to post
Share on other sites

I could tell from your profile.  He was my customer before he joined GA Automation.  Good guy and very willing to help or find someone who can help.

Share this post


Link to post
Share on other sites

So the solution suggested was to build function blocks, since you can use structured text inside them and achieve those nested loops.

Or if there are not that many steps then just write out the whole sequence. 

Another interesting function I found was "Address incremental copy" which can copy and paste a repeating block of ladder logic but increment the bits by whatever amount is needed.

Share this post


Link to post
Share on other sites

CJ2 allows a ST program as well (instead of ladder), this might be better suited.

there is also IR functions which I can provide an example of when back at computer.

 

edit:

Have a look at the attached. Have included an example in ST, as well in ladder using IR/DR functions. Sorry I defaulted to +32 loop count just for example, overlooking the 6 request you had. But that is an easy change.

There is also legacy ways using *D100, but we dont need to go down that path.

 

The ST method cannot be used in ladder as they did not allow pointer offsets into an array (from memory).

Using the IR/DR0 method is by far superior as does not require symbol definitions as arrays, but takes a little bit more to understand.

 

Hopefully they easy enough to follow, but let me know if not. Am sure you will understand both methods.

 

CJ2 ArrayPointer Examples.cxp

Edited by lostcontrol

Share this post


Link to post
Share on other sites

Thank you @lostcontrol. to be honest your example initially flew over my head but at least I knew that I needed to look into "pointers/ indirect addressing". Files in the  http://forums.mrplc.com/index.php?/topic/32363-ask-how-to-indirect-addres-plc-omron/  helped tremendously. And then I was able to follow your example.

I'm attaching a program I came up with (tried to simplify as much as possible) and a picture with some screen grabs of the simulation. I think it will serve as a good starting point to the next person trying to learn it. 

 

Pointers.cxp

Pointers cx-Programmer.jpg

Pointers.cxp

1 person likes this

Share this post


Link to post
Share on other sites

@MartyB Good effort, Thanks....As a starter for indirect addressing i was searching some kind of example .Thanks once again

One more thing, Is all the 5 loops completed in one scan or any delay ? How you captured different loop data? I am new in these kind of things.

Edited by Abdul Wajid

Share this post


Link to post
Share on other sites
Quote

Thank you @lostcontrol. to be honest your example initially flew over my head but at least I knew that I needed to look into "pointers/ indirect addressing"

Sorry about that, I thought it might be ok considering you knew what you wanted to achieve. 

Your code looks different to what you were originally trying to achieve?

Share this post


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

Sorry about that, I thought it might be ok considering you knew what you wanted to achieve. 

Your code looks different to what you were originally trying to achieve?

My code is just of the basics to serve as a tutorial for anyone looking into pointers/indirect addressing in the future.

After being able to follow your program I was able to use it for the solution to my own problem

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