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.

TON Timing Diagram
Parameter Type Direction Description

IN

bool

Input

Starts the timer with a rising edge and resets it with a falling edge.

PT

Duration

Input

The preset time that must pass before the output is set.

Q

bool

Output

Becomes true if IN is true and ET has reached PT.

ET

Duration

Output

The current elapsed time. Increments up to PT while IN is active.

Common Use Case: Debouncing sensors or delaying a machine start sequence.

Full Example: Motor Start Delay
#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.

TOF Timing Diagram
Parameter Type Direction Description

IN

bool

Input

Starts the timer delay with a falling edge and resets it with a rising edge.

PT

Duration

Input

The preset time that must pass after IN falls before Q is reset.

Q

bool

Output

Remains true after IN falls until PT has elapsed.

ET

Duration

Output

The current elapsed time. Increments while IN is false until it reaches PT.

Common Use Case: Keeping a cooling fan running for a set time after a machine stops.

Full Example: Cooling Fan Control
#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.

TP Timing Diagram
Parameter Type Direction Description

IN

bool

Input

The rising edge triggers the start of the pulse.

PT

Duration

Input

The duration of the generated pulse.

Q

bool

Output

Becomes true immediately upon trigger and remains so for PT, ignoring IN.

ET

Duration

Output

The current elapsed time. Increments while Q is active until it reaches PT.

Common Use Case: Triggering a specific mechanism (e.g., a glue gun shot or ejector) that requires a guaranteed active time.

Full Example: Ejector Trigger
#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.

Clock Generator Timing Diagram
Parameter Type Direction Description

EN

bool

Input

Enables the cyclic pulse generation when true.

PT

Duration

Input

The preset time duration between generated pulses.

CLK

bool

Output

Becomes true for exactly one execution cycle every time PT elapses.

Common Use Case: Triggering periodic events, such as logging data or blinking a status indicator.

Full Example: Periodic Logging
#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.

Square Wave Generator Timing Diagram
Parameter Type Direction Description

EN

bool

Input

Enables the signal generation when true.

PTON

Duration

Input

The duration the output remains true during one cycle.

PTOFF

Duration

Input

The duration the output remains false during one cycle.

CLK

bool

Output

The oscillating signal that toggles between true and false.

Common Use Case: Creating flashing warning lights or driving reciprocating actuators.

Full Example: Warning Light
#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

  1. Instantiation: Always declare timers as member variables of your Task class (as shown in the examples above). They need to maintain internal state across cycles. Do not declare them as local variables inside Update(), or they will reset every cycle.

  2. Units: Use standard C++ literals (e.g., 100ms, 5s, 1min) for the PT (Preset Time) arguments.

  3. 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.