Sign in to follow this  
Followers 0
ridgemao

Can I use MOVR in Functional Block, without AT settings?

10 posts in this topic

I defined an array_variable in functional block(ladder program), and I get error when I try to use MOVR to get the address of "array_variable[0]". If I assigned AT settings to array_variable, then I can use the movr command. Is there any other method to use MOVR command inside Functional Block without AT settings? thanks.

Share this post


Link to post
Share on other sites
Hi, and welcome to the forum! What is it you want to do? Do you want to read/write a value from/to a specified address in the PLC memory without defining the address in the FB? Then you may use indirect addressing (IR, DR) to point to that address. Click here for more info on indirect addressing! Example: You must have a AT variable in your FB internal tag list that points on the specific memory area you want to use: i.e: D_AreaPointer (DataType: WORD, AT: D0) MOVR D_AreaPointer IR0 MOV +200 DR0 MOV +100 DR0,IR0 In the example above, you move the value 100 to the address D200. You can then change the value of DR0 to another offset/address you want to read/write to: MOVR D_AreaPointer IR0 MOV +200 DR0 MOV +100 DR0,IR0 + DR0 +1 DR0 MOV +500 DR0,IR0 In this example above you move first the value 100 to the address D200, then move the value 500 to the address D201. You can of course also read this value: MOVR D_AreaPointer IR0 MOV +200 DR0 MOV DR0,IR0 NewVariable In this example above you move the value from the address D200 into an internal variable (NewVariable). Edited by VAU_RMA
2 people like this

Share this post


Link to post
Share on other sites
VAU_RMA, great post and good explanation. However, I believe the disadvantage of declaring AT variables within a function block is that it cannot re-used, especially if pointing to different memory areas [for example WR instead of DM]. It is necessary to create a new function block for each AT variable. I have found that using the technique similar to the Tech. Note from the OMRON Europe website to be very useful. No need to use an AT variable, and function block can be used many times. My 2 Krone! See attached file. Pass An Array Of Data To A Function Block.pdf

Share this post


Link to post
Share on other sites
BnB - In an ideal world, we'd all be using CJ2! Roald's technique can be used across the range; IN_OUTs are still not supported at CP1L level (unfortunately )

Share this post


Link to post
Share on other sites
I get your drift. The method I posted not only works with any CJ series [CJ1 or CJ2] as outlined in the document. Just felt it was good to post the info as not everyone accesses [or can readily find the article] at OMRON Europe . As far as I can tell the CP1L's also do NOT support STRING variables. Any heads up as to whether CP1L function block variables will match those of the CJ series [iN_OUT and STRING variables]?
1 person likes this

Share this post


Link to post
Share on other sites
It should however be possible to set IR0 to D0, IR1 to W0 etc. outside of the FB in you want, and then using them in the FB with a calculated DR0, DR1 etc., thus no use of AT variables in the FB. (correct me if I'm wrong...) Edited by VAU_RMA
1 person likes this

Share this post


Link to post
Share on other sites
BnB - I've not heard of any plans to introduce 'V4' functionality to CP1L - STRING data type, IN_OUTs, and SFC (big fan here!). Marketing will be to blame! Roald - I agree, you can load D0, W0 etc into IRx, and then perform maths on the DR's inside the FB.
1 person likes this

Share this post


Link to post
Share on other sites
I am 95% sure that this is already possible sort of . If you look at some of the Omron FM examples, they use a 'AreaID', that is used to reference each base index area. AT variables are still used, but by no means are they fixed, they just provide an index. Since these are Omron provided, this must be the best way to do the same thing...? I don't see a problem with this method of having all memory areas configured as an AT variable. I do the same thing, but only ever use CIO/DM as that suits all of our needs. Just an observation

Share this post


Link to post
Share on other sites
I found a workaround way to solve my problem. What I really want to do inside FB is that: I create an array(or memory space) inside FB, then I fill in the array with some calculating results. I need to pass this array to other FB. I do want to re-use my FB and I can't use "inout" in CP1L, as mentioned by BnB. So I use MOVR to get the array's first address inside FB. My solution is that uncheck "check stack" in the menu of PLC->Program Check Option.

Share this post


Link to post
Share on other sites
Hi, the correct instruction to find out the address of a variable in a FB is GETID. It works also with non absolut addressing. Please see the Omron-FBs from the library for example. (Sorry, they are not easy to understand) Harald

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
Sign in to follow this  
Followers 0