Skip to content

Infineon/mtb-example-ce240999-pmsm-foc-sl

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

PMSM FOC SL XMC1300, XMC1400 Drive Card

This code example (CE) demonstrates the sensorless (SL) permanent magnet synchronous motor (PMSM) field-oriented control (FOC) motor control application from Infineon XMC™ MCU using XMC1300 or XMC1400 Drive Card. To test this code example; XMC1300 Drive Card or XMC1400 Drive Card, 3-phase DC power board, and Nanotec DC motor (DB42S03) are required.

Requirements

Supported toolchains (make variable 'TOOLCHAIN')

  • GNU Arm® Embedded Compiler v11.3 (GCC_ARM) – Default value of TOOLCHAIN

Supported kits (make variable 'TARGET')

Hardware setup

Before using this code example, ensure that the XMC1300 or XMC1400 Drive Card is correctly connected to the 3-phase DC power card. Also, connect the Nanotec motor to the power card as in Figure 1. See the 3-phase Motor Control Power Card user manual for more details.

Figure 1. Hardware setup with XMC1300 Drive Card, power board, and Nanotec motor

Software setup

This code example uses Infineon's ModusToolbox™ Motor Suite application by default to run and control the motor.

Note: If you want to run the motor without using ModusToolbox™ Motor Suite, change the motor_request_start flag to true inside the main.c file. As it will directly start the motor after programming the board.

Using the code example

Create the project

The ModusToolbox™ tools package provides the Project Creator as both a GUI tool and a command line tool.

Use Project Creator GUI
  1. Open the Project Creator GUI tool.

    There are several ways to do this, including launching it from the dashboard or from inside the Eclipse IDE. For more details, see the Project Creator user guide (locally available at {ModusToolbox™ install directory}/tools_{version}/project-creator/docs/project-creator.pdf).

  2. On the Choose Board Support Package (BSP) page, select a kit supported by this code example. See Supported kits.

    Note: To use this code example for a kit not listed here, you may need to update the source files. If the kit does not have the required resources, the application may not work.

  3. On the Select Application page:

    a. Select the Applications(s) Root Path and the Target IDE.

    Note: Depending on how you open the Project Creator tool, these fields may be pre-selected for you.

    b. Select this code example from the list by enabling its check box.

    Note: You can narrow the list of displayed examples by typing in the filter box.

    c. (Optional) Change the suggested New Application Name and New BSP Name.

    d. Click Create to complete the application creation process.

Use Project Creator CLI

The 'project-creator-cli' tool can be used to create applications from a CLI terminal or from within batch files or shell scripts. This tool is available in the {ModusToolbox™ install directory}/tools_{version}/project-creator/ directory.

Use a CLI terminal to invoke the 'project-creator-cli' tool. On Windows, use the command-line 'modus-shell' program provided in the ModusToolbox™ installation instead of a standard Windows command-line application. This shell provides access to all ModusToolbox™ tools. You can access it by typing "modus-shell" in the search box in the Windows menu. In Linux and macOS, you can use any terminal application.

The following example clones the "mtb-example-ce240999-pmsm-foc-sl" application with the desired name "PMSM_FOC_SL_XMC13" configured for the KIT_XMC1300_DC_V1 BSP into the specified working directory, C:/mtb_projects:

project-creator-cli --board-id KIT_XMC1300_DC_V1 --app-id mtb-example-ce240999-pmsm-foc-sl --user-app-name PMSM_FOC_SL_XMC13 --target-dir "C:/mtb_projects"

The 'project-creator-cli' tool has the following arguments:

Argument Description Required/optional
--board-id Defined in the field of the BSP manifest Required
--app-id Defined in the field of the CE manifest Required
--target-dir Specify the directory in which the application is to be created if you prefer not to use the default current working directory Optional
--user-app-name Specify the name of the application if you prefer to have a name other than the example's default name Optional

Note: The project-creator-cli tool uses the git clone and make getlibs commands to fetch the repository and import the required libraries. For details, see the "Project creator tools" section of the ModusToolbox™ tools package user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf).

Open the project

After the project has been created, you can open it in your preferred development environment.

Eclipse IDE

If you opened the Project Creator tool from the included Eclipse IDE, the project will open in Eclipse automatically.

For more details, see the Eclipse IDE for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_ide_user_guide.pdf).

Visual Studio (VS) Code

Launch VS Code manually, and then open the generated {project-name}.code-workspace file located in the project directory.

For more details, see the Visual Studio Code for ModusToolbox™ user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mt_vscode_user_guide.pdf).

Command line

If you prefer to use the CLI, open the appropriate terminal, and navigate to the project directory. On Windows, use the command-line 'modus-shell' program; on Linux and macOS, you can use any terminal application. From there, you can run various make commands.

For more details, see the ModusToolbox™ tools package user guide (locally available at {ModusToolbox™ install directory}/docs_{version}/mtb_user_guide.pdf).

Operation

  1. Connect the XMC1300 (KIT_XMC1300_DC_V1) or XMC1400 s(KIT_XMC1400_DC_V1) Drive Card to the PC with a USB connector.

  2. To flash the code to the board, click Generate Launches for in Quick Panel.

  3. Program the board using one of the following:

    Using Eclipse IDE
    1. Select the application project in the Project Explorer.

    2. In the Quick Panel, scroll down, and click <Application Name> Program (JLink).

    In other IDEs

    Follow the instructions in your preferred IDE.

    Using CLI

    From the terminal, execute the make program command to build and program the application using the default toolchain to the default target. The default toolchain is specified in the application's Makefile but you can override this value manually:

    make program TOOLCHAIN=<toolchain>
    

    Example:

    make program TOOLCHAIN=GCC_ARM
    
  4. Close if ModusToolbox™ Motor Suite is opened already. In the ModusToolbox™ Project window, click the xmc1_motorsuite.mcws file and open it to access the ModusToolbox™ Motor Suite.

    Figure 2. Opening the ModusToolbox™ Motor Suite file

  5. Navigate to the project build path (C:<Users\Username>\PMSM_FOC_SL_XMC13_14\build\last_config) and open your project elf file as shown in Figure 3.

    Figure 3. Opening the project elf file

  6. For optimum ModusToolbox™ Motor Suite view, adjust it in full screen mode. To run the motor, click the Motor Start/Stop switch in the GUI as shown in Figure 4. Observe that the motor should start and automatically go to FOC closed loop mode in 1000 RPM by default. You can also adjust the motor speed by adding a value to the Target Speed, or changing the speed via the Target Set slide. You can also observe and adjust the motor control parameters from the Motor Tuning table.

    Figure 4. Motor Suite GUI start

  7. Additionally, there is an option to view the FOC variables from the GUI using the Oscilloscope option. Click Oscilloscope on the upper right corner of the GUI to launch it. In the Oscilloscope window, you can select the Auto Scale option for the selected parameters to view. Also from the bottom side of the window in Scope Settings, you can select the parameter that you want to observe in real time as shown in Figure 5.

    Figure 5. FOC parameters in Oscilloscope tab

Debugging

You can debug the example to step through the code.

In Eclipse IDE

Use the <Application Name> Debug (Jlink) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ user guide.

In other IDEs

Follow the instructions in your preferred IDE.

Design and implementation

This code example executes an FOC algorithm with a Nanotec motor using XMC1300 or XMC1400 Drive Card. Observe the motor control parameters and tune using Infineon's Motor Suite as explained in Operation section.

Resources and settings

This code does not use the Device Configurator in ModusToolbox™. All peripheral definitions and initializations are directly integrated within the software using low-level drivers by calling the necessary libraries. When you want to change a configuration variable or parameter, do within the code in the user config header files rather than in the Device Configurator.

Figure 6. Device Configurator in ModusToolbox™

For more details, see the Eclipse IDE for ModusToolbox™ software user guide.

Related resources

Resources Links
Application notes AP32370 – PMSM FOC motor control using XMC™ MCUs
Kit guide XMC1300 Drive Card - KIT_XMC1300_DC_V1 board user's manual
Code examples Using ModusToolbox™ on GitHub
Device documentation XMC1000 family datasheets
XMC1000 family reference manuals
Development kits Select your kits from the Evaluation board finder.
Libraries on GitHub mtb-xmclib-cat3 – XMC™ Peripheral Driver Library (XMCLib) and docs
Tools ModusToolbox™ – ModusToolbox™ software is a collection of easy-to-use libraries and tools enabling rapid development with Infineon MCUs for applications ranging from wireless and cloud-connected systems, edge AI/ML, embedded sense and control, to wired USB connectivity using PSOC™ Industrial/IoT MCUs, AIROC™ Wi-Fi and Bluetooth® connectivity devices, XMC™ Industrial MCUs, and EZ-USB™/EZ-PD™ wired connectivity controllers. ModusToolbox™ incorporates a comprehensive set of BSPs, HAL, libraries, configuration tools, and provides support for industry-standard IDEs to fast-track your embedded application development.

Other resources

Infineon provides a wealth of data at www.infineon.com to help you select the right device, and quickly and effectively integrate it into your design.

For XMC™ MCU devices, see 32-bit XMC™ industrial microcontroller based on Arm® Cortex®-M.

Document history

Document title: CE240999PMSM FOC SL XMC1300, XMC1400 Drive Card

Version Description of change
1.0.0 New code example

------

All other trademarks or registered trademarks referenced herein are the property of their respective owners.

The Bluetooth® word mark and logos are registered trademarks owned by Bluetooth SIG, Inc., and any use of such marks by Infineon is under license.

PSOC™, formerly known as PSoC™, is a trademark of Infineon Technologies. Any references to PSoC™ in this document or others shall be deemed to refer to PSOC™.

© 2025 Infineon Technologies AG

All Rights Reserved.

Legal disclaimer

The information given in this document shall in no event be regarded as a guarantee of conditions or characteristics. With respect to any examples or hints given herein, any typical values stated herein and/or any information regarding the application of the device, Infineon Technologies hereby disclaims any and all warranties and liabilities of any kind, including without limitation, warranties of non-infringement of intellectual property rights of any third party.

Information

For further information on technology, delivery terms and conditions and prices, please contact the nearest Infineon Technologies Office (www.infineon.com).

Warnings

Due to technical requirements, components may contain dangerous substances. For information on the types in question, please contact the nearest Infineon Technologies Office.

Infineon Technologies components may be used in life-support devices or systems only with the express written approval of Infineon Technologies, if a failure of such components can reasonably be expected to cause the failure of that life-support device or system or to affect the safety or effectiveness of that device or system. Life support devices or systems are intended to be implanted in the human body or to support and/or maintain and sustain and/or protect human life. If they fail, it is reasonable to assume that the health of the user or other persons may be endangered.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published