Repository navigation
Conversation
In task dispatch mode, the number of new conversions is computed from the DMA position, and the circular DMA buffer only held one dispatch period (plus one sample per channel). When the critical task was delayed by about two PWM periods (long interrupt, synchronous logging), the DMA wrapped around more than once between two dispatches and conversions were lost without any error. The buffer now holds DATA_DISPATCH_MARGIN_TICKS (4) dispatch periods. The rounding to a multiple of the enabled channel count is applied to the new size instead of to the repetition count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 tasks
This was referenced Nov 25, 2026
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
In task dispatch mode, the ADC DMA buffer holds only one dispatch period of conversions (plus one sample per channel). The number of new conversions is computed from the DMA position, so if the critical task is late by about two PWM periods, the DMA wraps around more than once between two dispatches and conversions are lost silently.
This PR sizes the buffer for
DATA_DISPATCH_MARGIN_TICKS(4) dispatch periods. It also applies the rounding to a multiple of the enabled channel count to the new size, not to the repetition count.Context
Found while bench testing DMA-driven HRTIM duty sequences (critical task at 100 µs, 5 conversions per ADC per tick). A spurious DMA interrupt logged an error, and the deferred log output delayed one tick by about 70 µs. The buffer held only 6 conversions per ADC, so that late tick lost data: some ticks had 3 or 1 conversions instead of 5.
The root cause of the delay is fixed in the duty sequence PR. This PR makes the dispatch tolerate a late tick, whatever delays it: synchronous logging, long interrupts, or
irq_locksections. With both changes, every tick had 5 conversions per ADC.Relation to #161
#161 changes the dispatch loop and fixes the overflow when a channel buffer is full. This PR only changes the DMA buffer allocation. The two merge cleanly with each other (checked with
git merge-tree) and are complementary.Cost
RAM: each ADC DMA buffer grows from
repetitionsto4 × repetitions16-bit words. For example, with 2 channels and 5 repetitions it goes from 6 to 22 words (12 to 44 bytes).Test
spin@1_2_0/twist_v1_4_2.Before marking ready
🤖 Generated with Claude Code