Repository navigation
feat(sim): count samples filed under the wrong ADC channel - #170
Merged
Merged
Conversation
The firmware files the conversions as V1 I1 V2 I2 V3 I3 in turn and writes ADMUX at the end of its ISR, for the conversion after next. When the ISR runs past the start of that conversion, it runs on the previous channel and its sample is filed under the wrong one. grid_sim now follows the firmware's sequence and counts those conversions (ignoring the first two rounds after the ADC starts), and the scenarios expect none: `expect misfiled_samples 0`. Measured on the surplus-step scenario: dev before #163 misfiled 10 samples (one per ISR overrun, at datalog time), dev with #163 none. It is a more precise check than the overrun count: of #162's 1928 overruns, only 14 misfiled a sample. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
The grid simulation now counts ADC samples filed under the wrong channel, and the scenarios expect none.
Why
The firmware files conversions as V1 I1 V2 I2 V3 I3 in turn. It writes ADMUX at the end of its ISR, for the conversion after next. When an ISR runs past the start of that conversion, the conversion runs on the previous channel, and its result is filed under the wrong one. For example, a V2 sample is used as I2.
No sample is lost: the next ISR starts straight away and reads the pending result. So
minSampleSets/MCstays at 32, and the datalog cannot show the problem.How
grid_simfollows the firmware's sequence and flags every conversion whose channel is not the one the firmware files it under. The first two rounds after the ADC starts are ignored while ADMUX's two-conversion pipeline fills up. The three scenarios now includeexpect misfiled_samples 0.Measured (surplus-step scenario, 60 s)
devbefore #163devwith #163This is more precise than the overrun count, which stays in place as an early warning. Most of #162's long ISR calls pass 1664 cycles by only a little, and ADMUX is still written in time.
Testing
make checkon currentdev(with perf: integer energy bucket, no float or division in the ADC ISR #163): 30/30 expectations pass, 0 misfiled samples.🤖 Generated with Claude Code