Skip to content

Stabilizer asynchronous batch sampling support#165

Merged
ryan-summers merged 23 commits into
quartiq:masterfrom
vertigo-designs:feature/dma-updates
Nov 25, 2020
Merged

Stabilizer asynchronous batch sampling support#165
ryan-summers merged 23 commits into
quartiq:masterfrom
vertigo-designs:feature/dma-updates

Conversation

@ryan-summers

@ryan-summers ryan-summers commented Nov 5, 2020

Copy link
Copy Markdown
Member

This PR updates the stabilizer firmware to utilize batch-based sampling of the ADCs. This essentially offloads the task of triggering SPI reads and gathering ADC samples into a buffer into hardware DMA. This PR also updates DAC outputs to utilize a DMA trigger to periodically write DAC codes to the DAC SPI as well.

A single timer drivers DAC + ADC DMA transfers - four comparison channels (each configured to compare against timer value 0) are used to generate 4 DMA requests, which initiate DAC writes and ADC samples simultaneously.

To generally describe the new ADC implementation, there are four DMA streams and one timer used to offload sampling. The ADC SPI interfaces are configured in infinite transaction mode with auto-suspend CS when no data is available. To trigger an ADC sample, a constant word is written to the SPI TXFIFO by the trigger DMA, which is repeatedly requested by a timer channel. This effectively controls the sample rate on both channels.

Two other DMA streams are configured to continuously read from the SPI RX FIFOs to gather data. The DMA will only read when data is present in the RX FIFO, so these will wait until the desired number of samples are acquired.

Once the DMA completes gathering N samples, an interrupt is generated for the DMA stream and firmware retrieves the buffers provided to DMA, which are now filled with ADC samples. It then schedules the next DMA transaction for additional samples before continuing to perform DSP on the acquired ADC samples.

Once DSP has been completed on the samples, they are enqueued into a FIFO for transmission on the DAC. The DAC DMA transfers are configured and started. The DACs are then asynchronously updated.

TODO

@ryan-summers
ryan-summers marked this pull request as ready for review November 10, 2020 15:55
Comment thread Cargo.toml Outdated
Comment thread Cargo.toml Outdated
Comment thread openocd.gdb Outdated
@ryan-summers

Copy link
Copy Markdown
Member Author

@irwineffect After our discussion yesterday, Robert and I discovered that DMA transfers behave differently than documentation would lead you to believe.

When a peripheral generates a DMA request, this results in a single data transfer of the request, not a completion of the entire request.

This means that it's possible to use the DMA channels to also update the DAC output codes regularly. I have since updated the PR to support DMA-driven DAC updates as well.

@jordens

jordens commented Nov 17, 2020

Copy link
Copy Markdown
Member

Would macros or generics for the timer channels, the ADC code, and the DAC code shrink the code?

@jordens
jordens self-requested a review November 17, 2020 13:25

@jordens jordens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The refactoring with macros/generics to reduce code footprint can also be done later.

@matthuszagh matthuszagh mentioned this pull request Nov 19, 2020
4 tasks
Comment thread src/sampling_timer.rs Outdated
Comment thread src/sampling_timer.rs Outdated
Comment thread src/sampling_timer.rs
Comment thread src/adc.rs
Comment thread src/adc.rs Outdated
Comment thread src/main.rs Outdated
Comment thread src/main.rs Outdated
Comment thread src/dac.rs
Comment thread src/sampling_timer.rs Outdated
Comment thread src/sampling_timer.rs Outdated

@irwineffect irwineffect left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ryan-summers
ryan-summers merged commit b0153b8 into quartiq:master Nov 25, 2020
@ryan-summers
ryan-summers deleted the feature/dma-updates branch November 25, 2020 15:58
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.

3 participants