Syscall 2: Firmware, home

BenchChapter 9: Special nodes

B66SPEED TRAP

The task

P0 and P1 read two light gates on CH1 and CH2. A car trips P0 first, then P1.

Sample both on each tick of P3. Count from the tick after P0 first reads high.

The count ends on the first tick P1 reads high, that tick included. Set P2 to 10 times it.

Hold it until the next car. A car has gone once P0 reads low again.

The board

The chip of SPEED TRAPChip u1 with 4 ports: P0 digital in, reaching V1, CH1; P1 digital in, reaching V3, CH2; P2 pwm out, reaching R1, C1, CH3; P3 timer 20 cycles.u1CHIP SC-2P0DIGITAL INV1, CH1P1DIGITAL INV3, CH2P2PWM OUTR1, C1, CH3P3TIMER 20 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes. On a narrow screen, scroll the board sideways to see all of it.
Sources
V1 5 V, V2 5 V square at 25 Hz, V3 2 V, V4 2 V square at 25 Hz, and V5 1.2 V square at 27.78 Hz
Resistors
R1 10 kΩ
Capacitors
C1 1 µF
Probes
CH1, CH2, and CH3

Key idea

Wait for P0 to read low first, so one car is never timed twice.

Hints

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

Hint 1Show

Count in tens: add 10 to B on every tick until P1 reads high.

Hint 2Show

After the wait for low, A is 0: MOV B, A clears the count for free.

Solution

Reveal the Full SolutionThe complete program for SPEED TRAP. 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.

Time between two gates, counted in ticks.

u1SC-2 standard

W: IN P3
IN P0
JNZ W
MOV B, A
A1: IN P3
IN P0
JZ A1
T: IN P3
MOV A, B
ADD 10
MOV B, A
IN P1
JZ T
MOV A, B
OUT P2
CYCLES
310
at par
ENERGY
620
at par
NODES
1
at par
INSTRUCTIONS
15
at par