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);
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.
Solved! Go to Solution.
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.
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 ?