Skip to main content
Skip table of contents

Measuring Frequency/Pulses (App Note)

Pulse signals are a common type of sensor output. The quantity of interest is often described by the total number of pulses that occur, or the number of pulses that occur per second (the pulse frequency). For example, Some flowmeters have pulse outputs: a pulse indicates a certain flow quantity and the number of pulses per second is the flow rate. RPM sensors typically output a certain number of pulses per revolution.

Below are some common strategies to measure pulse signals using LabJack hardware.

LabJack Counter

All LabJack devices have at least one counter. A counter simply increments an internal register whenever an external pulse is detected. By looking at the change in count over a change in time, frequency can be calculated. For example:

Frequency = (CurrentCount - PreviousCount) / (CurrentTimestamp - PreviousTimestamp)

See the counter documentation in your device datasheet for further information. On T-Series devices we call timer and counter features DIO_EF:

Counter frequency measurement error

When using a counter to measure frequency, your measurement accuracy depends on how well you can associate a count value to some timestamp. A common technique is to retrieve the current count from the LabJack hardware and when the read is complete note the current millisecond timestamp from the application that is taking the LabJack measurements. In this case, jitter occurs due to any inconsistency in the time between the counter read and timestamp read, and it is commonly around ±1 ms when using built in timing functions on Windows/Linux/macOS. If this jitter is estimated as ±1 ms it could cause an error of ±2 ms because two separate readings are required to find the number of counts in a time period. If a measurement is done every 1000 ms, the jitter could cause up to ±2 ms of error out of 1000 ms total, or 0.2% error. If you count for 10 seconds between readings, this error would decrease to about 0.02% error. Below are some solutions to further reduce error:

  1. All LabJack hardware besides the U12 can reduce this time jitter error by getting a timestamp from hardware rather than your computer. The timestamp can be retrieved in the same function call as the counter reading, reducing the timing jitter to less than 10 microseconds. See the system timer documentation in your device datasheet for more information:

  2. Rather than reading the counter using software timed command/response mode, you can read the timer in stream mode. Stream mode is hardware timed at a specified interval. For example, if you stream the counter at 100 scans/second, then you know that every 100th scan is exactly 1 second apart (to the accuracy of the LabJack’s clock). See the stream and/or communications documentation in your device datasheet for further information:

LabJack Timer Feature

All LabJack devices besides the U12 support timers that can be used to measure frequency in firmware. Since these features are timed using LabJack timing resources in firmware, they are often more accurate than using a counter to measure frequency. See the timer feature documentation in your device datasheet for further information. On T-Series devices we call timer and counter features DIO_EF:

Timing Individual Pulses

It is sometimes possible to monitor the digital I/O or analog input state directly and calculate information about the signal frequency and/or pulse rate. This is generally the least reliable way to monitor pulses on digital I/O. You would only see a pulse occur if the edge transitions occur much slower than the channel sampling rate, so timing individual pulses typically only works with low signal frequencies. We recommend using a LabJack counter or timer feature whenever possible.

Command response timing is inherently inconsistent and results in lower sampling rates compared to stream mode. Stream mode is usually the better option to time individual pulses. All LabJack hardware supports stream mode acquisition. See the stream and/or communications documentation in your device datasheet for further information:

Advanced Analog Measurements

Stream mode, and particularly stream burst modes, are often the best way to analyze analog signals whose characteristics cannot be properly captured using a digital I/O feature. The high sampling rates, high sampling interval accuracy, and discrete values captured using stream burst can be leveraged for calculations such as FFT, finding signal midpoints, frequency, signal peaks, RMS values, etc.

Special note about the U12

The LabJack U12 does not have timers, so the best option for pulse timing is to retrieve analog or digital inputs in stream/burst mode and find the time in software. The smallest time resolution available on the U12 is from a burst of a single analog input. In this case the sampling rate can be up to 8192 samples/second, meaning that the time resolution is about 122 us.

Frequency To Voltage Converter

There are various commercial signal conditioning devices available to convert frequency to an analog voltage signal. It is typically easy to measure voltage from these converters with an analog input on a LabJack.

AutomationDirect is one source for signal conditioning modules, but other common electronic distributors/manufacturers such as Digikey, Mouser, and Omega also likely have frequency to voltage conditioners.

For a lower level solution, consider the LM2917.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.