Skip to main content
HJang.3
Associate II
September 8, 2022
Solved

To update DMA (array buffer) during runtime for changing duty cycle of TIMER 1 pwm complementary channels on STM32F103C8T6(bluePill).

  • September 8, 2022
  • 2 replies
  • 2546 views

My question is regarding HAL library in STM32F103C8T6(blue Pill) , I've just started using stm32 , I've good knowledge about arduino.

I am trying to make sine PWM for a single phase inverter. For that i need channel1 of timer1 to generate complementary pwm signal Which i ve done using DMA (array of duty cycles), to vary duty cycle.

I've used :

 HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *) sinebuffer, 60);

 HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);

to generate PWM.

but this circular DMA buffer contains values to generate 100% sine amplitude only.(max duty cycle).

So to implement feedback to the project , I have to update DMA array Values (into some percentage of initial values)

Now i don't know how to implement it,

if there is a way like for example CCR = ( array[x] * percentage)

or any other method to multiple DMA array values (1 to 100%).

I will read percentage from analog pin.

THANK YOU

This topic has been closed for replies.
Best answer by waclawek.jan

Usually, you use DMA array twice as big. In the Half Transfer interrupt you can update the first half, in the Transfer Complete interrupt the second half.

JW

2 replies

waclawek.jan
Super User
September 8, 2022

Period of PWM output is given by value of TIMx_ARR, while pulse duration is given by TIMx_CCRx.

Thus, duty = (TIMx_CCRx + 1) / (TIMx_ARR + 1).

Reverse it to calculate TIMx_CCRx from TIMx_ARR and duty.

JW

HJang.3
HJang.3Author
Associate II
September 8, 2022

I can calculate CCR values, as I already have DMA array buffer of CCR values for different duty cycle. Now i want to update that DMA array values while the program is running .

How can i do that ?

THANKS.

waclawek.jan
waclawek.janBest answer
Super User
September 8, 2022

Usually, you use DMA array twice as big. In the Half Transfer interrupt you can update the first half, in the Transfer Complete interrupt the second half.

JW

HJang.3
HJang.3Author
Associate II
September 8, 2022

Thanks man.

Will try to implement it.