Skip to content

File syn_hysteresis.h

FileList > src > syntropic > util > syn_hysteresis.h

Go to the source code of this file

Threshold comparator with hysteresis (deadband). More...

  • #include <stdbool.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_Hysteresis
Hysteresis comparator with configurable dead-band.

Public Static Functions

Type Name
void syn_hyst_init (SYN_Hysteresis * h, int32_t threshold, int32_t band, bool initial)
Initialize a hysteresis comparator.
void syn_hyst_set (SYN_Hysteresis * h, int32_t threshold, int32_t band)
Update the threshold and band at runtime.
bool syn_hyst_state (const SYN_Hysteresis * h)
Get the current output state without updating.
bool syn_hyst_update (SYN_Hysteresis * h, int32_t value)
Feed a new value and get the output state.

Detailed Description

Prevents rapid on/off cycling when a signal hovers near a threshold. Classic use cases: thermostat, battery low warning, tank level control.

Header-only — zero code size if unused.

** **

SYN_Hysteresis hyst;
syn_hyst_init(&hyst, 1000, 50, false);  // threshold=1000, band=±50

// In sensor loop:
if (syn_hyst_update(&hyst, temperature)) {
    // crossed high threshold (1050) going up
    heater_off();
} else if (!syn_hyst_state(&hyst)) {
    // crossed low threshold (950) going down
    heater_on();
}

Public Static Functions Documentation

function syn_hyst_init

Initialize a hysteresis comparator.

static inline void syn_hyst_init (
    SYN_Hysteresis * h,
    int32_t threshold,
    int32_t band,
    bool initial
) 

Parameters:

  • h Instance.
  • threshold Center threshold value.
  • band Half-width of hysteresis band. The high trip point is (threshold + band) and the low trip point is (threshold - band).
  • initial Initial output state.

function syn_hyst_set

Update the threshold and band at runtime.

static inline void syn_hyst_set (
    SYN_Hysteresis * h,
    int32_t threshold,
    int32_t band
) 

Parameters:

  • h Hysteresis instance.
  • threshold New center threshold.
  • band New half-width of dead-band.

function syn_hyst_state

Get the current output state without updating.

static inline bool syn_hyst_state (
    const SYN_Hysteresis * h
) 

Parameters:

  • h Hysteresis instance.

Returns:

Current state.


function syn_hyst_update

Feed a new value and get the output state.

static inline bool syn_hyst_update (
    SYN_Hysteresis * h,
    int32_t value
) 

Parameters:

  • h Hysteresis instance.
  • value New input value.

Returns:

true if the value crossed the high trip point (threshold + band) while state was low, or remains above the low trip point.



The documentation for this class was generated from the following file src/syntropic/util/syn_hysteresis.h