Triggers & Edge Detection
The Adapnex SDK provides standard blocks for detecting state transitions (edges) in boolean signals. These are modeled after the IEC 61131-3 standard.
These blocks are useful when an action should be performed exactly once when a signal changes state, rather than continuously while the signal remains in that state.
Rising Edge Detector (R_TRIG)
The R_TRIG block detects when a signal changes from false to true.
Behavior:
The output Q becomes true for exactly one execution cycle when the input CLK transitions from false to true.
In all other cases (steady state or falling edge), Q is false.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
The signal to monitor for a rising edge. |
|
|
Output |
Becomes |
Common Use Case: Starting a process via a push-button (so the process doesn’t restart repeatedly if the button is held down) or counting items on a conveyor.
#include "adapnex.h"
class CounterTask : public Task {
public:
bool sensor_input = false; // Input
int item_count = 0; // Output
private:
// 1. Instantiate the trigger as a member variable
R_TRIG count_trigger;
void Update() override {
// 2. Update the trigger state
count_trigger(sensor_input);
// 3. Increment only on the single cycle where pulse is true
if (count_trigger.Q) {
item_count++;
}
}
};
Falling Edge Detector (F_TRIG)
The F_TRIG block detects when a signal changes from true to false.
Behavior:
The output Q becomes true for exactly one execution cycle when the input CLK transitions from true to false.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
The signal to monitor for a falling edge. |
|
|
Output |
Becomes |
Common Use Case: Detecting when a machine has stopped, or when an object has cleared a sensor (passed through completely).
#include "adapnex.h"
class FeederTask : public Task {
public:
bool exit_sensor = false; // Input: True when part is blocking exit
bool load_next = false; // Output: Trigger to load next part
private:
F_TRIG exit_detector;
void Update() override {
// Check if the part has just left the sensor (High -> Low)
exit_detector(exit_sensor, load_next);
}
};