2023-03-26 04:49 AM
My PWM and DMA configurations shown in below image and I wrote a simple code to start pwm.
As you see below, I set a gpio output pin and after that pwm starting. PWM period has setted to 20ms. What I except, I except start pwm after a few us gpio pin went high. But and pwm starts after 40 ms gpio pin goes to high.
uint16_t data[10] = {50,100,150,200,250,300,350,400,450,500};
HAL_Delay(500);
HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin,GPIO_PIN_SET);
HAL_TIM_PWM_Start_DMA(&htim1,TIM_CHANNEL_1,(uint32_t*)data,10);
What is the problem in here?
2023-03-26 05:22 AM
DMA request is generated after the first period, the loaded duty, thanks to the preload function, goes effective after the second period.
2023-03-26 06:39 AM
What if I want to start the pwm immediately ?
2023-03-26 08:47 AM
Which STM32?
One of the options would be to "manually" write first period's value to CCRx and force Update (by setting EGR.UG), before enabling the DMA. But the result depends on how exactly the Cube/HAL functions are written.
JW
2023-03-26 09:09 AM
Which STM32?
STM32F4 Series,, but, also I tried it with STM32G0 series and faced with same issue.
Actually you are right. when update the CCR register manually and set the CNT register to highest counter value the pwm starts immidiately. But I am not sure is it correct way or not