LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get frequency of measured square wave

I have a sensor that outputs a square wave of voltage, and the quantity I'm trying to measure is given by the frequency of the square wave.  Is there a way for me to find that frequency in Labview? 

0 Kudos
Message 1 of 7
(5,176 Views)

Yes, once you have that signal into LabVIEW. Now if the square wave is a nice "logic level" signal a DIO may be used, is not so well behaved or at voltages outside normal logic, the an Analog DAQ card. Once
"in LabVIEW" (proper LabVIEW code for signal acquistion from either type of IO) there are a number of LabVIEW functions for analyzing signals for frequency, max amplitude, period (inverse of frequency), etc.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 7
(5,168 Views)

Am I correct that you are describing a waveform that alternates between to levels (let's call them High and Low) at regular, fixed intervals?  Do you have any idea about how fast it does this -- to be more precise, if it is regular, do you have an idea of the time between successive transitions from Low to High and back to Low (which should be the same as High-to-Low-to-High)?  

 

Without thinking about LabVIEW or computers, if I drew a Square Wave and wrote down some times for Low-to-High and High-to-Low, could you tell me the Frequency?

 

Your original Post doesn't make clear (to me, at least) what level of knowledge you have about signals, let alone about LabVIEW, hence the questions above.

 

Bob Schor

0 Kudos
Message 3 of 7
(5,146 Views)

Yes, I am talking about a square wave, and yes I know how to get the frequency from a plot of a square wave.  For this application I am measuring a flow rate, with the signal from the flow meter being this square wave.  The frequency of the wave changes as the flow rate changes.  I'm hoping labview can give me the frequency of the wave in real time so I can know my flow rate.  

0 Kudos
Message 4 of 7
(5,142 Views)

Hi pirata,

 

As Putnam said, once you have this into LabVIEW it shouldn't be too tricky. What sort of acquisition hardware are you connecting to your sensor and your computer? This will (partially) determine what you need to do to get your data (for example, to put on a graph, although you don't need to do this).

 

Once you have your data (perhaps as an array of voltage values) you're looking for the rate at which you cross a threshold. There are several simple ways to do this, although perhaps coding it yourself would allow you greater control over the exact method.

Here is a possible example using the Pulse Measurement VI. Note that this measures only a single pulse per call (hence the For loop and the Mean VI after it).

example.png

The left half here you probably don't care about - it's only generating a square wave (which you'd replace with your actual acquisition code, e.g. DAQmx or similar).


GCentral
Message 5 of 7
(5,136 Views)

You now need to think "tradeoffs".  As I understand it, you expect the frequency of the Square Wave to change, so you want something like "instantaneous frequency".  So the question becomes how accurately do you need to measure the transition (Low to High and/or High to Low), and how much of a time lag can you tolerate between the time you start to acquire data and the time you have "an answer"?  [The former is related to the sampling rate, the latter to the number of samples taken in a batch].

 

Bob Schor

0 Kudos
Message 6 of 7
(5,130 Views)

Hi pirata,

 

For this application I am measuring a flow rate, with the signal from the flow meter being this square wave.

Which DAQ device are you using?

Does it allow for "advanced" digital inputs with counter and frequency measurement?

Then all you need is shown in the DAQmx example VIs explaining frequency measurement…

Best regards,
GerdW


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