Syscall 2: Firmware, home

BenchChapter 7: Frames and loops

B50AVERAGER

The task

P0 reads a slow triangle wave with a fast square ripple on top. P2 ticks every 20 cycles,

half the ripple's period, so two samples in a row catch one high and one low.

On each tick, put out on P1 the average of the newest sample and the one before.

The board

The chip of AVERAGERChip 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 1 V square at 250 Hz, V2 1.5 V triangle at 12.5 Hz, and V3 2 V
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1 and CH2

Key idea

XCH swaps A and B, so B can keep the newest sample while A gets the one before.

Hints

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

Hint 1Show

A register holds no more than 127, and two samples can add up to more. Halve each one first.

Hint 2Show

The ripple's high and low cancel in the average, and the triangle is left.

Solution

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

The mean of two samples cancels the ripple.

u1SC-2 standard

IN P2
IN P0
DIV 2
XCH
ADD B
OUT P1
CYCLES
235
at par
ENERGY
470
at par
NODES
1
at par
INSTRUCTIONS
6
at par