Sign in to follow this  
Followers 0
scottmurphy

Bit Arrays

7 posts in this topic

I notice now that a symbol can be declared as an array variable for use in the ladder editor. This works fine, but what I was wanting to try and achieve, was to address a bit, based on the value of a pointer. ie. Symbol CIO_0 Address 0 Array Size 32 Type Bool If I enter a contact, and define it as CIO_0[3], this will then access 0.03. What I want to do, is to use CIO_0[pointer], where the pointer is the location of the bit that I want to access. ie If pointer = 10, then bit = 0.10. If pointer = 17, then bit = 1.01. The same method works in a FB, but not in the ladder???

Share this post


Link to post
Share on other sites
I don't think that this is possible in the normal ladder environment. Maybe you could use index and data registers to do what you want? i.e. IR and DR Andy.

Share this post


Link to post
Share on other sites
You could use TST within a word to determine if a bit is on. Add a couple of lines within a loop to decrement the pointer by F and increment the index by 1 (depending on the range) to find the word address.

Share this post


Link to post
Share on other sites
Quite right Andy. This functionality was deliberately disabled as CX-Ps compiler would have no 'address reference' for the "pointer", and hence would not be able to tell whether or not the "pointer" address was valid at compile time. In a Function Block, this does not matter as the addresses are assigned more 'dynamically' Hope this helps explain the situation a little. P.S. Scott, have you had a look at the OUTB instruction? This will turn on a specified bit within a word, i.e. using a pointer!

Share this post


Link to post
Share on other sites
See previous post for more info:- http://forums.mrplc.com/index.php?showtopic=13609

Share this post


Link to post
Share on other sites
Hi Scott, You can use the dr,ir method for dynamic addressing of bits (or words) from within your ladder program. (you probably already know this?). For example: LD P_On MOVR(560) 0.00 IR0 LD P_On MOV(021) &10 DR0 MOV(021) &12 DR1 LD DR0,IR0 OUT DR1,IR0 ie, when CIO 0.10 is on, output CIO 0.12 is turned on. The indirect adressing can be very powerful. The dr is the pointer and can be easily manipulated. Not sure if you are already familiar with dr,ir ? Tim

Share this post


Link to post
Share on other sites
Gidday Nibroc, Yeah, I have used the ir functions before. I think that they are actually better than using the array methods, they seem to require less memory in FB's. Arrays seem easier to follow if you don't know how the dr, ir functions work. I guess arrays are how other packages perform the same thing, but the ir is the best method to use in the Omron world. Just been looking at different methods to streamline duplicate code, is a catch 22, is obvious to the programmer, but if someone comes along later, cannot follow what is happening. Not a major, as it is about the efficiency that is the key. Will be in touch this week chap...

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