SCOPE Solution
COMPARATOR RESET
SCOPE ACT 5

Prerequisites
Unlocks
sc_a5_12_comparator_reset locked
Par power700
Par lines20
Par chips3
Objective
Build a sawtooth whose peak is set by hardware, not by the firmware.
Board Data
- Window: 96
- Pins: p0 OUT, p5 OUT, p7 OUT, p6 IN, p8 IN
- Channels: p0 ANALOG label=CH1_p0_saw
- Peripherals: DAC data=p0 label=DAC_on_p0, COUNTER in=p6 strobe=p7 reset=p5 label=COUNTER_on_p6, COMPARATOR data=p0 in=p8 thr=40 label=COMP_p0_gt_thr
Firmware Solution
; COMPARATOR RESET reference. A closed loop draws a sawtooth whose peak the hardware
; picks. The COUNTER on p6 tallies the strobes on p7; a pulse on p5 resets it. The
; firmware mirrors the count onto the DAC at p0; the COMPARATOR on p8 reads HIGH once
; p0 passes the per-case threshold. Each iteration the firmware reads the count, draws
; it, then reads the comparator: LOW means strobe the counter up one, HIGH means pulse
; the reset so the ramp collapses. The firmware never names the peak: the threshold
; lives in the comparator, so the same loop draws every case in the battery.
loop:
inp r1, p6 ; read the hardware count
mov r3, r1
mul r3, 6 ; scale the count so the ramp climbs at a visible rate
out p0, r3 ; mirror it onto the DAC (the comparator watches this pin)
inp r2, p8 ; read the comparator: HIGH once the saw cleared thr
cmp r2, 0
jne fall ; comparator HIGH: collapse the ramp
out p7, 255 ; comparator LOW: strobe the counter up one
slp 1
out p7, 0 ; release the strobe (the rising edge counted)
slp 1
jmp loop
fall:
out p5, 255 ; pulse RESET: the count drops to zero
slp 1
out p5, 0 ; release the reset
slp 1
jmp loop
Board Definition
# COMPARATOR RESET. ACT 5. SCOPE waveform board.
# TITLE COMPARATOR RESET
# OBJECTIVE Build a sawtooth whose peak is set by hardware, not by the firmware.
# A closed loop of three chips draws this trace. A COUNTER tallies the strobes the
# firmware sends and presents the count on p6; the firmware mirrors the count onto
# the DAC at p0; a COMPARATOR watches p0 and reads HIGH once it passes a per-case
# threshold. The firmware reads the comparator with inp: while it reads LOW it strobes
# the counter up one step, and the instant it reads HIGH it pulses the counter RESET,
# so the ramp collapses to zero and climbs again. The peak is the hidden threshold,
# decided by the hardware. The battery moves the threshold, so a transcript with the
# teeth baked at one height diverges on the next: only closing the loop locks all.
ID sc_a5_12_comparator_reset
WINDOW 96
DIR p0 OUT
DIR p5 OUT
DIR p7 OUT
DIR p6 IN
DIR p8 IN
PERIPH DAC data=p0 label=DAC_on_p0
PERIPH COUNTER in=p6 strobe=p7 reset=p5 label=COUNTER_on_p6
PERIPH COMPARATOR data=p0 in=p8 thr=40 label=COMP_p0_gt_thr
CHAN p0 ANALOG label=CH1_p0_saw
CASE thr=40
PAR power=700 lines=20 chips=3