Skip to main content
Skip table of contents

14.1.8 Average and Threshold [T-Series Datasheet]

Overview

AIN#_EF_INDEX: 5

This Average and Threshold Extended Feature will read an input a specified number of times at a specified rate, then average the readings and set a flag if the average is above a specified threshold. The T8 can also return the median and standard deviation of the readings.

Can be used with analog inputs or digital inputs.

This feature internally uses stream mode.

Configuration

To configure, write to the following registers.

AIN#_EF_CONFIG_A - Number of Samples: Number of samples to be acquired.

  • Default: 200

  • Max: 16384

AIN#_EF_CONFIG_B - Digital Override: Selects whether this AIN-EF takes samples from the default analog line or from a specified digital line.

Digital Override is not supported on the T8.

  • When set to zero, the normal AIN# will be used.

  • This is the default.

  • For example, if AIN2_EF_CONFIG_B is 0, samples are collected from AIN2 when AIN2_EF_READ_A is read.

  • When set to non-zero, sets the Modbus address of a digital IO.

  • For example, if AIN2_EF_CONFIG_B is 2001 (the address of FIO1), samples are collected from FIO1 when AIN2_EF_READ_A is read.

AIN#_EF_CONFIG_D - Scan Rate: The frequency at which samples will be collected.

  • Default: 6000

AIN#_EF_CONFIG_E - Threshold: If the computed average is above this value, then the threshold flag (AIN#_EF_READ_A) will be set.

Sample time

The maximum possible sample time is 180 ms.

Sample time is the number of samples divided by the sample frequency. For example, the period is 16.7 ms when using a scan rate of 6000 Hz and 100 samples:

100 samples / 6000 samples per second = 16.7 ms

If the signal has a known periodic component, then setting the sample time to an even multiple of the period will generally improve results.

Stream Configuration

This extended feature internally uses Stream-Burst to acquire the data set, so stream AIN configurations apply.

  • Crucially, set STREAM_RESOLUTION_INDEX between 0 and 8. Resolution index 9 is not supported in stream.

Results

For results, read the following registers.

AIN#_EF_READ_A - Threshold Flag: Returns 1.0 if the average is greater than the threshold, 0.0 if not.
AIN#_EF_READ_B - Average: The average of the collected samples.

AIN#_EF_READ_C - Median: The median of the collected samples. *T8 Only

AIN#_EF_READ_D - Standard Deviation: The standard deviation of the collected samples. *T8 Only

Only reading AIN#_EF_READ_A triggers a new measurement. Because multiple measurements are taken, a read of AIN#_EF_READ_A blocks for the length of the sample time.

Example - Analog Input

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

AIN2_EF_INDEX = 5
AIN2_EF_CONFIG_A = 100   -- 100 samples
AIN2_EF_CONFIG_B = 0     -- Use AIN2 to collect samples
AIN2_EF_CONFIG_D = 1000  -- Scan rate
AIN2_EF_CONFIG_E = 1.15  -- Threshold

Reading register AIN2_EF_READ_A returns 1.0, indicating that the average is greater than the threshold. If, instead, the threshold written to AIN2_EF_CONFIG_E was 1.25, then AIN2_EF_READ_A would then return 0.0 to indicate that the threshold was greater than the average.

Example - Digital Input

A 10 Hz sine 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. In this case, the threshold of 0.65 is a ratio. If the average of the readings is 0.65 or greater, the AIN2_EF_READ_A register should be 1.0.

AIN2_EF_INDEX = 5
AIN2_EF_CONFIG_A = 100   -- 100 samples
AIN2_EF_CONFIG_B = 2000  -- Modbus address of FIO0
AIN2_EF_CONFIG_D = 1000  -- Scan rate
AIN2_EF_CONFIG_E = 0.65  -- Threshold

Reading register AIN2_EF_READ_A returns 1.0 and the calculated average is 66%.

JavaScript errors detected

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

If this problem persists, please contact our support.