cancel
Showing results for 
Search instead for 
Did you mean: 

Hello everyone, I am encountering with an issue about PWM over DMA.

gceti.1
Associate II

My PWM and DMA configurations shown in below image and I wrote a simple code to start pwm. 

0693W00000aJiE9QAK.png 0693W00000aJiDgQAK.png

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);

0693W00000aJiDfQAK.png 

What is the problem in here?

4 REPLIES 4
gbm
Lead III

DMA request is generated after the first period, the loaded duty, thanks to the preload function, goes effective after the second period.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
gceti.1
Associate II

What if I want to start the pwm immediately ?

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

gceti.1
Associate II

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