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 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.

You can use this example to run an industrial drive application and swap PMSMs by updating just the motor nameplate parameters.

To use the example, you need only these details:

  • Nameplate parameters of your motor (this example only supports PMSMs)

  • 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 currently running 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.

openExample('mcb/RunIndustrialDriveUsingFOCExample');

Model

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® (needed only if you modify the Stateflow algorithm available in the target model)

To generate code and deploy model:

  • Motor Control Blockset

  • Embedded Coder®

  • C2000™ Microcontroller Blockset

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

  • Stateflow (needed only if you modify the Stateflow algorithm available in the target model)

Simulate Model

Navigate to the MATLAB project window and follow these steps to simulate the target model:

1. Optionally, update the default values of motor parameters available in the System Parameters section of the model initialization script (PMSMQepIndustrialDriveF28379dData.m available in the script folder).

You can click the S1 Edit parameters shortcut button (available in the Project Shortcuts tab) to open the model initialization script.

If you want to use the default motor parameter values without any changes, skip this step and proceed to step 2.

2. Click the S2 Load parameters shortcut button to run the model initialization script and load the motor, controller, and inverter parameters to the MATLAB base workspace. Loading these parameters ensures successful simulation of the target model.

3. Click the S3 Open target model shortcut button to open the target model PMSMQepIndustrialDriveF28379d.slx from the model folder.

4. Click Run on the Simulation tab to simulate the target model. Observe the simulation results in the Simulation Data Inspector.

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 in the Simulation Data Inspector. For details, see the Simulate Model section.

2. Complete the hardware connections.

3. Ensure that the target model is open. You can click the S3 Open target model shortcut button to open the target model PMSMQepIndustrialDriveF28379d.slx from the model folder.

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

4. The target 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 the S4 Build and deploy target model shortcut button to deploy the target model to the hardware.

6. Click the S5 Open host model shortcut button 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 motor nameplate parameters of the new motor in the host model and run the new motor.