« Close

Datasheets and User Guides

App Notes

Software & Driver


14.1.8 Average and Threshold


Index: 5

Average and Threshold will read an input a specified number of times at a specified rate, average the readings and set a flag if the average is above a specified threshold.  Can be used with analog inputs or digital inputs.


Requires firmware 1.0204 or later.



When the AIN#_EF_READ_A register is read the LabJack will collect the specified number of samples at the specified rate. The collected samples will then be averaged and if the average is greater than or equal to the threshold then Threshold Flag will be set.

Internally this extended feature uses Stream-Burst (stream mode with a nonzero STREAM_NUM_SCANS) to acquire the data set and thus stream rules apply:

  • Range is controlled by the normal AIN range registers.
  • Single-ended or differential is controlled by the normal AIN negative channel registers.
  • Settling time is controlled for all channels by the special stream register STREAM_SETTLING_US.
  • ResolutionIndex is controlled for all channels by the special stream register STREAM_RESOLUTION_INDEX.  The default value of 0 corresponds to ResolutionIndex=1, and only indexes 1-8 are supported (high-res Pro converter not supported in stream).



The number of samples to be collected and averaged as well as the rate at which the samples should be collected need to be specified. If the signal has a known periodic component then setting the total acquisition time to an even multiple of the period will generally improve results.

Total Acquisition Time = NumSamples / ScanRate.

Total Acquisition Time should not exceed 180 ms.

AIN#_EF_CONFIG_A: Number of samples to be acquired. (default=200, max=16384)
AIN#_EF_CONFIG_B: Digital Override - When set to zero the normal AIN# will be used. Can also be set to the modbus address of a digital IO such as 2001 for FIO1.  This means you could configure AIN3_EF for example, and take readings from AIN3_EF_READ_A, but the feature is working with FIO1 and has nothing to do with AIN3.
AIN#_EF_CONFIG_C: Reserved.
AIN#_EF_CONFIG_D: ScanRate - The frequency at which samples will be collected.
AIN#_EF_CONFIG_E: Threshold - If the computed average is above this value then the threshold flag will be set.


Result Registers:

AIN#_EF_READ_A: Threshold Flag
AIN#_EF_READ_B: Average


Example #1:

A 10 Hz sign wave with magnitude 0.1 V and DC offset of 1.2 V is connected to an analog input. A threshold value less than the expected 1.2 V average will produce a positive result.


Reading register AIN#_EF_READ_A returns 1.0, indicating that the average is greater than the threshold. If we change the threshold to 1.25 then read register AIN#_EF_READ_A returns 0.0 to indicate that the threshold is greater than the average.

Example #2:

A 10 Hz sign wave with magnitude 1.2 V and DC offset of 1.6 V is connected to FIO0. The input signal should be interpreted as high two out of three times. The threshold of 0.65 is a ratio in this case. So if the average of the readings is 0.65 or greater the READ_A register should be 1.0.

AIN#_EF_CONFIG_B = 2000 (Modbus address for FIO0)

Reading register AIN#_EF_READ_A returns 1.0 and the calculated average is 66%.