Syscall 2: Firmware, home

BenchChapter 7: Frames and loops

B51SLEW

The task

P0 reads a square wave that jumps between 0 and 5 volts.

Follow it on CH2 through the PWM pin P1, but move at most 10 percent per tick of P2.

The jumps become ramps.

The board

The chip of SLEWChip u1 with 3 ports: P0 analog in, reaching V1, CH1; P1 pwm out, reaching R1, C1, CH2; P2 timer 10 cycles.u1CHIP SC-2P0ANALOG INV1, CH1P1PWM OUTR1, C1, CH2P2TIMER 10 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 square at 20 Hz
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1 and CH2

Key idea

B holds the duty you put out last.

Hints

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

Hint 1Show

Compare the reading with B: step up by 10 when it is higher and down by 10 when it is lower.

Hint 2Show

When they match, the duty stays where it is.

Solution

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

Follow the input at no more than 10 percent a tick.

u1SC-2 standard

L: IN P2
IN P0
SUB B
JZ L
JG UP
MOV A, B
SUB 10
JMP S
UP: MOV A, B
ADD 10
S: MOV B, A
OUT P1
CYCLES
617
at par
ENERGY
1234
at par
NODES
1
at par
INSTRUCTIONS
12
at par