Getting started with Motor Control

Revision as of 12:33, 24 September 2020 by Registered User
Under construction.png Coming soon
Info white.png Information
Please note that the software's used version in this tutorial is V5.4.3.
Please make sure to always use the last updated version.


Target description

The first part of the tutorial:

This tutorial enables you to use ST Motor Profiler and after applying it you will be able to :

  • Connect the motor control pack to your computer.
  • Start the motor
  • Monitor the speed.

The second part of the tutorial:

This tutorial enables you to use ST Motor Control SDK and after applying it you will be able to :

  • Generate the code to start the motor
  • Add delay to the engine

Prerequisites

  • Computer with Windows 7 (or higher)
  • ST-Link utility installed and updated

Hardware

Software

  • ST Motor Profiler

For the second part of the tutorial:

Literature

1. Configure your first motor application by means of ST Motor Profiler

Clock.png 25min

1.1. Install ST Motor Profiler

Get the installation file from this link and unzip it. Then just execute the .exe file so that the installation starts.
Once the installation is done the software is installed on your computer.
The ST Motor Profiler is automatically installed with the STM32 Motor Control Software Development Kit on your computer.
Once the installation is done, it will get installed automatically with the MotorControl Workbench while following the installation steps.
profiler.png

1.2. Connect the package to the computer

In this tutorial we will be working the P-NUCLEO-IHM03 Motor Control package composed by NUCLEO-G431RB as command board and X-NUCLEO-IHM16M1 as power board.
To start our application we should set up the boards and the power source, and finally connect it to the computer.
After setting up the boards and motor properly, let's launch the Motor Profiler application.

  • The first step to do is to select the boards we are using by clicking on Select Boards button

select12.png
boards.jpg

  • By referring to the user manual, the following parameters regarding the motor characteristics can be defined and set in the appropriate cases:
    • Pole Pairs
    • Max Speed
    • Max Current
    • VBus.
Info white.png Information
Do not forget that the pack used in this tutorial is P-Nucleo-IHM03, if you are using another one please make sure to refer to the user manual to set the right characteristic values.
  • After defining the values, the next step is to click on Connect button and check the motor working correctly.
Warning white.png Warning
Please make sure to upgrade the ST-Link version so to not have problems with launching the application.


First, ST Motor Profiler will create the following ST-Link checklist in order to load the added parameters to the software created for the board:
stlinkchec.png

1.3. Start the test

After finishing the connection between the boards and the computer, it is now the time to start the test.

  • Click on Start Profile button.

When clicking, the motor will start rotating in a high speed and the electrical as well as the mechanical models will get established as shown in the following photo, and if there is any fault it will be mentioned on the right of the window.
connect.png

1.4. Monitor the speed

After checking that the motor is connected and working properly, the next step is to make it work while controlling its speed.

  • Click on Play button and the following window appears.
  • By moving the cursor, the speed can be monitored


playwith.jpg

Now you are able to:

  • Start your own motor application
  • Set and properly use the ST Motor Control pack
  • Control the acceleration of the motor

2. Start the motor using ST Motor Control Workbench

Clock.png 45min

2.1. Install Motor Control Workbench

For the installation of the Motor Control Workbench, please follow the steps mentioned in the previous part of the tutorial.

2.2. Start the first application

Since the pack used is the P-Nucleo-IHM03 it is mandatory to select the appropriate boards used.
First step to do so is to click on New Project and to select the NUCLEO-G431RB as control board & X-NUCLEO-IHM16M1 as power board and later click on ok as enumerated in the next photo:
selectboard.jpg
After finishing selecting the pack's boards, another window appears that allows the user to check the details and set the values of the different caracteristics.

Info white.png Information
It is recommended to check some of the different values and try to use the user manual of the power control as well as the control board in order to understand them.

Later, just click on the generate file button presented in the photo below, and save the project in the appropriate directory. motorgenera.png
Then a window that allows to choose the IDE to use, and the drive type appears. Just click on Generate and after the software finishes generating the .ioc file, do not change any parameter, just click on Run STM32CubeMX.
codegeneration.jpg
The .ioc file is open now and the next step is to simply generate the code in the STM32CubeIDE and do not forget to update the project information in the Project Manager section.

The main code generated is as follows:

Info white.png Information
The CORDIC is a hardware accelerator designed to speed up the calculation of certain mathematical functions, notably

trigonometric and hyperbolic, compared to a software implementation.

Once the code is generated, the only step to do is to connect the pack and to debug the program.
The program has been installed on the command board and once clicking on the user button, the engine rotates correctly.

2.3. Start the motor and rotate the engine with a delay

In this part, the target work is to start the motor and make it stop with a delay fixed by the user.
The first steps are same as the previous part until the code generation.
Then, add the following code to the while loop in the main file:

 while (1)
  {
	  MC_StartMotor1();
	  HAL_Delay(2000); 
      MC_StopMotor1();
 }

3. Control the motor's direction

In this part, the motor control will be based on the direction control.
It will be devided into two parts, the first one is the managing the Motor Control Workbench and the second will concern the programming part.

3.1. Changing the motor control workbench parameters

After launching MotorControl Workbench, select the appropriate boards and pack. Later generate a project as presented in the previous parts.\\Once generating the project file, click on Firmware Drive Management and select Drive Setting. File:position.png

3.2. Managing the programming code part

while (1)
{
MC_StartMotor1();
x=x+0.175;
MC_ProgramPositionCommandMotor1(x,0);
}

Now you are able to:

  • Start your first application using MotorControl Workbench
  • Generate the motor control code
  • Rotate the engine
  • Specify the delay needed between the start and the stop