Skip to content

Flush above-threshold event buffer early instead of waiting out the interval - #16

Merged
kaklik merged 2 commits into
AIRDOS03Bfrom
feature/event-buffer-overflow-handling
Sep 6, 2026
Merged

Flush above-threshold event buffer early instead of waiting out the interval#16
kaklik merged 2 commits into
AIRDOS03Bfrom
feature/event-buffer-overflow-handling

Conversation

@kaklik

@kaklik kaklik commented Sep 6, 2026

Copy link
Copy Markdown
Member

Closes #15

Summary

  • Raise MAX_EVENTS 300 -> 1000 in both firmware variants (AIRDOS03_USTDFF, AIRDOS03_MAVLink), sized against the ATmega1284P's 16 KB SRAM (verified 30.5%/31.9% RAM usage after the change).
  • Extract the interval-flush logic into a shared static inline flushDataOut(), called both on the normal 10 s tick and immediately from loop() once events_counter reaches MAX_EVENTS, so a full above-threshold event buffer starts a fresh (shorter) interval instead of silently discarding events for the remainder of the old one.

This fixes the spectrum discontinuity at channel 64 reported in #15 (observed live in dosview, tested with an Am241 source): under high count rate, the 300-event cap was reached well before the 10 s DataOut() tick, after which every above-threshold event for the rest of the interval was dropped while channels below THRESHOLD kept being recorded — producing the "spectrum doesn't connect at channel 64" artifact.

The resulting variable interval length is recoverable downstream from either the GNSS-synced $STOP timestamp or the raw TCNT1 tick pair (captStart/stopSystime) already present in every record. dosview has been updated separately in UniversalScientificTechnologies/dosview#17 to use this and to warn when it detects buffer truncation.

Test plan

  • pio run builds clean for both AIRDOS03_USTDFF (TFUNIPAYLOAD01_uart) and AIRDOS03_MAVLink (TFUNIPAYLOAD01_isp) environments.
  • Verified RAM usage via pio run -t size.
  • Flash to hardware and confirm no spectrum discontinuity under a high-rate check source (e.g. Am241, matching the original report).

@kaklik
kaklik changed the base branch from kaklik-firmware_documentation to AIRDOS03B September 6, 2026 09:54
…nterval

A check-source or high-altitude burst can fill the 300-slot event buffer
well before the 10 s DataOut() tick, after which every above-threshold
event for the rest of the interval was silently discarded while channels
below THRESHOLD kept being recorded — producing a step discontinuity in
the spectrum exactly at the histogram/event boundary (channel 63/64).

- Raise MAX_EVENTS 300 -> 1000: sized against the ATmega1284P's 16 KB
  SRAM (measured 30.5%/31.9% RAM usage after the change), extending the
  loss-free rate from 30 Hz to 100 Hz sustained per 10 s interval.
- Extract the interval-flush logic into a shared static inline
  flushDataOut(), called both on the normal 10 s tick and immediately
  from loop() once events_counter reaches MAX_EVENTS, so a full buffer
  starts a fresh (shorter) interval instead of sitting idle dropping
  events for the remainder of the old one. inline keeps this on the
  hot loop() path without added call overhead/dead time.

The resulting variable interval length is recoverable downstream: $STOP
carries both the GNSS-synced absolute timestamp (tm.tm_s100) and the raw
TCNT1 tick pair (captStart/stopSystime), either of which gives the exact
duration of that specific interval. dosview has been updated separately
to use this and to warn when it detects buffer truncation.
@kaklik
kaklik force-pushed the feature/event-buffer-overflow-handling branch from 2bfe14c to abd51b8 Compare September 6, 2026 11:01
Upload commands were missing -e TFUNIPAYLOAD01_uart, causing PlatformIO
to also touch the ISP environment. The CTS-reset comment was also
misleading: verified via strace that avrdude's arduino protocol toggles
DTR/RTS on the host serial port, not CTS directly — the TFUSBSERIAL01
adapter wires its RTS output to the board's CTS pin, which is what
triggers the bootloader reset.
@kaklik
kaklik merged commit 835de4e into AIRDOS03B Sep 6, 2026
8 checks passed
ustbot added a commit that referenced this pull request Sep 6, 2026
…vent-buffer-overflow-handling, extended build
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.

Histogram

1 participant