Ken Roach
Lifetime Supporting Member + Moderator
I went off and got a haircut and missed most of the fun. Almost every time I write some indirect-addressing code I fault my controller at least once... and this time I didn't ! The FAL instruction is very powerful but often trips me up so I end up writing simple loops.
I should have shown the datatypes: the integer array was an INT[112] and the floating-point array was a REAL[56].
The FOR instruction is just a special kind of JSR loop: it increments that one specified tag every time it calls the subroutine, and it calls it X number of times all at once before the program continues.
Something you might not expect about FOR/NEXT is that when the instruction completes and the ladder routine continues to the next rung, the index value increments one last time. So the final value of that tag you may have used inside the subroutine for indirect addressing will often be one too high to be used in the same arrays afterwards.
If I was going to use that routine with a Prosoft card I would look to see if there's a scan counter or similar way to tell that the whole block of data I was working with was intact and complete. There's nothing quite like getting one half of a 32-bit REAL value's bits updated to make the result go wonky.
For related asynchronous-to-the-IO-update reasons, there's a Copy Synchronous (CPS) instruction that takes a teensy bit more time than an ordinary COP instruction because it locks the source and destination tags from being updated by I/O or Produced/Consumed or messaging functions until it finishes moving all the data in 32-bit chunks.
I should have shown the datatypes: the integer array was an INT[112] and the floating-point array was a REAL[56].
The FOR instruction is just a special kind of JSR loop: it increments that one specified tag every time it calls the subroutine, and it calls it X number of times all at once before the program continues.
Something you might not expect about FOR/NEXT is that when the instruction completes and the ladder routine continues to the next rung, the index value increments one last time. So the final value of that tag you may have used inside the subroutine for indirect addressing will often be one too high to be used in the same arrays afterwards.
If I was going to use that routine with a Prosoft card I would look to see if there's a scan counter or similar way to tell that the whole block of data I was working with was intact and complete. There's nothing quite like getting one half of a 32-bit REAL value's bits updated to make the result go wonky.
For related asynchronous-to-the-IO-update reasons, there's a Copy Synchronous (CPS) instruction that takes a teensy bit more time than an ordinary COP instruction because it locks the source and destination tags from being updated by I/O or Produced/Consumed or messaging functions until it finishes moving all the data in 32-bit chunks.