adapnex::core::HysteresisWithDelay

Switches a boolean output based on analog thresholds and an on‐delay filter.

Synopsis

Declared in <adapnex/core/hysteresis.h>

template<typename T>
class HysteresisWithDelay;

Description

Combines hysteresis switching with a time delay filter on both transitions. The input IN must cross and remain beyond the threshold for the duration PT before the output OUT switches state.

The block automatically adapts its logic based on the relationship between SET and RESET:

  • Direct (e.g. Cooling/High‐Alarm): If SET > RESET, OUT becomes true when IN rises above SET for PT, and false when IN falls below RESET for PT.

  • Inverse (e.g. Heating/Low‐Alarm): If SET <= RESET, OUT becomes true when IN falls below SET for PT, and false when IN rises above RESET for PT.

Hysteresis with Time Delay Diagram

Parameter Type Direction Description

IN

T

Input

The signal to evaluate.

SET

T

Input

Sets OUT to true after the PT delay.

RESET

T

Input

Resets OUT to false after the PT delay.

PT

Duration

Input

The delay duration required to confirm a state change.

OUT

bool

Output

The filtered switching result.

Common Use Case

Liquid level control in a tank with surface turbulence where splashing must not trigger false switching.

Example: Tank Refill Control

class RefillTask : public Task {
public:
    double tank_level = 0.0;
    bool valve_open = false;

private:
    HysteresisWithDelay<double> level_switch;

    void Update() override {
        // SET < RESET implies low threshold logic (refill).
        // Level must remain beyond threshold for 2 seconds (PT) to ignore waves.
        level_switch(tank_level, 10.0, 90.0, 2s, valve_open);
    }
};

Both SET > RESET and SET < RESET are allowed. The implementation adapts the comparisons accordingly.

Hysteresis blocks maintain state across cycles and must be instantiated as member variables of a task rather than locally within Update().

Member Functions

Name

Description

operator()

Function call operators

Data Members

Name

Description

IN

Input value that is evaluated.

OUT

Output that switches between true and false depending on the input value, thresholds and delay.

PT

Input duration that delays the effect of crossing the thresholds.

RESET

Input threshold that resets the output OUT to false when crossed for a duration defined by PT.

SET

Input threshold that sets the output OUT to true when crossed for a duration defined by PT.

Created with MrDocs