Practice

Feeder Power Path

The substation monitor samples voltage and current on all three phases of feeder 7 and computes instantaneous power, p = va*ia + vb*ib + vc*ic, once per clock. The block in your editor has done that job for four years at 25 MHz without a complaint. Then the protection team asked for faster disturbance capture and the platform clock moved to 100 MHz. The timing report turned red: three multiplies and two adds no longer fit in a single cycle.

The catch is downstream. The disturbance recorder lines p up against the raw sample stream, and it assumes p arrives exactly two cycles after the samples it came from. That number is hard-coded.

Your task: keep computing p = va*ia + vb*ib + vc*ic, one result per clock. Deliver each result exactly 2 cycles after its samples. Split the math into two pipeline stages, so the longest path between registers gets shorter. The 2-cycle contract must hold exactly.

Interface

PortDirectionTypeDescription
clkin1 bitClock
rstin1 bitSynchronous reset (active high)
vain8-bit vectorPhase A voltage sample (unsigned)
iain8-bit vectorPhase A current sample (unsigned)
vbin8-bit vectorPhase B voltage sample (unsigned)
ibin8-bit vectorPhase B current sample (unsigned)
vcin8-bit vectorPhase C voltage sample (unsigned)
icin8-bit vectorPhase C current sample (unsigned)
pout18-bit vectorva*ia + vb*ib + vc*ic (registered)

Behavior

LATENCY

exactly two cycles. A sample set on the inputs during one cycle shows on p two cycles later, not one, not three. The data passes two rising edges: the one that captures it, then the output register's.

  • Throughput is one result per cycle: a new sample set arrives at every edge and every result must appear, in order, with no gaps
  • rst = 1 at a clock edge clears every pipeline stage, and results already in flight are discarded
  • After a reset edge, p is 0 during the following cycle and the one after it
  • All arithmetic is unsigned; the 18-bit output cannot overflow (maximum value is 3 * 255 * 255 = 195075)

What the bench checks

  • The testbench checks p on every cycle, including the two warm-up cycles after each reset
  • A reference pipeline requires each three-phase sum to appear exactly two clocks after its inputs
  • A full-rate stream covers zero, maximum, mixed, asymmetric, and equal-sum sample sets with a new set every clock
  • Reset mid-stream must clear the output, discard the sample in flight, and leave both stages clean during refill
  • After refill, directed products must resume at the same exact latency without dropped or duplicated results

Constraints

TIMING

everything is synchronous to clk and p is registered.

SCOPE

this models the power arithmetic pipeline only. The samplers, the disturbance recorder, and the feeder hardware are out of scope.

The template contains the shipped single-cycle implementation: restructure it into two pipeline stages. The latency contract is exact, so a design with one or three stages fails the bench no matter how short its longest path is. Measured with this platform's synthesis flow, the shipped code runs 33 logic levels on the longest path. So does the version that just bolts a register onto the end. The properly balanced two-stage version runs 24. The bench cannot measure levels, only the contract, so where you put the cut is on your honor: put it where it does the work.

Do not add ports.

Loading editor...

Click Run to execute your code. Output will appear here.