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: 

Incremental encoder and analog input synchronization

Solved!
Go to solution

Hi, I have incremental encoder with 360 pulses per revolution (max. 3000 rpm) attached to NI9401 and analog input connected to NI9212 (both in cDAQ-9172).My goal is measure combustion engine pV diagram. I found this document 

(http://www.ni.com/pdf/csma/us/361574a1.pdf) but unfortunately there is no example how to....

How to synchronize and connect Position and Voltage together and get array with Voltage coresponding with each degree (Position 0-360°) ?

Thank for your help and your patience Smiley Happy

 

 

0 Kudos
Message 1 of 13
(5,580 Views)
Solution
Accepted by topic author CUA

Hi CUA,

 

you already set the encoder channel A as AnalogSampleClock. Now just read 360 samples (instead of just one!) and you get a sample for each encoder pulse (or with 1 degree resolution)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(5,574 Views)

Thank you for your advice, GerdW !

I added Start Digital Edge connected to Z channel of encoder (initial value set to -360) to ensure beginning of measurement at 0° and changed to 1D Analog 1Chan 360Samp but now this array contains only 336 items. When I turn encoder slowly with my hand I see every steps form 0 to 360 degrees.

 

0 Kudos
Message 3 of 13
(5,551 Views)

Your code for data acquisition is very odd.  You want one sample for every Encoder pulse, set up the DAQmx Read for one channel, N (=360) samples, set the sampling rate to 10KHz (which has nothing to do with the rate of encoder pulses).  So every degree, you try to acquire 360 points (continuously) which, at 10KHz, will take 360/10000 = 36 ms.  So each "bunch of 360 points" comes in at about 1000/36 = (roughly) 30 Hz.  What?  Weird!

 

So how many samples do you want for every Encoder pulse?  One?  Then set Single Sample mode, and every Encoder Pulse, you'll get one sample.  Simple.  A Simple Sample.

 

Or do you want something else?

 

Bob Schor

0 Kudos
Message 4 of 13
(5,515 Views)

Hi Bob,

 

I use the same approach to measure exactly the same phenomenon:

check.png

Setting up an AI DAQmx task by configurating some AI channels with scaling, then setting an external pulse input as sample clock.

The sample rate given to DAQmxTiming IS related to the encoder pulse frequency! It has to be higher than the max expected pulse frequency - otherwise you get DAQmx errors (something in the line of "ADC not ready for new conversion").

check2.png

This is how I read the samples: I read as many samples as the encoder gives pulse per revolution!

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 13
(5,505 Views)

Hello Bob,

I agree that my code is odd, But I think that 10kHz rate was fine, when I moved encoder axis only by hand (very slow rate).

Help says that if you use an external sample clock (my case), set Rate to maximum expected rate of that clock (it will be 50hz*360pulses =18kHz in real conditions). GerdW says simillar.

Anyway, thank you.

CUA

0 Kudos
Message 6 of 13
(5,482 Views)

Thank you ,

You give me new hope 🙂

I will tray it this way and let you know...

CUA

0 Kudos
Message 7 of 13
(5,481 Views)

I stand corrected.  I didn't realize you could set the Sample Clock to a Pulse Source that was "semi-random", like an encoder pulse (I've never done this kind of sampling).  It's not intuitive (to me) what the Sampling Rate (10KHz) means in a case like this, as you aren't using the A/D's "clock" for triggering samples.  I think that is what got me confused ...

 

Bob Schor

0 Kudos
Message 8 of 13
(5,472 Views)

Hi Bob,

 

the sample rate is used to "prepare" the ADC in terms of settling rate, conversion time settings and similar.

DAQmx handles such things internally whenever you set a sampling rate (depending on device capabilities)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 13
(5,468 Views)

Hi GerdW,

I'm still not able to get all encoder posititions while shaft is running at higher speeds (50Hz). I hope that this is causing my problems with analog read.

I tested encoder outupt with logic analyser and all pulses was ok (359 rising edges per revolution) at speed of 50 Hz.

I supposed that my loops are slower that data aquisition, so I used queue to catch all data, but with same results.

Any idea why i'm loosing encoder positions  ?

Thank you !

CUA

 

0 Kudos
Message 10 of 13
(5,447 Views)