LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to adjust rate of reading data from 1D array

I'm running a control loop on a real time system at 2kHz.  A 'reference trajectory' (collected at 500 Hz) is read from a 1D array.  My code is set up to read the same reference value for 4 iterations, and then it moves on to the next value for another 4 loop iterations and so on.  I'd like to be able to adjust the number of loop iterations for which the same value is being read on the fly.  I've tried dividing the "4" in the attached image, but the reference trajectory doesn't advance to the next value in series, but is reset back to initial value.  Any suggestions?

 

Maciek

0 Kudos
Message 1 of 2
(2,279 Views)

There isn't much of the diagram there so it is hard to see what actually went wrong.  But it looks like you are doing floating point division every time your loop cycles (2kHz?), then proceeding to convert it back to integer anyways.  Floating point division is an expensive operation.  Plus your comment says Loop Rate but the wire is coming from the index terminal.  

 

You are also referencing a 32 bit signed integer counter in a 2kHz loop.  that will roll over (or does it always stick high on a RT target?) after ~12.5 days uptime with indeterminate results if your divisor isn't a power of 2; and maybe weird even as a power of 2, I didn't work out the edge-case bit patterns in my head.

 

Again, this is all speculation.  I can't see enough of the diagram to verify that code is actually in your 2kHz loop.

 

I would think that a resetting counter shift register (rolls over every N iterations for example) would work and be efficient on RT.

0 Kudos
Message 2 of 2
(2,275 Views)