Strange delays when changing PWM using Circular DMA
Hello world!
I want to move a motor with serial commands. I use the stm32g051 PWM and a DC motor. And for the sake of lower consumption of energy and cpu I use a dma in circular mode. And of course I want to change the pwm from time to time.
But somehow, there is always a delay of more than 10 seconds between the calling of the function and the change in the motor behaviour.
mid_error_t tim_forward_buffers(void)
{
for (uint16_t i=0; i<PWM_BUF_LEN; i++){
pwm_ch1[i] = (uint32_t)(param.speed * (htim2.Init.Period-2))/ MAX_SPEED;
//pwm_ch1[i] = 0; // htim2.Init.Period;
pwm_ch2[i] = 0;
}
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, pwm_ch1[0]);
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, pwm_ch2[0]);
return MID_ERROR_OK;
}You may guess that the PWM_BUF_LEN is too big... There is just one element in pwm_ch1 and pwm_ch2. What may cause this problem?
I use the __HAL_TIM_SET_COMPARE to change the pwm faster and the pwm_ch1 pwm_ch2 just contain one element so the DMA doesn't have to wait to change it.
