cancel
Showing results for 
Search instead for 
Did you mean: 

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

HJang.3
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4

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

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.

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

Thanks man.

Will try to implement it.