Syscall 2: Firmware, home

BenchChapter 7: Frames and loops

B54PEAK

The task

A peak meter jumps up with its input and sinks back slowly. P0 reads a sine wave.

On each tick of P2, lower the held level by 3 percent, then raise it to the reading

if the reading is higher. Put the held level out on P1.

The board

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

Key idea

B holds the level between ticks.

Hints

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

Hint 1Show

Subtract 3 from the held level first, then compare it with the new reading.

Hint 2Show

Keep whichever is higher, store it in B, and write it out.

Solution

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

Jump up with the input, sink 3 percent a tick.

u1SC-2 standard

IN P2
MOV A, B
SUB 3
MOV B, A
IN P0
SUB B
JL K
ADD B
MOV B, A
K: MOV A, B
OUT P1
CYCLES
572
at par
ENERGY
1144
at par
NODES
1
at par
INSTRUCTIONS
11
at par