Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

how to limit the range of counter using rotary encoder

Hello all! I'm new user of labview.. I've problem to limit the range of counter by using rotary encoder.. I use DAQmx 6024e in my project.. Actually i am designing the controller for both dyno & throttle for engine testing.. The idea is, i want to vary the output of 0-10V from ni card to control the dyno & throttle.. I'm already manage to get the output from the analog output.. The problem is due to my software.. When i rotate the encoder shaft cw or ccw, it increase or decrease the voltage respectively just like i want.. But, when the counter hit minimum (0 value) it jump to the maximum count which is 16.772M (for koyo encoder that i used).. In that case the output voltage is increase to 10V directly.. So , the question is how can i limit the range of encoder so that it only count certain minimum or maximum value even the shaft is rotate cw or ccw over it standard limit which is 0 to 16.772M count.. Tq
0 Kudos
Message 1 of 3
(4,012 Views)

You'll need to do a little software workaround on the values you read from your counter.   But first a little tutorial to explain *why*.

The E-series boards use 24-bit counters.  When LabVIEW requests an integer count value, the count is returned in a 32-bit unsigned integer datatype, where the 24 lowest bits represent the value in the board's count register.  The upper 8 bits are *always* 0's.

The count register can increment from 0 to 16 million plus (2^24 - 1), then it must "roll over" back to 0 again just like an odometer.  Similarly, when it decrements past 0, it next goes to the max value of 2^24 -1 as you observed.

So we need a little software workaround that'll convert (2^24 -1) to (-1) and (2^24 -2) to (-2), etc.  The way to do it is to first detect whether the highest bit is a 1.  One way is to compare whether the count value is >= 2^23, making sure to use integers to do the comparison.  Whenever the value is >= 2^23, subtract 2^24 from it to create your new count value which will then decrement 3,2,1,0,-1,-2,-3, etc. as desired.

Here's a link to a similar explanation.  Couple more notes too.  First, if this is a continuously rotating encoder, you may still encounter a discontinuity when the revised count value crosses the +/- 2^23 boundary.   Second, direct connection of a quadrature encoder to an E-series board isn't recommended because of unrepeatability when measureing direction changes.

-Kevin P.

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 3
(4,002 Views)
Hello Kevin..

Thanks for your quick response..your advice is very useful for me to solve the problem.


0 Kudos
Message 3 of 3
(3,979 Views)