Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Aquire analog voltage synchronized with rotary encoder (NI-USB6251 / NI-USB6351 with Labwindows/CVI)

Hello community,

 

i have a common problem to solve and i'm stuck with it.

 

Problem:

I have a analog voltage signal which i want to sample synchronized to a rotary encoder. I have these signals:

        

A      _|---|__|---|__|---|__|---|__|---|__ ....   _|---|__|---|__|---|__|---|__|---|__ ....10240 pulses

B     |__|---|__|---|__|---|__|---|__|---|__ .... |__|---|__|---|__|---|__|---|__|---|__  10240 pulses

Z     ___________|---|_____________....___________|---|______________ zero index

Analog Signal ............

 

The rotary Encoder gives me 20480 pulses for one rotation.

 

When i start my measurement, i want to wait till the zero-index comes. Then i want to aquire for example 20500 samples (voltage and angle), which is a little bit more than one rotation. I also need the number of pulses counted from the first occurence of the zero-index-pulse (Z) to the next. If the counter counts correctly 20480 pulses should be counted. Otherwise there would be dirt on the encoder and i can't use the data.

 

What i achived so far:

 

Sample the analog signal with 20500 samples and use the zero-index as start-trigger. Therefore i "xor"ed the signal A and B, to have my 20480 pulses.

 

DAQmxCreateTask ("", &taskHandle);
DAQmxCreateAIVoltageChan (taskHandle, "/Dev1/ai0", "", DAQmx_Val_RSE, -1.0, 1.0, DAQmx_Val_Volts, NULL);
DAQmxRegisterDoneEvent (taskHandle, 0, DoneAquisition, NULL);
DAQmxCfgSampClkTiming (taskHandle, "/Dev1/pfi0", 5000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 20500); // pulse train
DAQmxCfgDigEdgeStartTrig (taskHandle, "/Dev1/pfi1", DAQmx_Val_Rising); // zero-index

DAQmxStartTask (taskHandle);

 

In the "DoneAquisition" Callback i save my sampled data and clean up the task.

This works so far, but now i'm stuck.

 

Question:

How can i sample 20500 samples with voltage and the corresponding angle and how can i check if 20480 pulses are counted for one rotation?

 

Thanks Christian

0 Kudos
Message 1 of 2
(3,342 Views)

I'm afraid I'm no help at all on the CVI syntax, but I can give you some ideas of what to look into.

 

1. XOR in hardware will double up your pulse rate, but you'll be susceptible to overcounting if there's any direction reversal, even just a brief oscillation at the end of a move.

   A better method is available for either board you mention, but will take some detailed configuration work.  It would involve both a change-detection-based DI task along with a position measurement mode on a Counter.

 

2. The AI task can be configured to use your pulse source (either the XOR output or the change detection event I referred to) as its sample clock, giving you 1 sample per position increment, regardless of speed as long as you don't exceed your board's sample rate limit.

 

3. A 2nd Counter can be used to count edges from your pulse source while using the Z index as its sample clock.  You get 1 sample per rev and it tells you how many pulses were seen between consecutive Z index pulses.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 2 of 2
(3,332 Views)