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
SETis true andRESETis false, the outputQbecomestrue. -
If
RESETis true, the outputQbecomesfalse, regardless of the state ofSET. -
Dominance: If both
SETandRESETare true simultaneously, Reset wins, andQbecomesfalse.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
Causes the output to become |
|
|
Input |
Causes the output to become |
|
|
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.
#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
SETis true, the outputQbecomestrue, regardless of the state ofRESET. -
If
RESETis true andSETis false, the outputQbecomesfalse. -
Dominance: If both
SETandRESETare true simultaneously, Set wins, andQbecomestrue.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
Causes the output to become |
|
|
Input |
Causes the output to become |
|
|
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.
#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);
}
};