2022-09-08 09:02 AM
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
Solved! Go to Solution.
2022-09-08 02:43 PM
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
2022-09-08 09:18 AM
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
2022-09-08 09:44 AM
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.
2022-09-08 02:43 PM
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
2022-09-08 03:18 PM
Thanks man.
Will try to implement it.