2024-06-25 03:08 AM - last edited on 2024-06-25 06:03 AM by STOne-32
Hi all!
I am new on STM32 this is my first project on STM32CubeIDE. I want to generate variable duty cycle using ADC with complementary PWM. When I did the code for one channel PWM it works well and the duty cycle varies but when I did it for the complementary PWM it does not work . Here is a picture of the code. What should I do to make it works for the complementary PWM? I will be grateful for your help.
while (1)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,HAL_MAX_DELAY);
pwm = HAL_ADC_GetValue(&hadc1);
duty = (pwm*899/4095);
HAL_Delay(1);
}
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); //AH=H,S1