rbaggett

Unusual results copying bits..

9 posts in this topic

I am making an Add-on instruction, containing the rungs in the attached picture.

It works, it puts the bits where I thing they should go, until reelBits[98]. after that point nothing seems to be copied.

CrData is I/O to the add-on, and is an array of 8 INTs

reelBits is an internal array of 128 BOOLs

idx variables are all internal INTs

Any ideas?

funny rungs.PNG

Share this post


Link to post
Share on other sites

I'm not seeing where you test the index bit for a value that's too large. What tells the logic to return to Rung 0 once you've reached the last index value? The very last branch says go here and stop (to me... but it's early and I haven't had my coffee yet)

1 person likes this

Share this post


Link to post
Share on other sites

The NEQ will cause a fall through to the next rung when idx2 reaches 7.

idx will have 16 added 8 times for total of 128, but the last iteration is irrelevant because the loop will fall through and.... I just answered my own question!

The NEQ compare value should be 8. The 8th iteration is never happening.

THANKS!

Share this post


Link to post
Share on other sites

:-) I'm glad I'm not the only one that does that.

The loop you built is a little different than the loop routine that I use for scaling analogs in CLX. Mine has a max index value so I can set it in a tag. That doesn't make it better or worse, it just is. in a CLX box I have to set the index to value - 1 because the arrays are zero based. Ie an array of 128 bits would end at Bit[127] (or something like that). That's why I missed the 7 vs 8 in the NEQ count. 

I'm glad you found your problem. 

1 person likes this

Share this post


Link to post
Share on other sites

BTW, I have been considering building an RNG for Logix, (Good for testing add-on instructions..) I haven't had time, but I could use it now and your sig mentions generating random numbers... Anything you can share?

Share this post


Link to post
Share on other sites

I've already left for work but I can check when I get home. My sig is a play on words though. I think CLX has a random number generator built in

1 person likes this

Share this post


Link to post
Share on other sites

Rule of thumb for CLX:

Never use INT for an array index - always use DINT.

Since memory fetches are always 32 bits, using INT requires additional program code and execution time to extract the 16 bit value.

Individual INT's store 16 bits of data but occupy 32 bits of memory.

1 person likes this

Share this post


Link to post
Share on other sites

We put forth extensive research into a similar ControlLogix issue 2  years ago in which we were pushing the execution of AOI's and getting varied results.  The fix...instead of an AOI used throughout a fast-scheduled routine (4 x 16 AOI blocks), we put all of the code in a single AOI with a fast-scheduled program that had one rung referencing the AOI.  This was an issue we had brought Rockwell into a number of times.  In our case, we were intending to migrate from a PC-based system to ControlLogix and needed our fast routine to execute every 1-2 ms.

1 person likes this

Share this post


Link to post
Share on other sites

Thanks everyone.

all indexes are now 32 bit. I will watch out for funny behavior.

For what it's worth, Here is how I made my RNG. It gives me 128 timer setpoints randomly distributed between 1000 and 1500 mS. The subtract is for a compare that makes a 50 mS pulse from the timer's count. Handy for testing. It could be easily made to give other ranges.

Random Number.PNG

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