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.
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)
Tms
EN
UPD
TICK
0
100
true
no-pulse
no-pulse
100
100
true
pulse
no-pulse
120
100
true
no-pulse
no-pulse
201
100
true
no-pulse
pulse
250
100
true
no-pulse
no-pulse
302
100
true
no-pulse
pulse
350
100
false
no-pulse
no-pulse
403
100
false
no-pulse
no-pulse
0
1000
true
pulse
no-pulse
500
1000
true
pulse
no-pulse
1001
1000
true
no-pulse
no-pulse
1501
1000
true
no-pulse
pulse
// edge case: when IVAL is 0, `clock` should constantly emit pulses
0
0
true
no-pulse
pulse
1
0
true
no-pulse
pulse
2
1000
true
no-pulse
pulse
1003
1000
true
no-pulse
pulse
// edge case: when IVAL is negative, behave like it's 0