LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting Square Wave Analog Pulses per unit time

Hi,
I am somewhat new to LabView and have been experimenting with code to do the following::

- Sample a low-frequency (0 to 300 Hz) analog square wave signal. (This signal will be a pulse from a photo-interrupt optical switched external circuit creating a high pulse when interrupted.
- Want to determine the quantity: Pulses/second

I've tried using the Express VIs in the LabView version 8.5 (student ed.). These included Timing and Transition Measurements and Trigger/Gate in series with Statistics Express VIs. I understand that these VIs can be somewhat like black boxes, but I am not familiar enough with the ins-and- outs of G-code.

Using the Timing and Transition Measurement VI, I get an error stating "the signal did not cross the mid reference level enough times" when I turn down the input frequency to close to 0 Hz. We want to measure all the way down to and including 0 Hz (corresponding to a zero velocity).

We ultimately want to end up with a real-time plot of wheel speed versus time.

I have the DAQ 6009-USB Hardware.
Any help would be greatly appreciated.

> Phil

0 Kudos
Message 1 of 8
(8,660 Views)

Hello Phil,

 

In order to make a frequency measurement with the USB-6009 you will need to count the pulses and then use software timing to determine the elapsed time.  Many of the multifunction data acquisition (DAQ) cards are capable of directly measuring frequency, but for the USB-6009 the only supported counter input measurement is edge counting.

 

There is an example that demonstrates how to use the USB-6009 to count events.  Here's how you can access this example:

 

1.  Open LabVIEW.

2.  Go to Help>> Find Examples...

3.  Navigate to Hardware Input and Output>> DAQmx>> Counter Measurements>>  Count Digital Events>>  Count Digital Events.vi

 

This VI will run on the USB-6009 if you change the "Edge" control on the front panel to "Falling."

 

You can modify this example to calculate the frequency in software by using a "Get Date/Time in Seconds" VI.  Use this VI to get a timestamp before you enter the loop and then put another copy of the VI inside the loop so you can get a timestamp each iteration.  If you divide the count by the difference in these two timestamps you'll get an estimate of the frequency.  You can also use a shift registers to calculate the frequency on an iteration by iteration basis.

 

This method uses software timing so it’s not nearly as accurate as the counter input frequency tasks available on some of our other products.  This method will work, but it won't be able to measure changing frequencies very well.  I would test it out and see if the results on your computer are acceptable for your application.  If you find that they aren't accurate enough then you may want to consider getting an M Series DAQ card to implement a frequency measurement in hardware.

 

I hope this helps, and have a great night!

 

Cheers,

Brooks
0 Kudos
Message 2 of 8
(8,637 Views)
I took a look at the example, Count Digital Events, and it seems to be a counter for an incoming digital signal. The signal coming from my wheel speed sensor is an analog square wave. Is there a way to modify this example and measure pulses/unit time?
0 Kudos
Message 3 of 8
(8,631 Views)
Hi Phil,

An analog square wave is pretty much just a digital waveform at a certain amplitude. The high portion of the square wave corresponds to a digital high for a certain duration of time and the low portion of the square wave corresponds to a digital low for a certain duration of time. One thing to consider when connecting this signal to the PFI lines for the counter input  is the level of the high and the low. From the USB 6008/6009 Specifications, the low should be within the range of -0.3V to 0.8 V and the high should be within the range of 2.0V to 5.8V.

If the signal that you are measuring meets these requirements, you can use the counter on the USB-6009 and modify the example according to Brooks' suggestion. Once this is done, it may look something like the screenshot below. This modified example is functional but I would take note of all the caveats that Brooks mentioned.



Regards,
Kent
Applications Engineer


Message Edited by tnek on 03-15-2008 10:10 PM
0 Kudos
Message 4 of 8
(8,609 Views)

Hi Kent,

 

I have the same requirement to count the Frequency of the digital signals coming on the Line 0, 1, 2, 3, 4, 5, 6, 7 (Port 0 of USB 6009).

But the problem is I have to count the samples simultaneously on all lines.

I guess, I have to physically connect a wire between the Line I/P and Counter Input PFI0 (which will start from the Line number under measurement and terminate to the Counter I/P) in order to have the fequency measurement because Internal switching is not available in USB 6009. 

Can it be possible with USB 6009 as it has only one Counter I/P PFI0 and i can not be able to switch from one line to another programatically.

PWM measurement is also required.

Can I measure the frequency without counter, i know it will be not as much as accurate but this is the requirement. 

 

Please suggest any solution or render any made vi.

 

Regards,

Samriddh Sarbalhi

0 Kudos
Message 5 of 8
(7,918 Views)

Samriddh,

The USB 6009 only has one counter, so this will only work to measure the frequency of one signal.  Without a counter you will have to read the signal in and then do post processing to find the frequency.  (You can use the Timing and Transition VI.)  

 

-Christina

0 Kudos
Message 6 of 8
(7,896 Views)

Hi Christina,

 

I had made a vi in which i am measuring the frequency by having the known number of samples of the signal and then averaging out and processing the values as per frequency formula 1/t=frequency (without counter use of USB 6009).

This method is working fine for low frequencies but for high frequencies it is not showing any accurate results.

Can you provide me any readymade code.

It is known to me that i have to ignore or discard counter available in USB 6009 in order to have simultaneous measurements on different lines of 6009.

 

What about PWM Measurement?

 

Regards,

Samriddh Sarbalhi

0 Kudos
Message 7 of 8
(7,887 Views)

Hey Samriddh,

 

I believe the problem you are seeing is due to the laws of the Nyquest Theorem. If you can not sample your signal fast enough, you are likely missing counts. If I had to guess I would assume that at higher frequencies of your signal, the frequency that your code outputs is less than the actual frequency you are inputting. One way to get around this would be to sample from you device faster. Unfortunately, the 6009 is limited to 48 Ks/s. So for sampling faster frequencies, you are going to have trouble because of this limitation.

 

Out of curiosity, what is the threshold where you go from accurate frequency readings to inaccurate readings?

Hope this helps.
-Ben

WaterlooLabs
0 Kudos
Message 8 of 8
(7,873 Views)