From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

presettable up/down counter VI

Has anyone created a VI for LabView that implements the following capability.

   Read logic level from a digital I/O board that have inputs A,B,and I from a incremental shaft encoder to determine shaft position. The encoder output 200 steps per rotation. Therefore, the counter needs to have the capability to be set to 199 if the shaft rotates ccw three degrees from home.

   The counter increments with a clockwise movement and decrements with a counterclockwise rotation.

   I will greatly appreciate any suggestions

0 Kudos
Message 1 of 7
(3,147 Views)
Both the M-series multifunction cards and the 660x series timer/counter cards can directly interface to a quadrature encoder.  The ability to increment and decrement according to rotation direction is built in.  There are shipping examples you can use to try it out.
 
When you read an unsigned 32-bit integer (u32) out of the counter, you just have to convert to a signed 32-bit integer (i32) so you get positive and negative readings.  From there, you can use modulus-like functions if you want to convert from, say, -1 to 199.
 
-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 7
(3,142 Views)
Kevin is right, however I noticed that you wrote "digital I/O...", which might imply that you do not have a board with counter/timer inputs.

You can still achieve what you would be able to with a counter/timer, however your results will be considerable less accurate, as you will be using software counting as opposed to hardware.

I remember seeing an example that showed how to do this, but I'm blanking on it now.  Have a boo in the example finder for encoder or encoder counting.

To write your own would not be that hard, you would only need to poll the input as fast as possible, counting every time you see a transition.  Different directions is slightly more tricky, and you need to monitor your two inputs (A and B), and then determine which leads the other, but the software overhead becomes greater, which further decreases your accuracy.

The more slowly your encoder turns, the more accurate your results will be.

Edit:  I guess I should ask: what DAQ board are you using?

Message Edited by Day on 09-14-2006 12:24 PM

0 Kudos
Message 3 of 7
(3,135 Views)

 I appreciate your email. The problem is how one can set direction flags. Should A be seen first I need to set a clockwise flag so I increment count whereas if B is seen before A I can set counterclockwise so count decrements when A is seen. I also need to set the counter to 0 if an I level is a "0" and A and B are high. My problem is remembering direction state. I thought of using  shift registers but that won't work becuse I can't clear the shift registers.

 Thank you so much for responding to my request.

Lloyd

0 Kudos
Message 4 of 7
(3,125 Views)
Well, to be honest with you, I'm really not sure how you'd determine which comes first, as the timing is quite critical.  Maybe keeping a buffer of the latest 5 readings would help.

I did a quick vi to maybe give you somewhere to start from.  The constants are to be replaced with the actual acquisition of the DIO lines.


Message Edited by Day on 09-14-2006 01:39 PM

0 Kudos
Message 5 of 7
(3,115 Views)
I checked your other similar posts and found that you "don't have access to" any hardware except DIO.  Is this a homework assignment?  Or some kind of at-home hobby-type project using very inexpensive digital I/O, like a parallel port interface?
 
I ask because the bottom line is that you can't count on getting reliable data using software-polled DIO to capture an incremental encoder.  You can never be sure that your polling will happen fast enough and regularly enough that you never miss any digital changes.  And if any digital changes are missed, your position count becomes unreliable and more than likely wrong.
 
Now that said, you can either try to get hardware that'll provide the reliability or you can just accept that your data isn't fully trustworthy.
 
The essence of the decode isn't very complex.  The better implementations are based on the idea of legal state transitions.  There's a normal repeating sequence of the 4 possible states: LL, HL, HH, LH, LL, HL, HH, LH, ...  From any given state, you're only allowed to transition to an immediate neighbor, either left or right.  Rotational direction is implied by which neighbor you move to, left or right.  State transitions that skip the immediate neighbor(s), such as LL-->HH are not allowed!
 
So you have shift registers to store the prior position count and the prior quadrature state.  When you look at your new digital inputs, you look for a change in quadrature state.  If there is one, you can determine whether it's a left or right neighbor and decided whether to increment or decrement your position count.  You can also look for your index pulse I to decide whether to reset your count.
 
Full details left as an exercise in case this is homework...
 
-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 6 of 7
(3,109 Views)

Kevin,

 Thanks again for your input. No this isn't homework but and actual project {'working on. The rate of change is less than 200 transitions per second which I don't consider to demanding.

  I'll attempt to implement your state suggestion but as you have probably surmised from my posting I'll new to LabView  programming.

 

Lloyd

 

 

0 Kudos
Message 7 of 7
(3,100 Views)