LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rotary Encoder + ni usb 6009

Solved!
Go to solution

I totally understood what you meant about counters, but unfortunately like I mentioned, currently it's impossible for me to change device (I have to use NI USB 6009, just because i'm working remotely due to spreading covid-19 emergency), and so i have to use this setup already done.

But sorry, is it possible to use NI USB 6009 in counters mode? I have to cable attach in ai0 and ai1. 

May someone provide any helpful suggestions since I'm a beginner.

 

Thanks a lot.

0 Kudos
Message 11 of 41
(2,134 Views)

If you rotate really slowly then it will work. The faster you go the less likely it will be accurate. That is what we have told you many times here. Do you think that if you ask the same question many times we are going to change our answer?

 

You have a device that is not recommended to do this. If you go very slow it will work. We have recommended that you switch to a DAQ card that has two high speed counters for a QUAD encoder setup. It will do all fo the hard work for you and it has timers that are in the MHz range so you do not need to worry about missing counts when the system is moving. It also has the calibration built in.

Tim
GHSP
0 Kudos
Message 12 of 41
(2,113 Views)

I think the OP understands he should be using a counter card, he's not asking what would be best, just how to use his limited resources in this emergency situation.

 

OP: You can do this but it will be something of a pain. If you need *continuous* positioning it will be a larger pain in the butt, but for "A to B" measurements where you just need to know where it wound up it won't be too hard.

 

Do some research on quadrature encoding. That will tell you what you need to know about how to interpret the signals. As far as LabVIEW goes, you'll need to just take a measurement at the highest speed you can on the analog channels, then convert manually. As far as I know there isn't any solid reference code on this, as like everyone else said you're using the wrong tool for the job, so you're gonna have to McGuyver it a little to make it do what you want.

 

Anyway, I think your supply is 5V, so your signals will be 0 or 5 V, with some noise. I'd take a sample set, then start at sample n=0 and work my way forward. If you see one line change state (i.e., it crosses 2.5V in either direction), increment a counter. If the next line changes state, increment it again; if the same line changes state, decrement the counter. Once you understand how quadrature counting works this should make sense. There are a million articles on this so I won't re-explain it here, but that's what you're going to have to do.

 

This should be pretty straightforward. Use the Example Finder (Help-Find Examples) to get started with analog acquisition, then you'll just have to figure out the code to interpret it. I'd recommend creating a chart of dummy values that you can use to test your decoding logic, that way you don't have to physically spin anything. If you know you should be seeing exactly 300 counts for a given set of quadrature inputs, you can run that sample code through your logic to see if you get 300 counts on the nose.

0 Kudos
Message 13 of 41
(2,105 Views)

Hi all, 

 

I've improved my understanding about quadrature encoding, and now I'm able to get some angles, but just in one direction. 

Now, i need to do the control aver the A and B phases together in order to get angles in both directions.

Currently what i did is to put a threeshold just to remove some noise from the analog voltage input, then I have 2 signals (A and B phase, but if needed even Z phase) composed just by 1 and 0.

So, I check the A signal and if this i greater than 0 I go to increment a couter because that means that it've found an edge.

Now, I need to do the control over which direction I gonna rotate the wheel.

 

Do you have any suggestions? 

 

Thanks for your time and your support.

0 Kudos
Message 14 of 41
(2,068 Views)

@valiora wrote:

I've improved my understanding about quadrature encoding...

 

So, I check the A signal and if this i greater than 0 I go to increment a counter


Apparently, you haven't improved your understanding *enough*.  Whether to increment or decrement depends on both the A & B signal.  There are 4 quadrature states.  From any state there are legal transitions to 2 others, depending on motion direction.  Positive motion will cycle through the 4 states in one sequence while negative motion will cycle through the same states in the reverse sequence.

 

Here's some more info to move you along further.

 

 

-Kevin P

 

 

 

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 15 of 41
(2,063 Views)

I agree, I don't think you have fully understood quadrature. You unfortunately will absolutely have to understand it to be able to make this system work given your limitations.

 

If you're at FF (A and B state) and move to FT, increment. From there, if you move to TT, increment again. From there, if you move to TF, increment again, then FF to increment yet again.

 

Quadrature encoding uses the following pattern:

 

FF

FT

TT

TF

FF (repeats)

 

Going "down" the list should increment your counter. Going "up" the list should decrement your counter. Check every sample state and remember the previous sample state using a shift register and you can count things. Once you have something semi-working, upload your code (save for no later than 2016 if possible, to make sure everyone can see it) and we can try to help you debug.

 

I think I would start by converting your waveform from analog into digital. Once that plot looks good, then try decoding it. Split up the task at hand into smaller and smaller parts until you can solve each part.

Message 16 of 41
(2,055 Views)

Ok, that sounds good.

 

Currently, to convert data from analogue to digital, I'm keeping a comparison with a threshold. After I convert the boolean values to double values.

From there, to merge A and B information into just one, I decided to multiply 2*A Phase to get a sum between A and B values. 

So, for instance, I'll receive 

FF --> 0

FT --> 1

TT --> 3

TF --> 2.

 

Using shift register I can track the current and previous iterations, but now could someone suggest me a way to do the multiple control? 

Because now I understood (I hope so) what quadrature means, but I don't know to do the multiple comparisons. 

If I have 0->1 decrement, if 0->2 increment, if 0->3 nothing.. that's the way how working, I guess.

 

Your help would be a lot appreciated.

 

 

0 Kudos
Message 17 of 41
(2,035 Views)

1. convert from boolean to integer rather than double.  Now you have a single integer value from 0 to 3 to represent which of the 4 quad states you are in.

2. use a 4x4 array as a lookup table.  Use the current quad state as the row #, previous quad state as column #.  The value at (row,col) is how much to add to your position counter.  With the numeric encoding you proposed, I *think* it'd look like this, but you should test it out to be sure.

 

  0   -1  +1    0

+1    0    0   -1

 -1    0    0  +1

  0  +1   -1    0

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 18 of 41
(2,030 Views)

That's a good idea, actually in the meanwhile I came with another implementation. May you have a look, just to make sure that I understood correctly how quadrature works. 

Therefore, if VI was great implemented I would need just a check for the increment or decrement. 

 

What do you think? 

 

It's 2016 LabView

0 Kudos
Message 19 of 41
(2,023 Views)

Maybe I have no totally clear how it works. 

One question, to increment or decrement I need to wait for a complete cycle? I mean.. is it not correct to increment if I see changing A+B status from 0 to 2? 

Just this changing from 0 to 2 should give me the increment? 

0 Kudos
Message 20 of 41
(2,016 Views)