On-Chip Peripherals
Two built-in peripherals that need no external components: the hardware counter for precise periodic alarms, and the watchdog for recovering a hung program. Both are configured at construction and controlled with a handful of methods.
Periodic software work belongs to a Thread — a kernel thread that sleeps between
rounds. Use the hardware counter when you need deterministic, sub-millisecond periodic execution
that doesn't depend on any thread.
Counter
One of the chip's hardware timers. The alarm frequency is the construction fact; start() arms it.
Example first
import { Counter } from '@typecad/hal';
const tick = new Counter(0, { hz: 1000 }); // instance 0, 1 kHz alarms
tick.onAlarm(() => { ticks++; }); // fires once per wrap (interrupt context)
tick.start();
// ...
tick.stop();onAlarm onAlarm(fn): void
The handler runs in interrupt context — the same ISR-safety rules as Hardware Events apply.
All methods
| Member | Description |
|---|---|
| new Counter(instance, { hz }) | The alarm frequency is the construction fact; the index selects one of the chip's declared free counters |
| onAlarm(fn) | Fires once per period — interrupt context |
| start() | Arm the alarm at the constructed frequency |
| stop() | Stop the counter |
Watchdog
A watchdog resets the chip if your program stops feeding it. The timeout is the construction fact, in milliseconds.
Example first
import { Watchdog } from '@typecad/hal';
const wdt = new Watchdog(8000); // 8 s window
wdt.enable(); // arm — full CPU reset on expiry
// somewhere in the main loop:
wdt.feed(); // keep it aliveAll methods
| Member | Description |
|---|---|
| new Watchdog(ms) | The timeout is the construction fact, in milliseconds |
| enable() | Arm — full CPU reset on expiry |
| feed() | Keep it alive — feed at least once per window |
| disable() | Not every chip supports disabling at runtime — treat as best-effort |
What isn't here
Capacitive-touch GPIOs and the on-die temperature sensor aren't supported — there is no stable
driver surface for either on the supported chips. Touch display
controllers (FT6336U and friends) are a separate feature; temperature sensing is covered by
the sensor catalog (a SENSOR. part with a temperature channel).