From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Angular velocity measurement in continuous mode with NI-9401 card

I have a ni cdaq-9178 chassis and SIX NI-9215 and ONE  NI-9401 and ONE NI-9237 cards. I want to measure angular velocity in continuous mode with NI-9401 card. In addition I need to measure 6 currents and 6 voltages and one force signal and synchronize all of the measurements together with the same data points and sampling rate. Now, my main question is about measuring the angular velocity in continuous mode with NI-9401 card.
As far as I know, if I want to use NI-9401 in continous mode I have to define an external clock source for it. How can I measure angular velocity with the previously mentioned settings and Card in Labview? I will give more details if needed.  

0 Kudos
Message 1 of 17
(7,522 Views)

You can use an angular position task with the NI 9401. Then, you can simply take into consideration your sample rate or the time between iterations to calculate the angular velocity. I actually looked for some examples and found two quite interesting ones that should give you a good start.

 

https://decibel.ni.com/content/docs/DOC-6834

 

https://decibel.ni.com/content/docs/DOC-11869

 

I like the first one better, but the second one can be implemented with the cDAQ-9178 and the NI 9401 only so that one might be better for you depending on your requirements.

 

You can find more information about encoder measurements here.

Camilo V.
National Instruments
0 Kudos
Message 2 of 17
(7,498 Views)

The "external" clock source can be the sample clock from your existing analog input task.

 

Do something similar to Camilo's first link where you have a known sample clock interval and you measure the distance travelled between every clock edge.  This can give good results if the encoder is fast relative to the sample clock (the margin of error on each sample is going to be ±1 encoder tick, you can mitigate this somewhat by computing a running average).

 

A Sample Clocked Buffered Frequency measurement (as discussed in chapter 5 of the user manual) might be an alternative since it will give better resolution over a wide range of frequencies.  However, there are caveats with doing this.

 

1.  The measurement only uses a single digital line (not both A and B) and so is susceptible to noise and cannot determine direction change.

2.  You need to have at least 1 encoder pulse during each sample clock interval or you will receive an error and will have to restart the task (losing synchronization with your other tasks).

 

 

Best Regards,

John Passiak
0 Kudos
Message 3 of 17
(7,488 Views)

Thanks guys.

Sorry for my late answer. Actually I tried to use both of them in the past. The second one that Camilo mentioned, works fine without error but since I have to synchronize it with different other tasks with the same sampling rate and data points, it is not useable. I tried to use Align & resample blocks and interpolation methods with it, but it was not very useful in this case because regardless of the way I do it, in that configuration, I can only get one sample at once from encoder and there is not guarantee that I can have the actual synchronized data.
But the first file looks better in terms of ability to define my desired sampling rate and samples to read. About it, my only problem is that I have to delete one of the encoder tasks. I did so, and as I stated above, I have to synchronize some voltage and current  and force tasks.  I kept the voltage task there. when I run the file by using highlight exceution, I receive the Error 20061, stating that frequency must be <= sampling rate/2. I cannot fix it by any selection of frequency & sampling rate. Would you please have a look at that to see what is the possible casue? I am already puzzeled.   

0 Kudos
Message 4 of 17
(7,286 Views)

Thanks guys.

Sorry for my late answer. Actually I tried to use both of them in the past. The second one that Camilo mentioned, works fine without error but since I have to synchronize it with different other tasks with the same sampling rate and data points, it is not useable. I tried to use Align & resample blocks and interpolation methods with it, but it was not very useful in this case because regardless of the way I do it, in that configuration, I can only get one sample at once from encoder and there is not guarantee that I can have the actual synchronized data.
But the first file looks better in terms of ability to define my desired sampling rate and samples to read. About it, my only problem is that I have to delete one of the encoder tasks. I did so, and as I stated above, I have to synchronize some voltage and current  and force tasks.  I kept the voltage task there. when I run the file by using highlight exceution, I receive the Error 20061, stating that frequency must be <= sampling rate/2. I cannot fix it by any selection of frequency & sampling rate. Would you please have a look at that to see what is the possible casue? I am already puzzeled.   

0 Kudos
Message 5 of 17
(7,286 Views)

Is there anyone who can kindly help  me out in this regard? I still don't know why I am getting that error. I attached the file and any selection I choose, it gives me the same error ( that frequency must be <= sampling rate/2).

0 Kudos
Message 6 of 17
(7,240 Views)

Hello Hamed,

 

You actually have a couple errors. The frequency one is actually from the Sawtooth Waveform.vi in sub_CalcVelovity.vi. The reason of this error is that the Sawtooth Waveform.vi is receiving zeros in the Sampling Info input while its frequency input has a 0.5 constant. The Sampling Info cluster has two elements, Fs (sampling rate) and #s (number of samples). Note that the Positions 1 control is wired to this cluster, but only to the Fs input; leaving #s unwired means that even when "frequency must be <= sampling rate/2" error is fixed by increasing Fs above 1, you will get a "The number of samples must be > 0" error.

 

I believe the error -20061 (frequency must be <= sampling rate/2) is a consequence from a previous error in the code. Right after the DAQmx Start Task.vi from the Counter Input task, you are getting error -200303. The reason for this error can be found in this article.

 

That error is also the reason for the "dummy" AI task from the example you modified; note that the two counter tasks in the original example have the AI sample clock from the dummy task as their "external clock" source, just as suggested in the article but with a counter output instead. When you modified the example you may have deleted the constant by mistake; placing it back should get rid of that error.

Camilo V.
National Instruments
0 Kudos
Message 7 of 17
(7,184 Views)

Thanks Camilo for your answer. I applied what you said and corrected my  SubVI as you said and fixed that wiring problem. but I am still receiving the same error (Error 20061 stating that frequency must be <= sampling rate/2 ). My desired sampling rate is 2000 samples/s and I set the frequency for the sawthooth function as 1000 which is equal to 2000/2 and got the same error. Even I tested smaller numbers for freqeuncy like 500,250,100,50,25,1,0.25 and still the same error is happening. what could be the possible cause and how can I fix it? please check my new modified file in the attachment. 

Thanks

0 Kudos
Message 8 of 17
(7,155 Views)

Hello Hamad,

 

The frequency must be <= sampling rate/2 error is entirely from the Sawtooth Waveform.vi and it is independent from the DAQmx Task sample rate defined in the DAQmx Timing.vi. You fixed the sample rate in the main VI but the subVI still has the same problem.

 

On the main VI, you are defining a number of 100 samples per channel on the DAQmx Read.vi. This means that the number of elements the DAQmx Read.vi will send through the Expression Node and into the subVI through the Positions 1 controls is exactly 100.

 

Then, inside the subVI, you are defining the Sawtooth Waveform.vi with a frequency of 1000 Hz but the Sampling Info input from the function is entirely defined by the number of elements in the Positions 1 control; this is, 100 elements. Since the Sampling Info cluster consists of two variables, Fs (sampling rate) and #s (number of elements), and you are defining both as 100, the Sawtooth Waveform.vi has a frequency of 1000 Hz and a sampling rate Fs = of 100 S/s; that's the root from the error.

 

To fix this, you either need to increase the number of samples per channel to a minimum value of 2000 (so that frequency <= Fs/2) or use a multiplier in Positions 1 so that the value that reaches Fs is at least that.

Camilo V.
National Instruments
0 Kudos
Message 9 of 17
(7,150 Views)

Dear Camilo V, thanks for your kind answer.

Do you think that now my file will woork properly? I did some modifications and cleared the error. But still not sure if it is going to work perfectly.

Would you please have a look at it?
By the way,  in order to do a proper velocity measuremnt, what should be my inputs for the Sawtooth waveform VI? 

what should be my offset and phase? Becasue in the exapmle it seems that I should set the according to the number of data points I have (or number of samples). Is that right?  

Thanks for your kind answers

0 Kudos
Message 10 of 17
(7,107 Views)