Digital Signals

Capture bounded digital edges and transmit finite, 100-nanosecond-quantized pulse waveforms.


The signal modules sit below human-scale events. trace.* records edge timing on up to three pins; pulse.* transmits a finite high/low waveform. Both use live handles and 100-nanosecond time quantization.

Capture Edges

capture is trace.open:
sda-channel is trace.watch: capture, $sda
scl-channel is trace.watch: capture, $scl

trace.arm: capture
trace.wait: capture, 1000
trace.dump: capture

trace.close: capture
set capture to nil

One trace capture can be open at a time. Add one to three pins while it is in the configuring state, then arm it. The capture completes when stopped, when its 256-edge buffer fills, or when its one-second maximum span is reached.

Trace Words

WordResultUse
trace.openHandleOpen the single capture
trace.watchIntAdd a pin; receive channel 0..2
trace.armnilClear old edges and start capture
trace.waitBoolWait interruptibly up to 60000 ms
trace.stopnilFinish an armed capture now
trace.complete?BoolTest for completed state
trace.countIntNumber of recorded edges
trace.channelIntChannel for one edge
trace.levelIntLevel after one edge
trace.delta-nsIntTime since the previous edge
trace.dumpnilPrint configuration and edges
trace.closenilRelease the capture

Inspect edges programmatically only after completion:

when trace.complete?: capture [
  repeat (trace.count: capture) as i [
    print: (text.from-int: trace.channel: capture, i)
    print: ":"
    print: (text.from-int: trace.delta-ns: capture, i)
    print: "\n"
  ]
]

The first edge’s delta is relative to the arm point; later deltas are relative to the previous captured edge. trace.wait returns false on timeout without automatically discarding the capture; use trace.stop to make partial results readable.

Transmit A Waveform

wave is pulse.open: 4, 0
pulse.add: wave, 1, 800
pulse.add: wave, 0, 450
pulse.add: wave, 1, 800

pulse.dump: wave
pulse.play: wave

pulse.close: wave
set wave to nil

One pulse output can be open at a time. idle_level and every segment level must be 0 or 1. A requested duration is quantized to 100-nanosecond ticks; pulse.add returns the actual duration so code can observe the rounding.

Pulse Words

WordResultUse
pulse.openHandleOpen a pin with idle level 0 or 1
pulse.addIntAppend a span and return actual nanoseconds
pulse.clearnilRemove all spans, keep output open
pulse.countIntNumber of spans
pulse.levelIntLevel of one span
pulse.duration-nsIntActual duration of one span
pulse.dumpnilPrint the waveform
pulse.playnilTransmit once and wait for completion
pulse.closenilReturn to idle and release the output

A waveform holds up to 256 spans and at most one second of total duration. Playback is one-shot and interruptible; use a loop for repetition. Use PWM for an ongoing periodic duty cycle and GPIO events for human-scale edges.

Trace and pulse handles are volatile. Close them and replace any top-level handle binding before save.