Hysteresis Control

The Adapnex SDK provides blocks for switching boolean outputs based on analog input thresholds. These blocks implement Hysteresis, a technique crucial for preventing "chattering" (rapid, unwanted switching) when a signal fluctuates near a specific threshold.

These templates are generic and work with any comparable type (e.g., float, double, int).

Standard Hysteresis

The Hysteresis block switches an output OUT based on two defined thresholds: SET and RESET.

Behavior: 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.

    • OUT becomes false when IN falls below RESET.

  • Inverse (e.g. Heating/Low-Alarm): If SET ⇐ RESET:

    • OUT becomes true when IN falls below SET.

    • OUT becomes false when IN rises above RESET.

Hysteresis Logic Diagram
Parameter Type Direction Description

IN

template

Input

The analog signal to be evaluated.

SET

template

Input

Crossing this threshold sets OUT to true.

RESET

template

Input

Crossing this threshold resets OUT to false.

OUT

bool

Output

The switching result based on the hysteresis logic.

Common Use Case: A thermostat controlling a cooling fan. The fan turns on at 30°C and shouldn’t turn off until the temperature drops to 25°C to prevent short-cycling.

Full Example: Temperature Control (Cooling)
#include "adapnex.h"

class CoolingSystem : public Task {
public:
    float current_temp = 0.0f; // Input
    bool fan_active = false; // Output

private:
    // Declare hysteresis block for float type
    Hysteresis<float> temp_switch;

    void Update() override {
        // SET > RESET implies "High Threshold" logic.
        // Turn ON at 30.0, Turn OFF at 25.0
        temp_switch(current_temp, 30.0f, 25.0f, fan_active);
    }
};

Hysteresis With Delay

The HysteresisWithDelay block adds a time filter to the standard hysteresis logic.

Behavior: This block functions identically to the standard Hysteresis, but with an added On-Delay for both transitions. The input IN must cross and stay beyond the threshold for the duration PT before the output OUT switches state.

Hysteresis with Time Delay Diagram
Parameter Type Direction Description

IN

template

Input

The analog signal to be evaluated.

SET

template

Input

Sets OUT to true after PT delay.

RESET

template

Input

Resets OUT to false after 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. The delay ensures that splashing or waves do not trigger false refilling cycles.

Full Example: Tank Refill (Heating/Inverse Logic)
#include "adapnex.h"

class RefillTask : public Task {
public:
    double tank_level = 0.0; // Input: 0.0 to 100.0%
    bool valve_open = false; // Output

private:
    HysteresisWithDelay<double> level_switch;

    void Update() override {
        // SET < RESET implies "Low Threshold" logic (Refill).
        // Open Valve (True) when level drops <= 10%
        // Close Valve (False) when level rises >= 90%
        // Signal must be stable for 2 seconds (PT) to ignore waves.
        level_switch(tank_level, 10.0, 90.0, 2s, valve_open);
    }
};