2024-01-26 07:56 AM
I'm using the STM32F103C8T6 microcontroller, better known as the blue pill.
I need to make a code that reads the voltage of a port (which I already managed to do) and depending on the input voltage it turns the PWM on or off. I'm having trouble because the code seems to be correct, but the PWM doesn't turn on.
Below I provide my Timer and PWM configuration in the hope that someone can help me. This is the code I made:
Could anyone help me?
2024-01-26 09:46 AM
HAL_TIM_PWM_Stop stops the timer. Call it before HAL_TIM_PWM_Start or use lower-level commands to start/stop only that channel.
Is pulse set to a value that would provide a PWM signal as opposed to a DC signal?
2024-01-28 07:29 AM
I'm sorry I did not understand your question. I just want to generate a PWM that varies depending on the voltage read
You mean that I initialize "HAL_PWM_Start" outside the while, right? So I use this "_HAL_TIM_DISABLE(htim)" in while?
But I'm using all PWM channels on TIM1, so using this code would disable all channels, wouldn't it?
2024-01-28 07:52 PM
Within your main loop, in each of your 3 if statements, you have 1 start command and 2 stop commands. Put the 2 stop commands before the 1 start command. The stop command disables the timer.