cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling the motor in both directions

GJamo.1
Associate II

Hello everyone,

I'm currently working on a project where I'm trying to control a motor in both directions. However, when switching from one direction to another, there is a delay which I would like to remove.

Here is the current code that I'm using:

MC_ProgramSpeedRampMotor1(700/6, 3000);
MC_StartMotor1();
HAL_DELAY(8000);
MC_STopMotor1();
HAL_DELAY(2000);
 
MC_ProgramSpeedRampMotor1(-700/6, 3000);
MC_StartMotor1();
HAL_DELAY(8000);
MC_STopMotor1();
HAL_DELAY(2000);

As you can see, after stopping the motor, I need to add a delay before starting it again in the opposite direction. However, I would like to switch between the two directions immediately without any delay.

I'm aware that the motor needs a start-up time to begin rotating, but I'm wondering if there is a way to switch between the two directions directly without any delay. Note: If I remove the delay of 2000ms then the motor won't switch its direction.

If anyone has any ideas or suggestions, please let me know. Thank you in advance for your help!

2 REPLIES 2
Cristiana SCARAMEL
ST Employee

Hello @GJamo.1​  and welcome to the ST Community.

For a better support could you share more details on your application?

First of all: motor type, used hardware devices, commercial evalution board or custom one, etc.

Moreover, does the MC_STopMotor1() function put the power stage in high impedance or is it making a "short-circuit" across the motor winding?

Are you performing a current control? Do you have some kind of protection that can lock the motor?

In general, you have to consider the motor inertia. The bigger the inertia, the more resistant it will be to acceleration or deceleration.

So your target could be reduce the delay according to your motor charcteristics but you can hardly remove it.

If you feel a post has answered your question, please click "Accept as Solution"
GJamo.1
Associate II

Hello, I'm working on an inverted pendulum project and I need a motor that can switch directions easily to be able to control the pendulum. I'm using the same control pack specified under this STM32 tutorial website. STM32StepByStep:Getting started with Motor Control - stm32mcu. ( P-NUCLEO-IHM03 motor-control Nucleo pack composed of NUCLEO-G431RB as command board and X-NUCLEO-IHM16M1 as power board and Gimbal motor). If I don't specify the HAL delay of 2000 ms after stopping the motor, then a short circuit will occur when switching to the opposite direction.