Hi,
first of all, I have to say I'm typically an hardware engineer, that's why my typical projects are normally a bit more hardware focused and my programming skills are not that great.
Furthermore I have to say, this is the first time working with an STM32F103RBT6 using the STM CubeIDE and its HAL. Before this I did stuff with various ATmegas (long before Arduino was widely spread) and some PIcs.
My project involves an STM32F103RBT microcontroller that uses it's internal ADCs triggered by timer 4 at 15Samples/s.
As soon as the ADC buffer is full the DMA complete interrupt is executed and whitin the ISR the processor increases the sample rate to 1MSamples per second and changes the DMA buffer to a fresh one.
Overall the sampling should look like this at the end:
- 20000 samples (10 DMA buffers) at 15samples/second
- 200 samples (1 DMA buffer) at 1Msamples/second
- 200 samples (1 DMA buffer) at 500ksamples/second
- 200 samples (1 DMA buffer) at 250ksamples/second
- 200 samples (1 DMA buffer) at 125ksamples/second
- and so on until ~15 samples per second are reached.
This has to be done so fast that there is no "gap" between two buffers.
But as you can see in the picture below the DMA interrupt can't execute fast enough to be able to do that.
The picture shows the point where the timer is changed from 15samples/second to 250kS/second (I made this picture with 250kS/s instead of 1MS/s but you will get the point).
Blue: Timer4 output (this generates the sample rate for the ADCs)
Red: Debug_GPIO set at the beginning of the DMA Transfer Interrupt routine
Yellow (D12): Debug_GPIO set when the timer gets is new values.
Now I'm struggling to get this code even faster. I tried to get rid of the HAL in the time critical sections (resulting in some pretty weird looking code mixture).
Are there ways to get this ISR call even faster?
If there is now way to speed the ISR up, is there another possibility to create a sampling clock that can quickly change its output frequency on the fly without hickup and delays?
Is there a way to generate 200 sample clock pulses at one frequency and than use DMA to give the timer completly different settings to generate another 200 clock pulses at a completly different frequency?
I attached this main-file of the source code. Please excuse the crudity of the code, I'm a mostly self taught programmer using trial and error.
To make inspecting the code easier:
The DMA ISR is in line 316
At this point I'm pretty much lost. I hope somebody has a brilliant idea on this topic
.
Best regards,
Wolfgang.
Edit: modified the silly MSamples copy&paste error.