Main Content

Swap Motors with Single Model Deployment of Sensor-Based FOC Algorithm

This example shows how to run a permanent magnet synchronous motor (PMSM) in an industrial drive application setup using position-sensor-based field-oriented control (FOC). Industrial drives enable you to swap motors in real time. These drives enable you to replace a motor with a new one without repeated deployment of code. An industrial drive setup needs a fixed inverter and software that has the ability to adapt the control algorithm according to the new motor using only the updated nameplate parameters.

The example uses motor agnostic models that are independent of motor parameters. You do not need to know the parameters of your motor to use these hardware-deployable target models.

To use the target models, you need only these details:

  • Motor type (this example only supports a PMSM)

  • Operating power range of your motor (this should be compatible with the power output of the BOOSTXL-DRV8305 inverter supported by this example)

  • Type of position sensor inside your motor (this example supports only a quadrature encoder sensor with an index pulse)

After successfully running a motor, the usual practice of replacing or swapping the motor includes updating the motor parameters in the control algorithm (such as FOC) and then generating and deploying the code again to the motor control hardware. This process can be time-consuming, especially in industrial and production environments where motors are regularly swapped but the controller and inverter hardware must remain fixed.

The example addresses this limitation by enabling you to replace the current motor with a new one without having to deploy the code again. After swapping a motor, you can use the host interface to update only the motor nameplate parameters. The control algorithm (position-sensor-based FOC) running on the target hardware then automatically performs the following operations:

1. Computes offset for a quadrature encoder position sensor.

2. Estimates the motor parameters.

3. Computes control gains for the speed and current PI controllers.

4. Runs the motor using FOC by adhering to a reference speed. For more information about FOC, see Field-Oriented Control (FOC).

This sequence of operations enables the control algorithm to automatically adapt itself to the newly connected motor without manual code updates and deployment.

However, note that:

  • After deploying a target model to the target controller, the workflow supports motor replacement and code adaptability only when you continue to use the same inverter hardware. This is because the inverter parameters are fixed in the deployed control algorithm and the example only estimates the motor parameters.

  • The new replacement motor must be compatible (with respect to voltage, power, and current range) with the inverter hardware.

Open MATLAB Project

The example is packaged as a MATLAB® project. Use one of these methods to open the MATLAB project window:

1. Click Open Project button.

2. Run this command to access the example folder containing the supporting files and open the MATLAB project.



The MATLAB project has a model folder that includes the following Simulink® models:

  • PMSMQepIndustrialDriveF28379d.slx — Deploy this target model to the target controller and inverter hardware.

  • PMSMQepIndustrialDriveHostF28379d.slx — Run this host model on the host computer connected to the target hardware via the serial port.

Required MathWorks Products

To simulate model:

  • Motor Control Blockset™

  • Stateflow®

To generate code and deploy model:

  • Motor Control Blockset

  • Embedded Coder®

  • C2000™ Microcontroller Blockset

  • Fixed-Point Designer™ (required for optimized code generation only)

  • Stateflow

Simulate Model

Follow these steps to simulate the model included in the project:

1. Open the target model PMSMQepIndustrialDriveF28379d.slx from the model folder.

This model includes default PMSM parameters, which you can update in the System Parameters section of the model initialization script (PMSMQepIndustrialDriveF28379dData.m) available in the script folder.

2. Run the model initialization script.

3. Click Run on the Simulation tab to simulate the target model.

Generate Code and Deploy Model to Target Hardware

This section shows you how to generate and deploy the code to the target hardware and run a PMSM using a position-sensor-based FOC algorithm in an industrial drive setup.

In addition to the target model, the MATLAB project uses a host model. The host model, which is a user interface to the controller hardware board, runs on the host computer. To use the host model, first deploy the target model to the controller hardware board. The host model uses serial communication to command the target model, provide basic motor parameters after the motor swap, run (and control) the motor, and collect and display the debug signals from the controller.

Required Hardware

The example supports the LAUNCHXL-F28379D controller + BOOSTXL-DRV8305 inverter hardware configuration. For connections related to this hardware configuration, see LAUNCHXL-F28069M and LAUNCHXL-F28379D Configurations.

Generate Code and Run Model on Target Hardware

1. Simulate the target model and observe the simulation results.

2. Complete the hardware connections.

3. Navigate to the MATLAB project and open the target model PMSMQepIndustrialDriveF28379d.slx from the model folder.

If you want to change the default hardware configuration settings for the model, see Model Configuration Parameters.

4. The model automatically computes the ADC (or current) offset values. To ensure that CPU2 is not configured to use the board peripherals intended for CPU1, load a sample program to CPU2 of LAUNCHXL-F28379D. For example, load a program that operates the CPU2 blue LED by using GPIO31 (c28379D_cpu2_blink.slx). For more information about the sample program or model, see the Task 2 - Create, Configure and Run the Model for TI Delfino F28379D LaunchPad (Dual Core) section in the Getting Started with Texas Instruments C2000 Microcontroller Blockset (C2000 Microcontroller Blockset) example.

5. Click Build, Deploy & Start on the Hardware tab to deploy the target model to the hardware.

6. Click the host model hyperlink in the target model to open the associated host model.

For more information on the serial communication between the host and target models, see Host-Target Communication.

7. In the model initialization script associated with the target model, specify the communication port using the variable target.comport and run the script. The example uses this variable to update the Port parameter in the Host Serial Setup, Host Serial Receive, and Host Serial Transmit blocks in the host model.

8. Click Run on the Simulation tab to run the host model.

9. Update the following fields in the Motor Setup section of the host model with the motor nameplate parameters.

  • Motor pole pairs — Number of pole pairs available in the PMSM

  • Motor rated current [A] — Rated current of the PMSM (in amperes)

  • Motor rated speed [RPM] — Rated speed of the PMSM (in RPM)

  • Encoder counts per rotation — Number of quadrature encoder sensor counts for every 360-degree rotation

10. Enter the reference speed (in radians/sec) to run the PMSM in the Speed Reference [RPM] field.

11. Change the position of the Motor switch to Start to start running the motor.

12. Observe the debug signals in the scope available in the host model. You can use the Debug Signal combo box to select the debug signal that you want to monitor.

13. To swap the motor, follow these steps:

a. Turn the Motor switch to Stop to stop the motor.

b. Click Stop in the Simulink toolstrip to stop simulating the host model.

c. Turn off the DC voltage power supply.

d. Reset the LAUNCHXL-F28379D controller hardware.

e. Disconnect the motor phase and encoder connections and connect the phases and encoder wires of the new motor.

f. Turn on the DC voltage power supply.

g. Repeat steps 8 to 12 to add new motor nameplate parameters in the host model and run the new motor.