Syscall 2: Firmware, home

BenchChapter 11: Capstones

B81LOW PASS

The task

P0 reads a slow swing with a coarse ripple on CH1. P1 is a fast PWM pin, filtered onto CH2.

Keep a running value in B. On each tick of P2, move it a quarter of the way to the reading.

Write the running value as the duty.

The board

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

Key idea

A quarter of the way is the reading minus the value, DIV 4, added to the value.

Hints

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

Hint 1Show

The ripple changes every two ticks, so each step only follows it a little.

Hint 2Show

IN P2, IN P0, SUB B, DIV 4, ADD B, MOV B, A, OUT P1.

Solution

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

An exponential average, a quarter of the way each tick.

u1SC-2 standard

IN P2
IN P0
SUB B
DIV 4
ADD B
MOV B, A
OUT P1
CYCLES
1394
at par
ENERGY
2788
at par
NODES
1
at par
INSTRUCTIONS
7
at par