Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

USB 6210 Measure frequency at a specific sample rate.

I am trying to measure the frequency out of an encoder at a specific sample rate.

 

I am using an encoder to measure the rotational speed of a mechanical system. The velocity of this rotating system is not 100% constant it will have some speed variation.

 

I want to be able to measure the frequency of the encoder at a specific sample rate lets say 100Hz (samples per second).  This way I can later run this data through a FFT and see what the frequency the speed variation is. This would be similar to measuring an analog signal with an A-D and setting it’s sample rate.

 

I am using LV 8.2 pro with a USB-6210 module.

 

I tried using the example – “measure digital freq. buffered cont.” but I can’t seem to control the samples per second.

 

Thanks

 

Brian

0 Kudos
Message 1 of 15
(8,468 Views)

With counter frequency (or period) measurements, the sample timing is "Implicit" because the pulse edges ARE the sampling clock.  This is simply how the hardware works so you have to live with it.

When I did apps in the past requiring an FFT on freq data I measured with a counter, I would first derive the corresponding timestamps for the variable freq pulse train, and then I'd perform some type of interpolation to calculate "virtual" frequencies at the times corresponding to my desired constant sampling rate.

Another little tip is to remove your DC offset before performing the FFT.  Simply subtracting a median value is often quite effective.

-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 15
(8,444 Views)
Hello Stewy,
 
Was reading the thread in the discussion of measuring frequency. Can you kindly, tell which VI example worked for measuring the frequency ?
0 Kudos
Message 3 of 15
(8,062 Views)

Hi Miaa,

Best that I can tell, Stewy was using a program from the LabVIEW Example Finder.  Open LabVIEW and then go to Help >> Find Examples.  Browse to Hardware Input and Output >> DAQmx >> Counter Measurements >>Digital Frequency.  He was probably using one of the continuous buffered digital frequency measurement examples that can be found in this folder like ‘Meas Dig Frequency-Buffered-Cont-High Freq 2 Ctr.VI.”

Hope this is what you were looking for.  A search on NI.com for “measure frequency” or other related terms might turn up additional examples.

Jared T.
0 Kudos
Message 4 of 15
(8,042 Views)

I don’t remember which example I used. My goal was to measure frequency at a high sample rate with the USB-6210 module. I was able to achieve this. I set the counter up to measure a frequency on an external clock edge. I used the second counter to generate a pulse train output (my sample clock @ 1000hz). I connected the output of this pulse train (counter 1digital I/O connector pin 7) to the frequency counter sample input (counter 0 digital I/0 connector pin 3). I then hooked up the pulse train I wanted to measure in this case an encoder signal to (counter 0 digital I/O connector pin 2). I am able to measure the frequency variations of the encoder at a sample rate of 1000Hz. I can then run this through an FFT and see what the frequency components are of the velocity variations the encoder is seeing when connected to a mechanical rotating device.

 

I will attach a couple screen shots of my program.

 

I hope this makes sense.

 

Stewy

Download All
0 Kudos
Message 5 of 15
(8,038 Views)

Thanks a lot Stewy for sharing that piece of information. Few questions:

1) In the worked examples of LabVIEW they define min and max value. I tried those examples and i am getting the error as attached. I have tried increasing the time out values to 2000 and still the same error , while measuring a ( 2Hz- 3KHz ) Pulse digital signal from a function generator. Kindly, explain if it is necessary to include the min/max values or not.

2) Also, since those examples were giving me error i tried your idea ( attached is the VI in LabVIEW8.5). Do we have to use PFI2 ? Cant we use regular channels like AI0 ? I am not trying to duplicate your VI ,,,instead i am trying different examples to learn  the differences and accuracy in them 🙂

3) Sample clock in your VI is primarily controlling the better resolution than the sampling of DAQ board. Am i understanding that correctly ?

My application involves a digital squarewave whose frequency needs to be calculated. The range of this frequency is ( 2Hz- 3KHz ). This frequency from the sensor takes some time ( 3 sec ) to settle to a stable value. Once this is stable it needs to be measured and plotted. I have 4 different inputs whose frequency needs to be measured one by one. After 6 sec the input frequency  varies to a different value. And have to repeat the same measuring criteria of frequency and plot them.  I am using USB 6210 as my DAQ.

Let me know if my above observation is correct ( from conceptual grounds ) and also what is the mistake i am making in the attached VI.

  

 

 

Download All
0 Kudos
Message 6 of 15
(8,011 Views)

Miaa

 

Your error is generated because your counter did not see any pulses before the timeout expired.

 

You want to use one of the counter inputs to measure your square wave signal. I suggest using Ctr/0  not AI0.

 

Yes, my example is for measuring frequency at a high sample rate. You won’t need to do this for your application.

 

I made a simple program for you to try (see attached).

 

Connect your signal to the Digital I/O terminal connector Pin-2 and you signal ground to Pin-5.

 

From the front panel of the program under “counters” select your device and counter 0. Example = Dev1/Ctr0

 

I set the timeout to 30 seconds so if the counter doesn’t see any pulses for 30 seconds it will generate an error.

 

You can find more examples under Help-Find Examples-Hardware Input and Output-Daqmx-Counter measurements-Digital Frequency.

 

Stewy

0 Kudos
Message 7 of 15
(8,005 Views)
once again many thanks for replying to my messages, i really appreciate your time. I really want to know what i am doing before i say OK i understand everything and the VI is working. I was reading through the chap 9 of 621x manual about the counters and chapter 10 about PFI's.
 
I am curious in finding out how were the following values in your VI calculated :
 
1) Rising = 10280, Falling = 10171
 
2) Values for setting up the counter:
    like low frequency with 1 counter = 10105
          high frequency with 2 counter = 10157
          high frequency with 2 counter = 10205
 
3) Is there any other DAQ board which has more counter pins. In 6210 we have  2 counters. I was thinking if there is any way we can add some hard ware and get more counters. This is the concern simply bec. with 2 counters i will be limited to measure 2 channels in one time. It will be nicer if i can measure 8 or 10 channels at a time. Kindly, suggest.....
 
 
0 Kudos
Message 8 of 15
(7,975 Views)

Miaa

 

I guess I don’t understand your application completely. The 6210 only has 2 counters so you can only measure 2 independent signals at the same time. To do this you would need to duplicate the counter setup vi’s in the program I sent you and pick the appropriate counters in the drop down boxes on the front panel ctr/0, ctr/1 and hook the signals to the proper terminals.

 

If you need a USB device with more counters you can look here

 

5 counters

http://www.measurementcomputing.com/cbicatalog/cbiproduct_new.asp?dept_id=620&pf_id=1817&mscssid=HFQ...

 

10 counters

http://www.measurementcomputing.com/cbicatalog/cbiproduct_new.asp?dept_id=620&pf_id=1818&mscssid=HFQ...

 

They say they will work with labview but I have not tried them.

 

 

Stewy

0 Kudos
Message 9 of 15
(7,971 Views)

Hello Stewy, My application is pretty straight forward electrical circuit. I have a light to frequency sensor which gives a signal with 50% duty cylcle, square wave, TTL, whose min value of frequency to be detected is 5Hz and Max value is 10KHz. The Sensor is doing a good job on detection as i can see the variation when i connect an oscilloscope at the output pin of the sensor. There are 10 identical sensors. And there are 10 physcial activities. EACH sensor detecting its own activity ( and converting the light activity to frequency ).

I want to replace the oscilloscope with Labview. And display the 10 outputs together on ONE graph, if possible. And then use the data for mathematical calculations. The VI you sent me is working when i try to check the out put one by one and using the "low freq with 1 counter option". And thanks a lot for your help but,  i am not clear on how were the values of rising and falling were calculated, and how were the counter values likes "low freq with 1 counter = 10105" were calculated ??

I also tried 2 sensors and its working but then again how were the values calculated , and is it possible to display 10 outputs( of sensor) using DAQ6210 ? 

0 Kudos
Message 10 of 15
(7,945 Views)