Skip to content

[bug] data_dispatch: size ADC DMA buffers for several dispatch periods - #162

Draft
luizvilla wants to merge 1 commit into
owntech-foundation:mainfrom
luizvilla:bugfix/data-dispatch-dma-margin
Draft

luizvilla wants to merge 1 commit into
owntech-foundation:mainfrom
luizvilla:bugfix/data-dispatch-dma-margin

Conversation

@luizvilla

Copy link
Copy Markdown
Member

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_lock sections. 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 repetitions to 4 × repetitions 16-bit words. For example, with 2 channels and 5 repetitions it goes from 6 to 22 words (12 to 44 bytes).

Test

  • Builds on spin@1_2_0 / twist_v1_4_2.
  • Bench (Spin + ownverter, task dispatch, 2 channels per ADC): 5 conversions per ADC every tick, including around delayed ticks.

Before marking ready

  • Bench test of this branch on Spin + scope (planned next week)

🤖 Generated with Claude Code

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>
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