2024-11-25 04:54 AM
Hello,
I'm facing a very strange issue with timer PWM in DMA mode.
I use the PWM channel to send step pulses to a stepping motor in order to free the mcu while the motor is moving, rather than using time consuming delays.
The issue raises when I change the motor speed by changing the PWM frequency.
Changing the PWM frequency breaks the DMA.
What I mean by breaks the DMA is that when I call the start function
if (HAL_TIM_PWM_Start_DMA(THIS->timer, THIS->channel, THIS->burst_buffer, THIS->steps_burst_size) == HAL_OK)
{
osMessageQueueGet(THIS->sync, &_token, 0L, osWaitForever);
}
I always get HAL_OK, but the pulse finished callback is never called.
I change the PWM frequency in a rather rogue way, by writing a new value to the ARR register.
I'm sure that the issue is related to the frequency change, if I comment out the lines changing the frequency, all works well.
To check wether errors are are trigerred or not, I setup a HAL_TIM_ErrorCallback, but it never gets called.
Solved! Go to Solution.
2024-11-26 12:59 AM
I think this has to do with the prescaler update being buffered and synchronized with the timer's update event, so, it avoids the immediate glitches that can occur when directly updating the ARR register.
I still believe that the best way to deal with ARR is to enable the preload so that you can update the ARR register without immediately changing the active register. Then, creating an update event can make sure that the new value in the preload register is transferred to the active register at the right 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.
2024-11-25 06:46 AM
Hello @zeboss49,
Are you enabling the preload when updating to the ARR register?
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.
2024-11-25 08:15 AM
Hello,
No, I don't enable it.
When it is enabled, DMA does not work properly.
I've tried another solution, I change the prescaler, and surprise... all works well.
I would prefer using ARR, but the workaround using the PSC is acceptable as a temporary solution.
2024-11-26 12:59 AM
I think this has to do with the prescaler update being buffered and synchronized with the timer's update event, so, it avoids the immediate glitches that can occur when directly updating the ARR register.
I still believe that the best way to deal with ARR is to enable the preload so that you can update the ARR register without immediately changing the active register. Then, creating an update event can make sure that the new value in the preload register is transferred to the active register at the right 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.
2024-11-27 09:47 AM
Hello,
I agree with you, enabling preload will be useful when you try to change the ARR on the fly, but this is not the case.
No DMA transfer is in progress when I set the ARR.
I will stay with the prescaler, it does the job, I've carefully reviewed the sped adjustments required in the app, and all can be solved by changing the prescaler.
Thanks for your help.