Syscall 2: Firmware, home

BenchChapter 10: Meshes

B75REGULATOR

The task

P0 is a PWM pin feeding the output on CH1 through R1. R2 loads it, and V1 adds a load step.

On each tick of P2, read the output on P1 and add a quarter of the error to the duty.

The error is 50 minus the reading, and a quarter is the error DIV 4.

The board

The chip of REGULATORChip u1 with 3 ports: P0 pwm out, reaching R1, C1, R2, CH1; P1 analog in, reaching R1, C1, R2, CH1; P2 timer 10 cycles.u1CHIP SC-2P0PWM OUTR1, C1, R2, CH1P1ANALOG INR1, C1, R2, CH1P2TIMER 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 10 Hz
Resistors
R1 1 kΩ, R2 4.7 kΩ, and R3 2.2 kΩ
Capacitors
C1 10 µF
Probes
CH1

Key idea

Keep the duty in B, so each tick only adds the correction to it.

Hints

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

Hint 1Show

Below 50 the error is positive and the duty grows; above 50 it shrinks.

Hint 2Show

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

Solution

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

Integral control: each tick adds a quarter of the error to the duty.

u1SC-2 standard

IN P2
IN P1
NEG
ADD 50
DIV 4
ADD B
MOV B, A
OUT P0
CYCLES
1593
at par
ENERGY
3186
at par
NODES
1
at par
INSTRUCTIONS
8
at par