2020-12-24 02:15 AM
Hello,
I currently use the STM32G4 MCU Nucleo board (NUCLEO-G474RE) - I create an array of numbers (specifically - a sine wave at a certain frequency), which I transmit via the DMA, triggered by a timer (TIM2). Currently, the array is being transmitted by the DAC endlessly.
What I want is:
For example:
arr1 = [0,1,2,...]
transmit arr1 for 1 sec.
Create a new arr: arr2 = [3,4,5...]
transmit arr2 for 1 sec
etc.
What is the best way to do that? Please be as specific as you can regarding each step, an example will help.
Thanks for helping!
2020-12-24 07:50 AM
Set the DAC to shift out data via a circular DMA buffer, forever.
Every 1s, change the contents of that buffer.
At the end, stop the DAC.
So don't create a new array, just modify the one already in use by the DAC.
2020-12-27 12:53 AM
Hey,
How do I time the every 1sec to change the content of the buffer?
2020-12-27 07:47 AM
The value returned by HAL_GetTick() changes by 1 every 1ms. You could use that. Or you could create another timer that updates once per second and do the processing in the timer update callback.
2020-12-27 08:08 AM
Have the DMA TC/HT interrupts count out elapsed time, have the buffer size as some multiple that cleanly divides into the time span you're looking to cover. ie don't pick large odd numbers that don't divide into anything helpfully.
Say have a buffer holding 10 or 100ms of sample data. Perhaps use a TIM with a repetition count, and capable of triggering the DAC with a CCx rather than UPDATE signal.