Syscall 2: Firmware, home

BenchChapter 6: Trees

B40STEPPER

The task

V1 sends a clock to P0. On each rising edge, raise the duty on P1 by 25 percent.

After 100 percent, the next edge brings it back to 0.

The board

The chip of STEPPERChip u1 with 2 ports: P0 digital in, reaching V1, CH1; P1 pwm out, reaching R1, C1, CH2.u1CHIP SC-2P0DIGITAL INV1, CH1P1PWM OUTR1, C1, CH2
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 square at 125 Hz
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1 and CH2

Key idea

Wait for P0 to fall, then for it to rise. That is one edge.

Hints

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

Hint 1Show

B keeps the duty from edge to edge.

Hint 2Show

ADD 25 and MOD 125 count 0, 25, 50, 75, 100, and around again.

Solution

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

Each rising edge of the clock climbs a quarter.

u1SC-2 standard

L: IN P0
JNZ L
H: IN P0
JZ H
MOV A, B
ADD 25
MOD 125
MOV B, A
OUT P1
CYCLES
800
at par
ENERGY
1600
at par
NODES
1
at par
INSTRUCTIONS
9
at par