2023-10-25 11:46 PM
Hi,
1. Project Purpose: Generate pulse to control stepper Driver.
2. My method and step:
1) every 2 milisecond calculate out the pulse need to send next cycle;
2) DMA and Timer Handle the pulse sending.
a. Timer update interru 3pte cycle is 2ms, ARR = 56000.
b. enable OC compare output , Toggle mode
C. Timer count from 0~56000, CCRx will be a series value attempt to toggle the output.
For example, I want to generate 2 pulse in 2ms cycle, Then I need to set CCRx to 14000 , 28000, 42000, 55999 step by step.
d. Using DMA to Send CCRx Array.
e. Using DMA Double Buffer mode.
3. My Question:
1) All work right when the pulse frequence below 100kHz
2) It seems that above 100KHz, DMA will be too slow to push the newer CCRx value to the peripherial. So the pulse will lose.
for exmaple:
a. last cycle 100puse / 2ms
b. DMA should TC interrupe first then Timer update interrupe,
c. But What I debug found is After DMA interrupe, Timer CNT have been exeeced and be arround 2000 of 56000.(0...56000 => 0... 2000)
3) Another question: I found that , DMA CCRx value pushing would be affect by other thread, for example 100 pulse /200ms, actually , we will lost 80% pulse per cycle.
Solved! Go to Solution.
2023-10-26 06:48 AM
Welcome @Nickle to ST Community,
Have you tried adjusting the DMA data rate or increasing the buffer size?
For the third question, you may want to consider using mutexes or semaphores to make sure that only one thread is accessing DMA at a time.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-10-26 06:48 AM
Welcome @Nickle to ST Community,
Have you tried adjusting the DMA data rate or increasing the buffer size?
For the third question, you may want to consider using mutexes or semaphores to make sure that only one thread is accessing DMA at a time.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-10-26 06:07 PM
Hi Sarra.S
It seems that I have fix the bug on my code.
1) Change the priority of the DMA interrupte;
2) You are right about mistooken on my double mem buffer calculating and filling sizes.
And Now doing 300KHz stable testing.
Thank you so much.