2019-02-20 09:12 AM
Need to generate a repeating waveform with external SPI 16-bit DAC.
Using a table of values in memory, repeatedly loop through table outputting values to DAC.
Delay between outputs is constant. No glitches at repeat!
DMA only (no interrupts).
What's the most effective way to do this with ST32F427?
Thanks,
Best Regards, Dave
Solved! Go to Solution.
2019-02-26 11:47 AM
This turns out to be much easier than I thought (I missed 'DMA circular mode' first go around).
One timer to:
DMA:
Scope picture below (top trace is CS, bottom 2 traces are SPI clock and MOSI):
2019-02-20 09:17 AM
Pattern buffer with TIM driving DMA to GPIO->BSRR
SPI on the STM32 is a bit limited due to the brain damaged implementation of chip select. On could certainly loop DMA data to SPI->DR, but the word level synchronization at the target device is problematic.
2019-02-20 11:00 AM
@Community member - That's not going to work driving an SPI, and doesn't address how to loop?
2019-02-20 11:07 AM
One way to do this is with a DMA stream writing SPI:
Primary timer uses additional channels to generate:
2nd timer is used to reset system at time after table cycle by using a DMA2 stream to:
This seems really complicated; is there a simpler way to do it?
Thanks in advance,
Best Regards, Dave
2019-02-20 11:21 AM
I could generate any set of bit patterns I want at very high speed, I could certainly drive an SPI attached device at speeds matching the peripheral implementation, and loop the patterns.
2019-02-20 11:54 AM
What SPI DAC device is considered here? Without knowing how to update the external DAC, it's difficult to "optimise". Also, why not using internal DAC if available. Voltage?
2019-02-20 11:56 AM
OK, I think I understand. Requires 3 transfers per SPI bit (clock low, set data bit, clock high) plus transfers for CS, so ~50 32-bit words for each 16-bit value to go to the DAC, right?
2019-02-20 11:57 AM
It always helps a discussion's quality if facts are stated. What DAC, what sample rate/frequencies, what data length, how many channels, which STM32, etc.
For audio-rate signals (i.e. 20Hz-20kHz, no DC-correctness required), look at I2S and respective I2S DACs.
TI mode in SPI module provides framing, too, the DAC has then to be chosen to fit this mode.
I'm not familiar with the DACs offerings, but I'd be willing to bet that there are serial DACs out there which don't require explicit framing, i.e. which automatically convert upon each Nth shifted bit.
If DAC has been already chosen and it requires different framing, besides the fairly straighforward timer-triggered-DMA-to-GPIO as Clive suggests, you can also look at generating whatever clocks waveforms you need using chained timers, and feed them back to SPI in slave mode.
You may also want to look at the SAI module, it's pretty flexible in its settings.
> No glitches at repeat!
Why would there be glitches, if DMA is in circular mode?
JW
2019-02-20 12:05 PM
@S.Ma - We need 16 bits of real accuracy, not 12 bits of marketing accuracy, hence the external DAC (also higher voltage to minimize noise). Standard 16-bit SPI xfer to set DAC (LDAC strobe optional).
2019-02-20 12:10 PM
Thanks @Community member - Faster than audio, waveform is 62kHz. Hadn't thought to see if there are I2S DACs that run fast enough. Perhaps circular mode with NDTR = table length does what I need (possibly requiring timer to generate CS as well as trigger DMA)?