cancel
Showing results for 
Search instead for 
Did you mean: 

Motor Pilot

kkhli.1
Associate III

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)
{

}

1 ACCEPTED SOLUTION

Accepted Solutions

thank you it works correctly now

View solution in original post

4 REPLIES 4
Sarra.S
ST Employee

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.

kkhli.1
Associate III

the GPIO configuration  is covered by the file 

Hl_st
ST Employee

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.

thank you it works correctly now