fix(AS7341): AS7341 overflow, spectral coefficients and new PAR coefficients - #7
Open
Ludo-lab wants to merge 6 commits into
Open
fix(AS7341): AS7341 overflow, spectral coefficients and new PAR coefficients#7Ludo-lab wants to merge 6 commits into
Ludo-lab wants to merge 6 commits into
Conversation
get_PAR() assigned `counts * Spec_COE_n` into a uint16, which wrapped rather than saturated. Full scale is (ATIME+1)*(ASTEP+1) = 50000 counts, but the weights (12,10,11,10,10,9,7,4,1,1) push the reported word past 65535 from ~11% of that -- F1 wraps above 5461 counts. A bright reading therefore came back looking like a dark one, and since PAR was summed from those same wrapped words, PAR collapsed with them: at F1 = 5462 counts the old code reported word 8 and PAR 0.19 where the true values are 65535 (pegged) and 1573. - Compute PAR in get_PAR_raw() from the unclamped counts in a uint32 accumulator. Coefficients and operation order are otherwise untouched, so the result is bit-identical to the old one whenever nothing overflowed (checked over 100k non-overflowing vectors against the previous algorithm). - Saturate the ten 16-bit channel words at 65535 instead of wrapping. A pegged value is monotonic and obviously at the rail; a wrapped one is silently wrong. Framing and the 24-byte length of cmd 31 are unchanged -- only values differ, and only under light that used to wrap. - Add binary cmd 35 get_spec_raw: 0xA1 + 32 B + 0xF0 carrying the unscaled counts plus format/atime/astep/gain_low/gain_high/flags, so a host can normalise across exposures and detect saturation. Byte-explicit and naturally aligned, so it avoids the ESP32-default-alignment coupling that froze the cmd 33 structs. Additive: cmd 31 is untouched and pre-v1.2.0 images are unaffected. Hosts gate on cmd 33/2, since an unknown opcode hits `default:` and draws no reply at all. - Guard spec_meas.h, which was unguarded while it held only idempotent declarations and now defines a type. The ambyte side is deliberately not updated yet; cmd 31 still answers exactly as before, so deployed loggers keep working untouched. Re-runs plans/HW_CONFORMANCE.md (logged in section 7, layout in section 6). Co-Authored-By: Claude Opus 5 (1M context) <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.
creation Command 35
adjustment spec coefficients