Syscall 2: Firmware, home

BenchChapter 11: Capstones

B87DUTY METER

The task

P0 reads a digital signal on CH1. IN P2 waits for a tick and returns the ticks so far.

Sample P0 on each tick and count the high samples in windows of 8 ticks.

When the tick count MOD 8 is 0, the window ends: write 12 times its count, then start at 0.

The board

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

Key idea

The sample on the window's last tick counts too.

Hints

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

Hint 1Show

The count is at most 8, so 12 times it never passes 96.

Hint 2Show

Keep the count in B. After the write, MOV A, 0 and MOV B, A clear it.

Solution

Reveal the Full SolutionThe complete program for DUTY 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 the high samples of each 8 tick window.

u1SC-2 standard

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