v-uhr

hio/nwt-gus-hi/v-uhr

Die Uhr tickt.
v-uhr
@/v-uhr
Die Uhr tickt.
AnAusboolean
Is the clock enabled, i.e. produces ticks? At the moment when set to true, starts counting from scratch.
Intervallnumber
Tick interval in seconds
Neustartpulse
Resets current count, restarts clock with new interval
v-uhr
AnAus
Intervall
Neustart
Tick
Tickpulse
Jedes Intervall tickt die Uhr.
To use the node in your project you should have the hio/nwt-gus-hi 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

node {
    TimeMs nextTrig;

    void evaluate(Context ctx) {
        TimeMs tNow = transactionTime();
        auto ival = getValue<input_Intervall>(ctx);
        if (ival < 0) ival = 0;
        TimeMs dt = ival * 1000;
        TimeMs tNext = tNow + dt;

        auto isEnabled = getValue<input_AnAus>(ctx);
        auto isRstDirty = isInputDirty<input_Neustart>(ctx);

        if (isTimedOut(ctx) && isEnabled && !isRstDirty) {
            emitValue<output_Tick>(ctx, 1);
            nextTrig = tNext;
            setTimeout(ctx, dt);
        }

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

Tabular tests

__time(ms)IntervallAnAusNeustartTick
00.1trueno-pulseno-pulse
1000.1truepulseno-pulse
1200.1trueno-pulseno-pulse
2010.1trueno-pulsepulse
2500.1trueno-pulseno-pulse
3020.1trueno-pulsepulse
3500.1falseno-pulseno-pulse
4030.1falseno-pulseno-pulse
01truepulseno-pulse
5001truepulseno-pulse
10011trueno-pulseno-pulse
15011trueno-pulsepulse
// edge case: when IVAL is 0, `clock` should constantly emit pulses
00trueno-pulsepulse
10trueno-pulsepulse
21trueno-pulsepulse
10031trueno-pulsepulse
// edge case: when IVAL is negative, behave like it's 0
0-1trueno-pulsepulse
1-1trueno-pulsepulse
21trueno-pulsepulse
10031trueno-pulsepulse