Skip to content

feat(v2): stabilize VBUS readout filtering#95

Merged
kawinie merged 1 commit into
mainfrom
feat/v2-readout-stability
May 17, 2026
Merged

feat(v2): stabilize VBUS readout filtering#95
kawinie merged 1 commit into
mainfrom
feat/v2-readout-stability

Conversation

@kawinie
Copy link
Copy Markdown
Collaborator

@kawinie kawinie commented May 17, 2026

Summary

The supply readout jittered under V_SENSE divider noise, and the load readout twitched downward after the output toggled on. This PR adds three layered fixes so the displayed voltage stays steady at rest and snaps cleanly on PDO transitions.

  • ADC samples are oversampled 64× per read for sqrt(N) noise reduction on uncorrelated jitter, around 300 µs loop time and negligible vs the 40 ms sensor period.
  • Filter::ema gains an optional snap threshold so deltas above the threshold (PDO step changes) bypass smoothing and replace the prior value. EMA methods now live on LoadReading/SupplyReading with their own tuned constants.
  • On OFF→ON toggle, the load EMA is seeded with the current supply value, and the first two INA226 samples are discarded so a stale conversion (latched while the FET was off, ~200 mV) does not contaminate the seed.

Also inlines the pin map into pocketpd.h (drops the PocketPDPinOut dependency) and renames evtevent in two stage handlers.

Linked issues

Hardware tested

  • HW1_3

How tested: Flashed HW1_3. Confirmed supply readout no longer jitters at rest. Toggled output OFF→ON across 5 V and 20 V profiles. Display now seeds to the supply value and converges to the load reading without the previous downward droop. PDO switching still snaps to the new voltage immediately.

Breaking change / migration

Details:

Notes

The .clang-format change adds PenaltyReturnTypeOnItsOwnLine: 1000 to keep return types on the same line as the function name. Carry-over from local config, included for consistency with how the touched files are now formatted.

Display jittered under V_SENSE divider noise and dropped after the
output toggle. ADC oversamples 64 samples per read for sqrt(N) noise
reduction. EMA gains an optional snap threshold so PDO step transitions
bypass smoothing. On OFF->ON, the load reading seeds from the supply
value and the next two INA226 samples are discarded while a fresh
conversion completes.
@kawinie kawinie marked this pull request as ready for review May 17, 2026 08:22
@kawinie kawinie requested a review from centydev May 17, 2026 08:22
@kawinie kawinie merged commit 9083568 into main May 17, 2026
1 check passed
@kawinie kawinie deleted the feat/v2-readout-stability branch May 17, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant