Bistable Latches

The Adapnex SDK provides standard bistable blocks (latches) for maintaining binary state. These blocks allow you to "set" a signal to true and "reset" it to false using separate inputs. They are modeled after the IEC 61131-3 standard.

These blocks are useful for building state machines, memory circuits, or simple Start/Stop logic where the output state must be remembered across execution cycles.

Reset Dominant Latch (RS)

The RS block is a bistable latch where the Reset input has priority.

Behavior:

  • If SET is true and RESET is false, the output Q becomes true.

  • If RESET is true, the output Q becomes false, regardless of the state of SET.

  • Dominance: If both SET and RESET are true simultaneously, Reset wins, and Q becomes false.

Parameter Type Direction Description

SET

bool

Input

Causes the output to become true.

RESET

bool

Input

Causes the output to become false. (Overrides SET).

Q

bool

Output

The current stored state of the latch.

Common Use Case: Safety-critical Start/Stop circuits. If a user presses "Start" while an "Emergency Stop" (Reset) is active, the machine must not start.

Full Example: Motor Control
#include "adapnex.h"

class MotorControlTask : public Task {
public:
    bool start_button = false; // Input (Active High)
    bool stop_button = false;  // Input (Active High)
    bool motor_cmd = false; // Output

private:
    // 1. Instantiate the latch as a member variable
    RS motor_latch;

    void Update() override {
        // 2. Update the latch state
        // If both buttons are pressed, stop_button wins (Motor stays off).
        motor_latch(start_button, stop_button, motor_cmd);
    }
};

Set Dominant Latch (SR)

The SR block is a bistable latch where the Set input has priority.

Behavior:

  • If SET is true, the output Q becomes true, regardless of the state of RESET.

  • If RESET is true and SET is false, the output Q becomes false.

  • Dominance: If both SET and RESET are true simultaneously, Set wins, and Q becomes true.

Parameter Type Direction Description

SET

bool

Input

Causes the output to become true. (Overrides RESET).

RESET

bool

Input

Causes the output to become false.

Q

bool

Output

The current stored state of the latch.

Common Use Case: Alarm systems or Fault indicators. If a fault condition (SET) is still present, the operator should not be able to clear the alarm (RESET) until the fault is resolved.

Full Example: Persisting Alarm
#include "adapnex.h"

class AlarmTask : public Task {
public:
    bool over_temperature = false; // Input: Fault condition
    bool reset_button = false; // Input: Acknowledge/Reset button
    bool alarm_active = false; // Output: Alarm light

private:
    SR alarm_latch;

    void Update() override {
        // Even if the operator holds the acknowledge button (reset_button),
        // the alarm will remain TRUE as long as over_temperature is true.
        alarm_latch(over_temperature, reset_button, alarm_active);
    }
};