adapnex::core::SquareWaveGenerator

A cyclic signal generator that produces pulses with defined high and low durations.

Synopsis

Declared in <adapnex/core/timer.h>

class SquareWaveGenerator;

Description

When enabled (EN is true), output CLK alternates 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 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 alternates between true and false.

Common Use Case

Creating flashing warning lights or driving reciprocating actuators.

Example: Warning Light

class WarningTask : public Task {
public:
    bool fault_active = false;
    bool light_output = false;

private:
    SquareWaveGenerator blinker;

    void Update() override {
        // Flash light: 500ms ON, 500ms OFF while fault is active.
        blinker(fault_active, 500ms, 500ms, light_output);
    }
};

Generators maintain internal state across cycles and must be instantiated as member variables of a task rather than local variables within Update().

Member Functions

Name

Description

operator()

Function call operators

Data Members

Name

Description

CLK

Output that alternates between true and false according to the durations PTON and PTOFF.

EN

Input that enables the pulse generation when true.

PTOFF

Input defining the duration that the output CLK remains false during each cycle.

PTON

Input defining the duration that the output CLK remains true during each cycle.

Created with MrDocs