Syscall 2: Firmware, home

BenchChapter 9: Special nodes

B72HICCUP

The task

P0 switches Q1, which runs current from the supply through R2 and the sense resistor R3.

P1 reads the sense voltage on CH1. The supply on CH2 surges now and then.

Keep Q1 on. If a tick of P2 reads over 40, turn it off for 5 ticks, then try again.

The board

The chip of HICCUPChip u1 with 3 ports: P0 digital out, reaching R1, Q1; P1 analog in, reaching R3, Q1, CH1; P2 timer 10 cycles.u1CHIP SC-2P0DIGITAL OUTR1, Q1P1ANALOG INR3, Q1, CH1P2TIMER 10 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes.
Sources
V1 3 V and V2 3 V square at 25 Hz
Resistors
R1 1 kΩ, R2 47 Ω, and R3 47 Ω
Transistors
Q1, an NPN transistor
Probes
CH1 and CH2

Key idea

The sense voltage grows with the current: about 28 percent normally, near 58 in a surge.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

While Q1 is off no current flows, so the sense reads 0: count the off ticks, do not read.

Hint 2Show

Write 1, then loop: sleep, read, SUB 40, JL back. Over 40: write 0, sleep 5 ticks, start over.

Solution

Reveal the Full SolutionThe complete program for HICCUP. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

On until the sense passes 40, then 5 ticks off and retry.

u1SC-2 standard

ON: MOV A, 1
OUT P0
L: IN P2
IN P1
SUB 40
JL L
MOV A, 0
OUT P0
IN P2
IN P2
IN P2
IN P2
IN P2
JMP ON
CYCLES
288
at par
ENERGY
576
at par
NODES
1
at par
INSTRUCTIONS
14
at par