Syscall 2: Firmware, home

BenchChapter 8: Scarcity

B58SOLENOID

The task

P1 drives a solenoid through Q1. Full current pulls it in; far less holds it there.

P0 is the enable on CH1. Sample it on each tick of P2.

When it goes high, set P1 to 100 for two ticks, then to 30 while it stays high; when low, 0.

D1 carries the coil current while Q1 is off. CH2 dips as the current grows.

The board

The chip of SOLENOIDChip u1 with 3 ports: P0 digital in, reaching V1, CH1; P1 pwm out, reaching R1, Q1; P2 timer 20 cycles.u1CHIP SC-2P0DIGITAL INV1, CH1P1PWM OUTR1, Q1P2TIMER 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 12.5 Hz, and V3 5 V
Resistors
R1 100 Ω and R2 47 Ω
Inductors
L1 100 mH
Diodes
D1, a diode
Transistors
Q1, an N channel MOSFET
Probes
CH1 and CH2

Key idea

Wait for the enable on ticks: a loop of IN P2, IN P0, and JZ back to the top of it.

Hints

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

Hint 1Show

The two ticks at 100 are two sleeps in a row, whatever the enable does meanwhile.

Hint 2Show

Write 100, sleep twice, write 30, then loop on ticks until the enable reads 0, and write 0.

Solution

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

Full current to pull in, then a hold duty, off with the enable.

u1SC-2 standard

OFF: MOV A, 0
OUT P1
W: IN P2
IN P0
JZ W
MOV A, 100
OUT P1
IN P2
IN P2
MOV A, 30
OUT P1
H: IN P2
IN P0
JNZ H
CYCLES
242
at par
ENERGY
484
at par
NODES
1
at par
INSTRUCTIONS
14
at par