Skip to content

Infineon/mtb-example-xmc-foc-3-shunt

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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

XMC™ MCU: MOTIX™ 6EDL7141 and IMD700A sensorless FOC 3-shunt

This code example works with both the MOTIX™ 6EDL7141 3-shunt field oriented control (FOC) sensorless and MOTIX™ IMD700A 3-shunt FOC sensorless projects in the MOTIX™ Battery Powered Application (BPA) Motor Control Workbench to illustrate sensorless FOC motor control on EVAL_6EDL7141_FOC_3SH and EVAL_IMD700A_FOC_3SH evaluation boards for FOC motor drive based on the MOTIX™ 6EDL7141 smart 3-phase driver and MOTIX™ IMD701A motor controller IC.

Requirements

Supported toolchains (make variable 'TOOLCHAIN')

  • GNU Arm® Embedded Compiler v10.3.1 (GCC_ARM) - Default value of TOOLCHAIN

Supported boards (make variable 'TARGET')

Hardware setup

This example uses the board's default configuration. See the board user guide to ensure that the board is configured correctly.

Software setup

See the ModusToolbox™ tools package installation guide for information about installing and configuring the tools package.

This example is compatible with the MOTIX™ BPA Motor Control Workbench software. Before you can install this tool, install the Infineon Developer Center Launcher application. To interact with the MOTIX™ BPA Motor Control Workbench, see the Design and implementation section. This code example can be compiled in Debug mode to ensure the full compatibility features with the MOTIX™ BPA Motor Control Workbench.

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-xmc-foc-3-shunt" application with the desired name "Sensorless_FOC_3_Shunt" configured for the EVAL_IMD700A_FOC_3SH BSP into the specified working directory, C:/mtb_projects:

project-creator-cli --board-id EVAL_IMD700A_FOC_3SH --app-id mtb-example-xmc-foc-3-shunt --user-app-name Sensorless_FOC_3_Shunt --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 board to your PC using a Micro-USB cable through the debug USB connector.

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

Download the hex code without error.

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 more 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 example runs a BLDC motor using sensorless FOC motor control. Then, the hex code generated by this code example can be downloaded to the EVAL_6EDL7141_FOC_3SH or EVAL_IMD700A_FOC_3SH board via the MOTIX™ BPA Motor Control Workbench.

To customize the code example for your application, expand the Application Notes folder in the Documents section, AN_2110_PL88_2202_070459 - PMSM FOC motor control software using MOTIX™ 6EDL7141 and MOTIX™ IMD700A.

With the MOTIX™ BPA Motor Control Workbench, you can configure the following options:

  • Select the control mode as one of the following:

    • Speed control mode
    • Voltage control mode
  • Select motor stop/run and set the target speed using one of the following:

    • Onboard potentiometer
    • Direct variable write
  • Protections:

    • DC link overvoltage protection
    • DC link undervoltage protection

MOTIX™ 6EDL7141 smart gate driver support

  • Low-level read/write MOTIX™ 6EDL7141 registers through the SPI interface
  • High-level 6EDL gateway provides an interface to the application code

MOTIX™ BPA Motor Control Workbench's oscilloscope support

  • 4-channel scope
  • Trace signal of each channel can be changed on-the-fly

Supported motor

This board and application support 3-phase BLDC motors (rated voltage 24 V DC).

Correct motor connection

This board supports 3-phase BLDC/PMSM motors. Connect the motor's phase U, V, and W cables to the board as follows:

Table 1. Motor's phase connection

Motor Board
Phase U U (J3)
Phase V V (J4)
Phase W W (J5)

Basic operations

Motor control operation

  • Change the control scheme, define the USER_FOC_CTRL_SCHEME macro to either (SPEED_INNER_CURRENT_CTRL) or (VQ_VOLTAGE_CTRL) in the user_input_config.h file. For example:

    #define USER_FOC_CTRL_SCHEME   SPEED_INNER_CURRENT_CTRL // Sets to speed control mode
    

    or

    #define USER_FOC_CTRL_SCHEME   VQ_VOLTAGE_CTRL      // Sets to voltage control mode
    
  • Enable onboard potentiometer control for motor start/stop and target setting. Motor direction is controlled by the direction switch on the board (SW1).

  • To enable the motor control with the potentiometer, define the USER_REF_SETTING macro as (ENABLED) in user_input_config.h. For example:

    #define USER_REF_SETTING         (ENABLED) // Enables onboard potentiometer control
    
  • To disable motor control with the potentiometer, define the USER_REF_SETTING macro as (DISABLED) in the user_input_config.h file. For example:

    #define USER_REF_SETTING         (DISABLED) // Disables onboard potentiometer control
    

    When potentiometer control is disabled, motor start/stop and target setting change are controlled through a variable write:

    • To start the motor:
    PMSM_FOC_MotorStart();                   // Sets motor_start flag
    ADC.adc_res_pot = 2048;                  // Sets adc_res_pot to 2048 = 50% nominal speed (speed mode) or 50% duty cycle (voltage mode)
    
    • To stop the motor:
    ucProbe_cmd = 16;  // Sets motor stop command
    

    Scaling of ADC.adc_res_pot is Q12(4096=1PU), which means that ADC.adc_res_pot at the max value is 4096.

    • In voltage control mode, the torque Vq PMSM_FOC_INPUT.ref_vq controls the output duty cycle (32768 = 100% output duty cycle).

    • In speed control mode, the reference speed PMSM_FOC_INPUT.ref_speed controls the motor speed (32768 = motor maximum speed); the actual motor speed can be read from the PMSM_FOC_OUTPUT.rotor_speed variable.

  • The fault status can be read from MotorVar.error_status (unmasked faults) or MotorVar.MaskedFault (masked faults). Bitfields set in MotorVar.error_status mean that faults are present. Control will enter the FAULT state only if the fault is enabled and the bitfields are set in the MotorVar.MaskedFault masked fault variable. In other words, only an enabled fault can trigger the state machine to enter the FAULT status. In firmware, the masked fault is calculated as follows:

    MotorVar.MaskedFault.Value = MotorVar.error_status & MotorParam.EnableFault
    
  • A fault can be enabled/disabled by setting/clearing the corresponding bit in the MotorParam.EnableFault parameter. Its value is calculated by the Motor Control Workbench.

  • To clear the fault, do one of the following:

    • Option 1: Write ucProbe_cmd to '3'. After this command is received, the firmware will write MotorVar.fault_clear to '1'.
    ucProbe_cmd = 3;  // Control word 3: clear fault. Firmware will then set `MotorVar.fault_clear` to '1' after receiving this control word command
    
    • Option 2 (Preferred): Directly write MotorVar.fault_clear to '1'.
    MotorVar.fault_clear = 1;                     // Directly sets the clear fault flag
    
  • The detected faults will be stored in a different bit position of the 'MotorVar.error_status' variable. E.g., a '1' at bit 12 position indicates nFault from 6EDL7141 detected, a '1' at bit 10 position indicates DC link undervoltage detected, a '1' at bit 4 position indicates DC link overvoltage detected.

  • Board temperature from MCP9700 is sampled, filtered, and converted to degree celsius. To read the board temperature:

    int degreeC_x16 = MotorVar.t_sensor;  // Degree celsius temperature in Q4, 16 counts = 1°C e.g., 0 = 0°C, 160 = 10°C, 320 = 20°C
    

Managing the parameters

There are two types of parameters:

  • User input: User input parameters are usually presented in engineering units (volt, amps, RPM, etc.) which can be configure based on the application requirements.

  • Internal parameters: Internal parameters are actual parameters that are being used by the firmware. Most internal parameters use different scaling to ensure efficient code execution and cannot be easy to be understood.

One key feature of the Motor Control GUI is the ability to calculate the internal parameter from the user input parameter. A conversion function is available in the firmware.

In the firmware, user inputs are #define in the Configuration/pmsm_foc_user_input_config.h header file; the conversion function is in the C source file, ToolInterface/Register.c.

All internal parameters related to motor control are grouped in the MotorParam data structure; configure this structure correctly before the motor could run. Use the MOTIX™ BPA Motor Control Workbench to enter the user input and let the tool calculate the internal parameter value, and then click Write Parameter to write all internal parameters into the MCU's RAM. After completing this step, the motor should be ready to run.

You can save the parameters into the MCU so that the next time when the board powers up, the motor is ready to run immediately. A location inside the MCU's flash memory is designated for storing the internal parameters. Click Write to Flash in the MOTIX™ Motor Control Workbench to store the internal parameters into the flash memory.

All 6EDL7141 config registers are handled in a similar way.

To write both MotorParam and Edl7141Reg into the flash, set the control word to '4':

ucProbe_cmd = 4;    // Control word 4: program parameter RAM value into flash memory

Using the oscilloscope

Scope traces are no longer selected in the oscilloscope page. The register map defined in the Register.c file contains the TraceID, variable, data type, and bit field (if in use). Change ProbeScope_Chx.TraceId (x = 1, 2, 3, or 4) to select a different trace signal for each scope channel so that the MOTIX™ Motor Control Workbench can select the scope signal in Test Bench view.

Controlling MOTIX™ 6EDL7141 smart gate driver and MOTIX™ IMD700A motor controller

The EN_DRV pin output level ('1' or '0') from XMC1400 MCU is controlled by EdlIo.en_drv_level. Note that the motor state machine controls the EN_DRV pin in some state changes; the EN_DRV pin control is valid only if there is no motor control state change.

The nBrake pin output level ('1' or '0') from XMC1400 MCU is controlled by EdlIo.nbrake_level. Note that the nBrake pin control is independent of motor control.

Note: EN_DRV and nBrake control are only for testing the MOTIX™ 6EDL7141 smart gate driver function. If nBrake is set to a low level manually while the motor is running, it can cause faults such as stall error. In such cases, set nBrake to a high level, clear the fault, and verify that the motor is in ‘STOP’ state before running the motor again. Do not set EN_DRV to a low level while the motor is running.

DC calibration control can be turned on or off by writing '1' or '0' to the MOTIX™ 6EDL7141 configure register bitfield CSAMP_CFG[11].

ADC input selection (Idigital/DVDD/VDDB) is written to the MOTIX™ 6EDL7141 configure register bitfield ADC_CFG[2:1].

An ADC request is initiated by writing '1' to the MOTIX™ 6EDL7141 configure register bitfield ADC_CFG[0].

Firmware code overview

This firmware code example can integrate with the MOTIX™ BPA Motor Control Workbench to provide an easy user configuration for the motor control system.

The code has stored most of the configurations in the MotorParam structure. Those parameters in this structure have internal scaling. The MOTIX™ BPA Motor Control Workbench is designed to take the user input (user input parameter) and convert it into internal parameter values in MotorParam. This means that these parameters can be changed without recompiling or reflashing the code.

If you choose not to use the MOTIX™ BPA Motor Control Workbench for parameter configuration, this process can be simulated by taking the user input into user_input_config.h file, and then converting it into internal parameter values by using the parameter_set_default() function in parameter_bldc.c file. This function will be called once during code initialization; it initializes the parameters in the MotorParam structure into default values. These values can be changed by modifying the member values in the MotorParam structure directly.

A different control scheme can be switched at the motor stop state by changing the value in MotorParam.ControlScheme.

The fault bit in error_status will not cause a motor fault unless the corresponding bit in MotorParam.EnableFault is set. In other words, error_status is masked by EnableFault; if a fault is not enabled by the EnableFault bit, the fault will not put the motor control into the ERROR state.

Resources and settings

The project uses the default design.modus file.

Known limitations

This section lists the current known limitations of the system.

Supported operating modes between the Motor Control Workbench and code example

Currently, the following two modes of operations are supported in using the MOTIX™ BPA Motor Control Workbench and the code example itself in source code form:

  • Using the MOTIX™ BPA Motor Control Workbench

    Use the MOTIX™ BPA Motor Control Workbench for evaluation of the code example performance and tuning the parameters by flashing the board using the programming features of the MOTIX™ BPA Motor Control Workbench. For this, supply both the HEX and ELF artifacts of the build to the tool following the on-screen prompts. Using this method, the tool will always overwrite the motor control parameters that are defined in the firmware source code. Therefore, editing of parameters is possible only through the MOTIX™ BPA Motor Control Workbench.

    Use all MOTIX™ BPA Motor Control Workbench features to modify the parameters, control the motor, and observe the application performance. This option is intended for early evaluation of the related kit and firmware or for fine-tuning the motor control parameters in a graphical way.

  • Using the code example in source code form with ModusToolbox™

    If you use the code example in source code format and modify the parameters of the application, motor control, or MCU, compatibility with the MOTIX™ BPA Motor Control Workbench cannot be guaranteed and can lead to unexpected behavior. This applies especially to modifying motor control parameters that are automatically overwritten in the tool as mentioned above. Use this option if you want to edit the firmware source code or tune the parameters in the source code.

Oscillation in motor RPM against the set target

In normal operation with a running motor in speed control mode, the observable motor RPM can be slightly different from the specified target speed. This variation from the target speed is dependent on the PI tuning of the control loop and whether the motor is loaded or running free.

This code example is not fine-tuned for any specific motor. Fine-tuning of the motor control parameters can be done either in firmware or by using the MOTIX™ BPA Motor Control Workbench.

Related resources

Resources Links
Application notes AN_2112_PL88_2112_011208 - EVAL_IMD700A_FOC_3SH 18 V brushless DC motor drive board
AN_2201_PL88_2202_025343 - Sensorless FOC tuning guide for BPA motor control GUI
Code examples Using ModusToolbox™ software on GitHub
Device documentation MOTIX™ 6EDL7141 datasheets; MOTIX™ IMD700A datasheets
Development kits MOTIX™ 6EDL7141 eval boards; MOTIX™ IMD700A eval boards
Libraries on GitHub mtb-xmclib-cat3 – XMC™ Peripheral Driver Library (XMCLib)
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: CE237314XMC™ MCU: MOTIX™ 6EDL7141 and IMD700A sensorless FOC 3-shunt

Version Description of change
0.5.0 Initial version
0.5.1 Bug fixes and Probe Scope update supporting arbitrary variables access from MOTIX™ BPA Motor Control Workbench. This enables users to observe any variables in Oscilloscope and Custom GUI Builder features

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.

© 2024 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