2023-12-18 06:47 AM
I have an issue when using both PWMs generated by timers TIM2 and TIM3 to control two motors simultaneously. Specifically, when I call the function DC_MOTOR_Init(0), it activates PWM1, and when I call DC_MOTOR_Init(1), it activates PWM2. However, if I call both DC_MOTOR_Init(0) and DC_MOTOR_Init(1) simultaneously, they don't seem to work together. When I call either function alone, it works correctly, but when I attempt to call them simultaneously, there is an issue. Despite the fact that the two timers do not share common resources..
#include "main.h"
#include "DC_MOTOR.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
DC_MOTOR_Init(1);
DC_MOTOR_Init(0);
/
while (1)
{
}
Solved! Go to Solution.
2023-12-19 11:18 AM
thank you it works correctly now
2023-12-19 03:27 AM
Hello @kkhli.1,
I cannot see what could have caused the conflict
DC MOTOR 1 uses TIM2_CH1 to generate the PWM signal
DC MOTOR 2 uses TIM3_CH1 to generate the PWM signal
the code you provided does not cover the GPIO configuration though, but I suppose you're using different GPIOs to control the motors?
Meanwhile, I will look more in-depth
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-12-19 06:01 AM
2023-12-19 07:35 AM
Hello,
please try to null htim variable in function DC_Motor_Init() before htim variable will be used:
TIM_HandleTypeDef htim = {0};
It should works correctly.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-12-19 11:18 AM
thank you it works correctly now