ticker(milli)

koadrobot/arduino/ticker(milli)

Outputs pulses at regular intervals in milliseconds.
ticker(milli)
@/ticker(milli)
Outputs pulses at regular intervals in milliseconds.
ENboolean
Enabled or not. If set to `false` pulses on `UPD` do not change the output value. Effictively that means the timer is paused. Set to `true` again to continue time counting.
Tmsnumber
Tick interval in millisec.
UPDpulse
Triggers the time value update.
ticker(milli)
TICK
EN
Tms
UPD
TICKpulse
Pulses on each time interval end
To use the node in your project you should have the koadrobot/arduino library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State 
{
  TimeMs nextTrig;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) 
{
    State* state = getState(ctx);
 
    TimeMs tNow = transactionTime();
    TimeMs tms = getValue<input_Tms>(ctx);
    
    if (tms < 0) tms = 0;
    TimeMs tNext = tNow + tms;

    auto isEnabled = getValue<input_EN>(ctx);
    auto isRstDirty = isInputDirty<input_UPD>(ctx);

    if (isTimedOut(ctx) && isEnabled && !isRstDirty) 
    {
        emitValue<output_TICK>(ctx, 1);
        state->nextTrig = tNext;
        setTimeout(ctx, tms);
    }

    if (isRstDirty || isEnabled) 
    {
        // Handle enable/disable/reset
        if (!isEnabled) 
        {
            // Disable timeout loop on zero IVAL or explicit false on EN
            state->nextTrig = 0;
            clearTimeout(ctx);
        } 
        else if (state->nextTrig < tNow || state->nextTrig > tNext) 
        {
            // Start timeout from scratch
            state->nextTrig = tNext;
            setTimeout(ctx, tms);
        }
    }
}

Tabular tests

__time(ms)TmsENUPDTICK
0100trueno-pulseno-pulse
100100truepulseno-pulse
120100trueno-pulseno-pulse
201100trueno-pulsepulse
250100trueno-pulseno-pulse
302100trueno-pulsepulse
350100falseno-pulseno-pulse
403100falseno-pulseno-pulse
01000truepulseno-pulse
5001000truepulseno-pulse
10011000trueno-pulseno-pulse
15011000trueno-pulsepulse
// edge case: when IVAL is 0, `clock` should constantly emit pulses
00trueno-pulsepulse
10trueno-pulsepulse
21000trueno-pulsepulse
10031000trueno-pulsepulse
// edge case: when IVAL is negative, behave like it's 0
0-1000trueno-pulsepulse
1-1000trueno-pulsepulse
21000trueno-pulsepulse
10031000trueno-pulsepulse