LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous Frequency Measurement with Daqmx and Quadrature Encoder

Highlighted

I had written a vi for controlling our aircraft brake dynamometer originally with LabVIEW 5.0, using traditional NI DAQ.  The AMD K6 333 based PXI controller finally went bad, and now I am updating my application to use LabVIEW 7.0 (The latest version that our company has a license for) and DAQmx.  I successfully converted all of the control functions, with one exception.  I use a quadrature encoder on the central spinning mass, and continuously measure the frequency of the pulses on one of the encoder channels to compute the surface velocity of the spinning mass.  This method worked fine with traditional NI DAQ, but it is not working correctly with DAQmx.  I followed an example I found for continous frequency measurement with DAQmx on this site, where I set up a DAQmx task outside of a loop and then keep calling DAQmx Read (Counter 1D DBL NSamp) inside of a loop.  I tell it to read all available data, average the readings, and then run it through a formula node to compute surface velocity.  This seems to work fine for steady state readings, but goes wild while the spinning mass is CHANGING velocity.  When I accelerate or decelerate the spinning mass, the readings jump wildly (indicating a wide range of frequencies being read) from very large numbers to very small numbers, then home in on the correct number as a steady state velocity is reached.  I have tried using two methods for reading frequency, and both methods exhibit this behavior.  I have tried the low frequency with one counter method, and also the wide range frequency with two counters method.  The spinning mass will see maybe 450rpm maximum rotational velocity, and the encoder outputs 1024 pulses per revolution.

I can attach a vi with my velocity reading loop, if it will help.  Is there something that I am fundamentally missing in using DAQmx for continuously reading frequency with counters?  I am now using a PXI-6221 M series board, I believe.  Before, I was using a PXI-6040E series board for this task.  The spinning mass can remain stationary for minutes at a time, with no rotation, and can accelerate from zero RPM to the maximum, then decelerate again to zero, over the course of several minutes.  I want the vi to not error out while waiting for pulses, and also to exit cleanly and quickly if I press my stop button.

0 Kudos
Message 1 of 11
(4,478 Views)
Here are two vi's with my encoder / velocity loops in them.  The Traditional one works fine, while the DAQmx one makes wild jumps in its readings during changes in angular velocity.
0 Kudos
Message 2 of 11
(4,454 Views)
I'll simplify my question.  How do you use DAQmx to continuously count the frequency of pulses from one channel of an optical encoder?  I need to count frequencies from 0Hz to about 15KHz, and the frequency will vary between these two numbers while I am measuring it.  I am using a PXI-6221 M Series board.  Thanks!
0 Kudos
Message 3 of 11
(4,433 Views)

As I understand this you are trying to read the frequency of an quad encoder and the reading is fine as long as the quad encoder is at a steady speed but when it is changing speed you are getting random frequency values.  I looked at your code and nothing seemed to jump out at me as being wrong with it but I do have a couple suggestions to see if we can narrow down where the issue may lie.

 

If you could just try running on of the examples found in the example finder (Help»Find Examples...) specifically example Hardware Input and Output»DAQmx»Counter Measurements»Digital Frequency»Meas Dig Frequency-Buffered-Cont-High Freq 2 Ctr.vi.  And just wire the output to a waveform chart or a dial and see if you are seeing the same results there.  If that is giving expected results i would just implement your formula node and averaging into that example and save it as your code.  I have attached an image of such an implementation.

Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 4 of 11
(4,430 Views)
Thank you, I'll give that a try in the morning.  You are correct, it is just when my frequency is changing (during acceleration or deceleration of the encoder) that the DAQmx code I posted gives wild random values.  I'll post back my results in the morning.
0 Kudos
Message 5 of 11
(4,427 Views)
Well, I tried one of the examples you suggested, and have attached a screenshot of the waveform chart that I wired the output to.  You can see there are spikes in the frequency measurements.  These are small spikes, because I was only decelerating the encoder slightly.  With faster changes in rotational velocity, the spikes get bigger.  What could cause this?
0 Kudos
Message 6 of 11
(4,403 Views)
I also recorded the measured frequencies into a .txt file, from my DAQmx frequency program.  This file is from a short test where I started the encoder at a very low speed, accelerated it to a higher speed, then decelerated it again.  Each row in the file corresponds to how many frequency readings were in the buffer at that instant when the reading was made (the program reads all available data at each loop iteration).  When the encoder was rotating faster, the row has more readings in it.  At slow speed, the rows are shorter because there are fewer freqency readings in the buffer.  As you can see, there are some major jumps in the frequency readings in the rows.  Is this a problem with my vi, or should I look at the harware for the cause of this?
0 Kudos
Message 7 of 11
(4,393 Views)
Ooops, here is the file.
0 Kudos
Message 8 of 11
(4,392 Views)
While I look a little further into this over here, could you try using the example DAQmx code with your old 6040E.  Note, that to use the 6040 you will need to be running DAQmx 8.1 or earlier and should uninstall DAQmx first if you have a later version already installed.  Right now I am thinking this is an issue with the hardware and would just like to see if we can eliminate the code as a factor.
Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 9 of 11
(4,351 Views)

I know this is an old thread, but we are having a similar problem with frequency spikes on a cdaq 9178 chassis and NI9401 DIO module running DAQmx 9.02 in both SignalExpress and LabVIEW 2009.

Any resolution to this?

0 Kudos
Message 10 of 11
(3,453 Views)