LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Edge Count

Hello guys!

 

 

I'm struggling with a rotary encoder implemented to a treadmill for a few days and I'm not getting over 2 basic problems. Probably everything is really easy, but we got this setup only 2 days ago and I can really say that I'm a beginner in everything. 

I have a Digital input which gives '1' every time the treadmill belt makes a full rotation. I have got a Counter input which provides data about the position of the belt. All I want to do is to set the belt position counter to 0 every time the belt makes a full rotation. Here's what I got until now. Can anybody provide me some help please?

Download All
0 Kudos
Message 1 of 4
(2,367 Views)

Doesn't the counter give a specific amount of pulses/turn? If so, you should use the Counter with a Quotient and Remainder instead and get the total number of turns and it's angular position in one.

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 4
(2,357 Views)

Hi Sz,

 

yesterday you already got an answer on using Q&R, so why don't you try the suggested operation in your VI?

 

 


@szszilard wrote:

I have a Digital input which gives '1' every time the treadmill belt makes a full rotation. I have got a Counter input which provides data about the position of the belt. All I want to do is to set the belt position counter to 0 every time the belt makes a full rotation. Here's what I got until now.


So you are looking for a simple comparison function like this:

 

IF "Digital input" == TRUE THEN
/* you can omit this "== TRUE" for boolean values! */
  counter := 0
ENDIF

 

 On your image:

What's the point of the case structure when there is a TRUE constant wired to its selector input?

 

(As that "Counter" apparently is the "Position" indicator you would need to reset the DAQmx counter task to initialize the counter back to zero, so the Q&R operation would be far more easier!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 4
(2,351 Views)

Yamaeda (as usual) gives very sound advice.  Suppose your encoder gives 1000 counts per revolution (encoders usually tell you how many counts per revolution, or sometimes how many per degree, in which case you multiply by 360).  This can tell you relative position -- if the count increases by 1000, you've gone 1 revolution (in the positive direction), while if it decreases by 1500, you've gone 1.5 revolutions in the opposite (negative) direction.  So if you divide the current count (being sure you increment when it goes positive, and decrement when it goes negative), you have the current relative position, a(nd if you want to know how far it moves between Position A and Position B, you can just subtract their relative positions.

 

But what if you want to know the "absolute" position, i.e. is it at 0 degrees (however you define that)?  That's the function of the digital "once-per-revolution" pulse.  Here's the idea -- you turn the encoder (slowly) in one direction, keeping track of the number of pulses.  Let's say you start your counter at 0 and turn in the positive direction.  At some position < 1000, you will get the "once-per-revolution" pulse, say at 678.  Look at where your encoder "actually" is at this point -- for simplicity, I'm going to assume it is the position you call 0°.  You now have a formula for taking Encoder Counts and getting Shaft Position in degree as an output:

   Shaft Position (°) = 360 °/revolution * (# Counts - Counts at Pulse) / 1000 Counts/revolution 

                               = 360/1000 * (# Counts - Counts at Pulse).

 

With this simple formula, you only need to use the digital pulse once (typically done before taking data) in order to determine Counts at Pulse by the method described again, and thereafter can simply use the data from the encoder itself.

 

Bob Schor

 

P.S. -- Oops, I missed GerdW's response, which is essentially the same as mine, just in many fewer words (sorry about that, both overlooking GerdW and being so verbose ...)

Message 4 of 4
(2,340 Views)