Syscall 2: Firmware, home

BenchChapter 12: Shared buses

B100WINCH

The task

P0 reads the winch's speed knob on CH1: 50 is stop, above reels in, below lets out.

On each tick of P3, add (reading minus 50) DIV 10 to a phase in B that wraps at 60.

P1 is high for a phase of 30 or more; P2 is the same a quarter turn ahead, phase plus 15.

The board

The chip of WINCHChip u1 with 4 ports: P0 analog in, reaching V1, CH1; P1 digital out, reaching R1, D1, CH2; P2 digital out, reaching R2, D2, CH3; P3 timer 20 cycles.u1CHIP SC-2P0ANALOG INV1, CH1P1DIGITAL OUTR1, D1, CH2P2DIGITAL OUTR2, D2, 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 3.5 V, V2 2 V square at 12.5 Hz, and V3 1 V square at 6.25 Hz
Resistors
R1 330 Ω and R2 330 Ω
LEDs
D1 green and D2 blue
Probes
CH1, CH2, and CH3

Key idea

Add 60 before MOD 60, so a backward step never leaves the phase negative.

Hints

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

Hint 1Show

Phase plus 15, MOD 60, DIV 30 gives P2.

Hint 2Show

Everything stays under 127: 59 plus 5 plus 60 is 124.

Solution

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

A phase accumulator driving two coils in quadrature.

u1SC-2 standard

IN P3
IN P0
SUB 50
DIV 10
ADD B
ADD 60
MOD 60
MOV B, A
DIV 30
OUT P1
MOV A, B
ADD 15
MOD 60
DIV 30
OUT P2
CYCLES
1186
at par
ENERGY
2372
at par
NODES
1
at par
INSTRUCTIONS
15
at par