cancel
Showing results for 
Search instead for 
Did you mean: 

Strange issue with timer pwm in dma mode

zeboss49
Associate III

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

4 REPLIES 4
Sarra.S
ST Employee

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.

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.

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.

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.