Skip to content

R4: the power model reads pre-dither pixels, and dither only ever adds — 50% under-report at low brightness #4342

Closed

Description

@zackees

docs/color-pipeline-contracts.md states:

The electrical contract bounds modeled demand for each latched output frame, including upward quantization/dither choices.

It does not. calculate_unscaled_power_mW() takes the source CRGB span — pre-dither, pre-quantization — while PixelController::dither() is

return b ? fl::qadd8(b, pc.d[RO(SLOT)]) : 0;

applied before scaling. qadd8 saturates upward, so dither can only ever raise a channel above the value the limiter modelled, never lower it. This is #4156 R4's second half, stated there as "many sub-LSB emitters can dither upward together".

Measured

64 LEDs of CRGB(40, 40, 40), BINARY_DITHER, walking the full 8-frame dither cycle via advanceDitherFrame(), comparing calculate_unscaled_power_mW of the actually-latched bytes against the same function applied to the source scaled by brightness:

brightness modelled worst latched frame overshoot
255 2400 mW 2430 mW +1.25%
64 600 mW 630 mW +5.0%
16 120 mW 180 mW +50%

The absolute overshoot is roughly constant — about one output LSB per channel per LED — because e[i] = 256/s + 1 scales the offset up as brightness falls and the subsequent scale8 scales it back down. So the relative error grows without bound as brightness drops.

Why the direction matters

The power limiter's job is to lower brightness until demand fits a budget. The lower it goes, the more it under-reports. A budget tight enough to force brightness to 16 is precisely where the model is 50% optimistic, and the limiter has no reason to stop there — nothing feeds the discrepancy back.

That is the opposite of conservative, and the contract claims otherwise in as many words.

Caveats, stated rather than buried

  • The real limiter computes scale_power_for_brightness(unscaled_mW, brightness); my "modelled" column powers the brightness-scaled pixels instead. Same function, same inputs in spirit, but they can differ by rounding — the comparison is apples-to-apples between two uses of calculate_unscaled_power_mW, not a reproduction of the limiter's exact arithmetic.
  • My first probe recreated the PixelController each iteration without advancing the global dither phase, so all eight "frames" were identical and I measured +25% at brightness 16 rather than the true +50%. Advancing the phase is what found the worse frame. Recorded because the first number looked plausible.
  • One LSB per channel is small in absolute terms. Whether a reserve is worth its cost is a judgement about how tight the budget is meant to be — hence an issue rather than a patch.

Fix direction

Either charge a dither reserve in the estimate (bounded by e[i] per channel, known before encode), or narrow the contract sentence to say the bound is on pre-dither demand and that dither may exceed it by up to one output LSB per channel. The current text and the current code disagree; both are defensible, only one can be written down.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Activity

  1. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Correction: the contracts doc is normative, so there is no doc defect here

    I framed this as the document claiming something the code does not do, and said the present tense should not persist. That was wrong, and it is wrong for a reason I could have checked in one line — docs/color-pipeline-contracts.md opens with:

    These are implementation requirements, not a statement that the managed output path is already available. Phase PRs must link their actual tests and artifacts. Unimplemented requirements remain open; accepting this document does not close any implementation phase or the hardware measurement gate.

    So "the managed implementation uses two-pass streaming" and "the electrical contract bounds modeled demand ... including upward quantization/dither choices" are requirements, stated the way requirements normally are. An unimplemented one is exactly what the preamble says to expect. There is nothing to narrow and no present tense to remove.

    What survives, and it is the part worth having

    The measurements. They are unchanged and they were the point:

    Those quantify what it costs to ship managed output before the prepass exists, which is useful for ordering the remaining work. They do not describe a defect in the document.

    So read this as "requirement not yet met, here is the current exposure", not "doc and code disagree". Retitling is not needed — the titles describe the behaviour, which is accurate — but the framing in the body above is not, and I would rather say so than leave it.

    This is the third time this session I have reported a defect from the wrong layer: #4326 (looked for a guard in the wrong file), #4333 (looked for a log capture hook in log.h when it is in cstdio.h), and now reading a requirements doc as a description. The common failure is concluding from where I looked instead of checking what the thing is for.

  2. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Same correction as I have just posted on #4344, since this issue carries the same error.

    I wrote that "the contract claims otherwise in as many words", offered "narrow the contract sentence" as one of two fixes, and closed with "the current text and the current code disagree; both are defensible, only one can be written down."

    That reads docs/color-pipeline-contracts.md as a description of current behaviour. It is not, and its preamble says so:

    These are implementation requirements, not a statement that the managed output path is already available. ... Unimplemented requirements remain open; accepting this document does not close any implementation phase or the hardware measurement gate.

    The whole file is written in that voice. A requirement the code has not met yet is the document working as intended, not a disagreement between two defensible statements. So narrowing the sentence is not one of the options — it would weaken a requirement to match an implementation gap, which is the opposite of what the addendum is for.

    Which leaves the other half of my own "either/or" as the actual work: charge a dither reserve in the estimate, bounded by e[i] per channel and known before encode. That is not an invention either — the same contract section names it directly in the two-pass text:

    Evaluate solved demand ... include response inversion, current-field policy, and quantization reserve.

    So the requirement already exists and is unmet, and this issue is the measurement of what it costs while it stays that way: up to +50% under-report at brightness 16, in the direction a limiter drives you.

    The caveats in the original text still stand as written — particularly that my first probe measured +25% because it never advanced the dither phase, and that one LSB per channel is small in absolute terms. What does not stand is the suggestion that editing the doc is an equally valid outcome.

  3. zackees commented on Sep 12, 2026

    @zackees
    MemberAuthor

    Pinned the exposure in #4391, and in doing so measured a figure that does not match this issue's headline. Recording that rather than quietly asserting agreement.

    What I measure

    Brightness 16, 200-LED strip, dither off against the worst frame of a full cycle, both sides through calculate_unscaled_power_mW:

    source dither off worst frame ratio
    1 1000 1162 1.162
    8 1000 1162 1.162
    16 1162 1327 1.142
    64 1655 1818 1.098

    +16% at worst, not +50%.

    The shape is exactly as this issue describes, and it is the part that matters: the 1000 mW floor is the idle term for 200 dark LEDs, and the dither adds a near-constant ~162 mW on top, because what it does is lift channels off zero and how far barely depends on how dim the source is. So the relative error grows as the signal shrinks — a limiter pushing brightness down walks toward the worse end.

    Why the number differs, as far as I can tell

    Two things move it a lot, and I hit both:

    1. Which two quantities are compared. Powering the source and calling scale_power_for_brightness — what the real limiter does — treats the estimator's per-LED idle term differently from powering an already-scaled pixel. Done that way I get 2.4x, which is not the dither; it is the comparison. This issue's own caveat flags the same hazard, which is what made me check.
    2. The idle term's share. With 200 LEDs the idle floor is most of the draw at brightness 16, so a fixed addition on top is a small fraction of the total. A shorter strip, or a metric excluding idle, would report a larger ratio for the same physical effect.

    I do not know the strip length or source value behind the +50%, so I cannot say which of those accounts for it — only that either is sufficient. If the original probe is still around, the difference should be recoverable from those two knobs.

    What is pinned

    Two cases: that the worst dithered frame exceeds the undithered draw by more than 15% at a dim operating point, and that the ratio is larger at source 8 than at source 64 — the shape, not just the magnitude. Both fail if the dither is made to contribute nothing.

    The fix this issue points at is untouched: a quantization reserve in the estimate, which the contract names directly in the two-pass prepass text.

  4. moved this from Triage to Done in FastLED Trackeron Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions