Digital signal repeater

Digital I/O pulse repeater

This node would read the duration of a short pulse on a digital input pin. The pulse is then copied to a digital output pin after a specified delay. The delay is based on the duration of the input pulse multiplied by a number.

Inputs

  1. port…board port to read input signal from
  2. input-number…“IN” multiplier to calculate delay before outputting signal
  3. input-boolean…“H/L” High (true) or Low (false) Pulse Measure
  4. input-pulse… “UPD” Triggers new read

Outputs

  1. port…board port to write output signal to
  2. output-number…“Time” duration of input pulse
  3. output-pulse…Fires on writing complete

    Extra info: rationale, edge-cases, details

This node is intended to intercept a trigger signal from teeth on a rotating wheel and to then output the same signal after a specified delay. (In an combustion engine crank signal pulses control ignition timing. By delaying the output the spark timing can be modified.)

In the case of zero delay then the output pulse could start immediately after the inlet pulse finishes.

block

This is my guess at what the layout would look like. The pulse-in node below by robertspark/components has the main elements for the pulse measurement. Suggestions on how to scaling the delay and writing the output signal would be much appreciated.

#pragma XOD error_raise enable

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    if (!isInputDirty<input_UPD>(ctx))
        return;

    const uint8_t port = getValue<input_PORT>(ctx);
    if (!isValidDigitalPort(port)) {
        raiseError(ctx);
        return;
    }

    bool highLow = getValue<input_HU002FL>(ctx);
    uint8_t value = 0;
    if (highLow == 1)
    {
        value = 1;
    }
    else {
        value = 0;
    }

    bool mSecs = getValue<input_mU002Fu>(ctx);
    auto multi = 0.0;
    if (mSecs == 1)
    {
        multi = 0.001;
    }
    else {
        multi = 1.0;
    }

    emitValue<output_TIME>(ctx, pulseIn(port, value) * multi);
    emitValue<output_DONE>(ctx, 1);
}