Timers & Signal Generators
The Adapnex SDK provides a suite of deterministic timing blocks. These classes are pure C++ but their behavior is modeled after the IEC 61131-3 standard. Developers with industrial automation experience will find the logic familiar, while benefiting from type safety and object-oriented design.
These blocks manage time delays, pulse durations and generate cyclic signals for synchronization or periodic control. They are designed to be instantiated as member variables within a Task and invoked cyclically in the Update() loop.
On-Delay Timer (TON)
The TON timer is used to delay the rising edge of a signal.
Behavior: The output Q becomes true only after the input IN has been true continuously for the duration PT. If IN goes false before PT elapses, the timer resets.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
Starts the timer with a rising edge and resets it with a falling edge. |
|
|
Input |
The preset time that must pass before the output is set. |
|
|
Output |
Becomes |
|
|
Output |
The current elapsed time. Increments up to |
Common Use Case: Debouncing sensors or delaying a machine start sequence.
#include "adapnex.h"
class MotorTask : public Task {
public:
bool start_button = false; // Input
bool motor_on = false; // Output
private:
// 1. Instantiate as the timer as a member variable.
TON delay_timer;
void Update() override {
// 2. Call the timer cyclically.
// If start_button is held for 2s, the motor turns on.
delay_timer(start_button, 2s, motor_on);
}
};
Off-Delay Timer (TOF)
The TOF timer is used to delay the falling edge of a signal.
Behavior: The output Q becomes true immediately when IN is true. When IN falls to false, Q remains true for the duration PT before turning off.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
Starts the timer delay with a falling edge and resets it with a rising edge. |
|
|
Input |
The preset time that must pass after |
|
|
Output |
Remains |
|
|
Output |
The current elapsed time. Increments while |
Common Use Case: Keeping a cooling fan running for a set time after a machine stops.
#include "adapnex.h"
class CoolingTask : public Task {
public:
bool machine_running = false; // Input
bool fan_on = false; // Output
private:
TOF off_delay;
void Update() override {
// Keep fan running for 10s after machine stops running
off_delay(machine_running, 10s, fan_on);
}
};
Pulse Timer (TP)
The TP block generates a pulse of a fixed duration, regardless of how long the input signal is active.
Behavior: As soon as IN becomes true, Q becomes true and remains so for the full duration PT, irrespective of the state of IN.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
The rising edge triggers the start of the pulse. |
|
|
Input |
The duration of the generated pulse. |
|
|
Output |
Becomes |
|
|
Output |
The current elapsed time. Increments while |
Common Use Case: Triggering a specific mechanism (e.g., a glue gun shot or ejector) that requires a guaranteed active time.
#include "adapnex.h"
class EjectorTask : public Task {
public:
bool sensor_trigger = false; // Input
bool ejector_valve = false; // Output
private:
TP pulse_gen;
void Update() override {
// Fire ejector for exactly 50ms upon trigger
pulse_gen(sensor_trigger, 50ms, ejector_valve);
}
};
Clock Generator
The ClockGenerator creates a single-cycle pulse at a defined interval.
Behavior: When enabled (EN is true), the output CLK becomes true for exactly one cycle every time the duration PT elapses.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
Enables the cyclic pulse generation when |
|
|
Input |
The preset time duration between generated pulses. |
|
|
Output |
Becomes |
Common Use Case: Triggering periodic events, such as logging data or blinking a status indicator.
#include "adapnex.h"
class LoggerTask : public Task {
public:
bool enable_logging = true; // Input
private:
ClockGenerator log_clock;
void Update() override {
// Trigger a log entry every 1 minute
log_clock(enable_logging, 1min, do_log);
if (log_clock.CLK) {
// Perform logging operation here
}
}
};
Square Wave Signal Generator
The SquareWaveGenerator produces a cyclic signal with configurable high and low durations.
Behavior: When EN is true, CLK toggles between true and false. PTON defines the high duration, and PTOFF defines the low duration.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
|
Input |
Enables the signal generation when |
|
|
Input |
The duration the output remains |
|
|
Input |
The duration the output remains |
|
|
Output |
The oscillating signal that toggles between |
Common Use Case: Creating flashing warning lights or driving reciprocating actuators.
#include "adapnex.h"
class WarningTask : public Task {
public:
bool fault_active = false; // Input
bool light_output = false; // Output
private:
SquareWaveGenerator blinker;
void Update() override {
// Flash light: 500ms ON, 500ms OFF while fault is active
blinker(fault_active, 500ms, 500ms, light_output);
}
};
Best Practices
-
Instantiation: Always declare timers as member variables of your
Taskclass (as shown in the examples above). They need to maintain internal state across cycles. Do not declare them as local variables insideUpdate(), or they will reset every cycle. -
Units: Use standard C++ literals (e.g.,
100ms,5s,1min) for thePT(Preset Time) arguments. -
Elapsed Time: If you need to know how much time has passed, you can access the public
ET(Elapsed Time) member of any timer object.