Sign in to follow this  
Followers 0
Nick Clute

ST FB - Syntax for Calling Instructions

11 posts in this topic

Has anybody used CX-P V7 with the Function blocks and ST programming and found out how to write an instructions like COLL? I'm trying to write a function block that needs to have an address passed into it and pulling data from the next few words so using the offset function would be the easiest that I can tell. Any thoughts?

Share this post


Link to post
Share on other sites
This would follow along the lines of indexed addressing, using pointers etc. The bonus of the Omron software, is there is an instruction for almost everything, so complicating code with indexed addressing IF not required is not always required. Are you familiar with using pointers etc? This is basically what the COLL & DIST instructions are doing. To do it in ladder, you do something like MOV @D0 D0. If D0 = 32, this would move the value of D32 into D0. A basic example only, others may point out the flaw in that method! To do it in ST: result := index[pointer] where result is the DESTINATION, index is the SOURCE, and pointer is the OFFSET Hope this helps.

Share this post


Link to post
Share on other sites
I am familiar with pointers, and I understand what COLL is doing. Here is what I need to do specifically: Have an input to a FB be the address of my Profibus Node: CIO3300. Based on that input, I want to read the rest of the node information (30 bytes worth). The only way to pass the actual address and not the information for the address, either needs to be an array in-out variable, or an internal variable with AT settings. From what I've read, you cannot change the internal variable AT settings dynamically, so this is out. If I create and In-Out variable, it will pass the address for use in COLL. Doing as you suggest, I declared is as an array with length 2. I gave the input 499, and wrote Result := DWORD_TO_WORD(Input_Address[1]); So my result should equal the value in address 500, alas, it does not. So if I missed something in your post, please let me know. Thanks!

Share this post


Link to post
Share on other sites
Can you post a snippet of your cx-p file with the FB where you are trying to do this?

Share this post


Link to post
Share on other sites
I can, but really it was just the one line that I posted...here is the corresponding ladder. And here is where I call that FB... As you can see, doing it this way it will pass the address into the FB, and I can increment it from there...just trying to find out similar ways to do this with ST, since a lot of my other functionality will be easier with ST.

Share this post


Link to post
Share on other sites
Hi Nick Does this help? Lets you get an address into an FB rather than the contents of the adress... Edited by ParaffinPower

Share this post


Link to post
Share on other sites
Hi Nick I would suggest using index registers (see attached jpg) There is no way to do this using ST. Instead you could divide you function block in two. One for ladder and one for ST, and then call the ST FB from the Ladder FB. BR

Share this post


Link to post
Share on other sites
What about declaring the 'index' as an AT variable, make it CIO 0. Then make the pointer the value of the CIO area that you want to read. I am not super competent with the index registers, have never had the need to really use them. As with anything though, they all have there use. arrayex.cxp

Share this post


Link to post
Share on other sites
Hi Scott. See my example further up. Basically, the 'AT 0' points at the whole of the CIO area. Cheers, Pp

Share this post


Link to post
Share on other sites
Scott, Thanks! That was exactly what I needed! what PP offered was good, however it was in ladder when I needed the ST. I almost didn't understand what you meant until I saw you attached an example. I find it strange that it will only work once you declare an array, but it doesn't need to be a large array, just any array. Oh well, as long as we know that it works, thats all that matters. Thanks everybody for your input! I'm sure I'll have more questions as I continue on (including acyclic telegrams over Profibus) Nick

Share this post


Link to post
Share on other sites
Sorry Pp, I did see your example. The poster was after a way of doing this in ST. Edited by scottmurphy

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