Self-learning holdover temperature compensation#2
Closed
peterlewis wants to merge 1 commit into
Closed
Conversation
Builds on the $PMTXTS telemetry: while GPS-locked the clock learns each oscillator's frequency error vs die temperature (binned, per-oscillator), then during a GPS-loss holdover it steers the SysTick timebase from the HSE model to cancel temperature-driven drift, and optionally trims RTC->CALR from the LSE model so the battery RTC hands over better time across a power loss. - tc_learn / tc_apply / tc_rtc config keys (all default off = stock behaviour) - steering is a Bresenham SysTick->LOAD stretch inside the tick ISR (integer only; all model maths is main-loop); origin-free HSE model so only the temperature DIFFERENCE since GPS loss is applied, and the per-edge PPS phase snap makes re-lock instantly neutral - 'tc_dump = on' over serial prints the learned coefficients as paste-ready config lines (+ a $PMTXTC sentence); pasting them back freezes the model - MODE_TEMPCOMP diagnostic display: die temp / model offset / sample count - ticks-per-ppm derived from the runtime SysTick period (no core-clock assumption) Hardware-validated on an Mk IV: the LSE model learned 18.68 ppm vs 18.9 ppm measured directly (~1%). Survived an adversarial review pass (ISR-safety, integer math, sign conventions, re-lock neutrality, off-means-identical). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
|
Superseded by mitxela#9 (draft, targets upstream). Branch kept for the clean stacked diff against pcc-firmware-proposals. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on mitxela#5 (pcc-firmware-proposals) — review that first; this PR's own diff is just the temperature-compensation feature, which consumes the
$PMTXTStelemetry mitxela#5 adds.What this adds
While GPS-locked, the clock learns how each oscillator's frequency error varies with die temperature (binned per-oscillator, weighted least-squares). During a GPS-loss holdover it then:
tc_apply— steers the SysTick display timebase from the HSE model to cancel temperature-driven drift (the dominant holdover error);tc_rtc— optionally trimsRTC->CALRfrom the LSE model, so if power is lost during an outage the battery RTC hands over far better time on the next boot.All three enables (
tc_learn/tc_apply/tc_rtc) default off — with them unset, behaviour is identical to stock.Design notes
calibrateRTCfloat precedent); the tick ISR only does an integer BresenhamSysTick->LOADstretch from three precomputed values — a true fractional-ppm rate steer with no phase steps.model(T_now) − model(T_at_loss), so the origin cancels and the per-edge phase snap makes re-lock instantly neutral. (It therefore corrects temperature-driven drift; the absolute TCXO offset at loss is its spec ~±1–2 ppm — re-lock anchoring is a possible follow-up.)tc_dump = onover serial prints the learned coefficients as paste-readyconfig.txtlines (plus a checksummed$PMTXTCsentence for host tools); pasting them back freezes the model.tc_reset = onclears it. Both are serial-only (guarded so a stray line inconfig.txtcan't fire on every reload).MODE_TEMPCOMPdiagnostic display pages die temp / model offset / sample count on the date row.calibrateRTC, which owns CALR while locked); the WPR sequence runs IRQ-off against PendSV'swrite_rtc.Status
Hardware-validated on an Mk IV — the LSE model learned 18.68 ppm vs 18.9 ppm measured directly (~1%). Builds clean (
arm-none-eabi-gcc -O3, zero warnings in changed code). Survived an adversarial review pass (ISR-safety, integer math, sign conventions, re-lock neutrality, off-means-identical). Draft pending broader holdover-steering validation on the bench.