Syscall 2: Firmware, home

BenchChapter 11: Capstones

B90PULSE METER

The task

P0 reads pulses of different lengths on CH1. Sample it on each tick of P2.

When a pulse ends, set the duty of P1 to 8 times the number of ticks it read high.

Hold that duty until the next pulse ends. R1 and C1 smooth it onto CH2.

The board

The chip of PULSE METERChip u1 with 3 ports: P0 digital in, reaching V1, CH1; P1 pwm out, reaching R1, C1, CH2; P2 timer 20 cycles.u1CHIP SC-2P0DIGITAL 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 square at 25 Hz and V2 1.2 V square at 62.5 Hz
Resistors
R1 10 kΩ
Capacitors
C1 1 µF
Probes
CH1 and CH2

Key idea

Count the high samples in B, as in STRETCH.

Hints

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

Hint 1Show

The first low sample after a count ends the pulse: write, then clear the count.

Hint 2Show

A low sample with the count at zero needs nothing at all.

Solution

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

Count while high, write 8 times the count when it falls.

u1SC-2 standard

L: IN P2
IN P0
JZ E
MOV A, B
ADD 1
MOV B, A
JMP L
E: MOV A, B
JZ L
MUL 8
OUT P1
MOV A, 0
MOV B, A
CYCLES
474
at par
ENERGY
948
at par
NODES
1
at par
INSTRUCTIONS
13
at par