Skip to content

fix(AS7341): AS7341 overflow, spectral coefficients and new PAR coefficients - #7

Open
Ludo-lab wants to merge 6 commits into
mainfrom
fix/spec_overflow
Open

fix(AS7341): AS7341 overflow, spectral coefficients and new PAR coefficients#7
Ludo-lab wants to merge 6 commits into
mainfrom
fix/spec_overflow

Conversation

@Ludo-lab

Copy link
Copy Markdown

creation Command 35
adjustment spec coefficients

Ludo-lab and others added 6 commits August 12, 2026 17:45
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>
@Ludo-lab Ludo-lab changed the title Fix/spec overflow (fix) AS7341 overflow, spectral coefficients and new PAR coefficients Aug 19, 2026
@Ludo-lab Ludo-lab changed the title (fix) AS7341 overflow, spectral coefficients and new PAR coefficients fix(AS7341): AS7341 overflow, spectral coefficients and new PAR coefficients Aug 19, 2026
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