Timers and Waveform Generators
The simplest way to do something periodically on a board — blinking an LED, polling a sensor, generating a PWM, ramping a value — is to tick a timer. NodeBlue offers three flavours, from the most flexible (and most common) to the most specialised:
- Software Timer — a generic, software-driven periodic trigger. The workhorse.
- Hardware Timer — uses a hardware peripheral; very precise but limited in count.
- Generator (Periodic) — emits a waveform (sine, triangle, sawtooth, pulse, PWM) at a given frequency.
Software Timer
A Software Timer counts in the main loop and fires its output at the configured frequency. Each fire toggles its output from 0 to 1 (or vice versa), so wiring its output to a digital pin (or to a Digital Out module) makes that pin blink. Its parameters are:
| Parameter | Description |
|---|---|
| Frequency | The toggling frequency, in Hz. Live-tunable (input 1 or via SetParam). |
| Mode | Continuous (toggle forever) or One-shot (toggle Nb Periods times then stop). |
| Nb Periods | In one-shot mode, how many periods to emit before stopping. |
| Unit | Internal time unit (Micros for fine periods, Millis for slow ones). |
| Pin | Optional — if set, the timer drives this digital pin directly. |
Its inputs let you control it at runtime:
| Input | Effect |
|---|---|
trig | Any non-zero value re-arms a one-shot timer (restart). |
freq | Sets the frequency live, in Hz. |
rept | Sets the number of periods for one-shot mode. |
The classic blinking-LED example uses a Software Timer wired into a Digital Out:
Open Examples/01-Basics/Blink in Node Blue.
Other examples in the same folder add fading, serial output, or pair the timer with other modules:
- BlinkFade — a Software Timer drives an Analog Out through a Generator to fade the LED.
- BlinkSerial — blink and print the count to the serial console.
- GenPulse and GenPWM — derive pulses or PWM from a timer.
The Frequency parameter is runtime-tunable — you can change it live from a dashboard Number or Slider widget set to SetParam. The widget's Period value type is particularly handy here: think "blink every 250 ms" and let the widget send the matching Hz.
Hardware Timer
A Hardware Timer is backed by an MCU peripheral — it produces an exact frequency with no jitter from the main loop, but you only get as many instances as your MCU has timer channels. Parameters are minimal:
| Parameter | Description |
|---|---|
| Frequency | Output frequency in Hz. |
| Pin | The pin the timer drives. |
Inputs let you set the frequency live (Freq) and enable/disable it (En).
Reach for a Hardware Timer when you need stable timing for stepper steps, audio-grade clocking, or anything else where main-loop jitter is unacceptable.
Generator (Periodic)
While the two timers above emit a square wave, a Generator (Periodic) emits a signal at a given frequency. Pick the waveform you want and the values stream out of its output:
| Type | What comes out |
|---|---|
| Triangle | A linear ramp up then down, between ±Gain. |
| PWM | Pulse-width-modulated square, duty controlled by Duty Cycle. |
| Sawtooth | A rising ramp that snaps back. |
| Sine | A sine wave between ±Gain. |
| Pulse | A short impulse once per period. |
Its parameters:
| Parameter | Description |
|---|---|
| Type | One of the waveforms above. Live (input 2). |
| Frequency | In Hz. Live (input 0). |
| Gain | Amplitude of the wave (signed). Live (input 1). |
| Duty Cycle | Used by PWM and Pulse; the fraction of the period that the output is high. Live (input 3). |
A generator's output is signed (s16), so you can feed it straight into an Analog Out (after a Range/Offset if needed) to drive an audible tone, an LED brightness sweep, or any modulated signal.
The BlinkFade2 and Blink_fade_analogout examples demonstrate this pattern.
Sync signals — driving modules from a timer
A timer's most common job isn't to blink a pin, it's to pace another module. NodeBlue exposes this through a small yellow port at the top edge of every module that supports it — the Sync input. It controls when the module is evaluated (and therefore when its output is updated):
MainLoop(the default) — run every iteration of the firmware loop, as fast as possible.InputSync— run only when one of the data inputs changes.- A wired signal — run on each tick of whatever drives that yellow port.
That wired signal is most often a timer, but anything that produces a transition will do: an Edge, a button, an external clock. To poll an ADC at 100 Hz, for instance, drop a Software Timer at 100 Hz, drag a wire from its output to the analog-input module's yellow port, and the read happens on each timer tick instead of every main-loop iteration.
Sharing one timer between several modules
You can wire the same timer into the Sync port of as many modules as you want, but on a busy canvas that quickly turns into a spaghetti. NodeBlue ships a dedicated module — Sync — for exactly this case.
Give a Sync module a name, drive its yellow port from your timer once, and every consumer simply picks that name from its own Sync parameter dropdown. No wire on the consumer side, no clutter, no risk of mixing up which timer drives which module. Adding a new consumer later is one parameter pick.
Choosing between them
A quick rule of thumb:
- Need to do something on a schedule, in code? → Software Timer.
- Need a clean, jitter-free pulse output (stepper, audio clock)? → Hardware Timer.
- Need a continuously-varying signal (ramp, sine, modulated PWM)? → Generator (Periodic).
Now let's see how to make decisions from those signals: Logic gates.