Main Content

Field-Oriented Control of BLDC with Encoder Using Infineon AURIX Microcontrollers

This example shows you how to implement the field-oriented control (FOC) technique to control the speed of a three-phase brushless DC (BLDC) motor. The FOC algorithm requires rotor position feedback, which is obtained by using an encoder sensor. For more details about FOC, see Field-Oriented Control (FOC) (Motor Control Blockset).

A closed-loop FOC algorithm is used to regulate the speed and torque of a three-phase brushless DC (BLDC) motor. You can use this example to implement position control applications by using closed-loop FOC. The example drives the motor to reach the speed value. This example uses AURIX™ peripheral blocks from the SoC Blockset® Support Package for Infineon® AURIX™ Microcontrollers and MCB library blocks from Motor Control Blockset.


Complete the following tutorials:

Required Hardware

  • Infineon AURIX™ TC4x - TriBoards

  • AURIX™ TC3xx Motor Control Power Board

  • Nanotec DB42S02 Electric motor

  • WEDL5541-B14-KIT (5 mm) Incremental Encoder

Hardware Connection

Connect the required hardware as shown in this diagram.

Available Model

The example includes the tc4x_mcb_pmsm_foc_encoder model.

You can use this model for both simulation and code generation. This model is configured for the TC4x TriBoards.

You can change the model parameters to fit your specific motor. The controller algorithm generates space vector PWM signals to drive the inverter switches. The inverter measures the current of the two motor inputs (ia and ib) input currents to the motor (ia and ib) using two analog-to-digital converters (ADCs) and sends the measurements to the processor.

This example uses the encoder sensor to measure the rotor position. The encoder sensor consists of a disk with two tracks or channels that are coded 90 electrical degrees out of phase. This creates two pulses (A and B) that have a phase difference of 90 degrees and an index pulse (I). The controller uses the phase relationship between A and B channels and the transition of channel states to determine the direction of rotation of the motor.

Configure the Model

1. Open the tc4x_mcb_pmsm_foc_encoder model.

2. Press Ctrl+E to open the Configuration Parameters dialog box. Click Hardware Implementation in the left pane. Set Hardware board to Infineon AURIX™ TC4x - TriBoards.

3. Under Hardware board settings, expand Target hardware resources. Set the Series and Package class parameters to match your hardware.

Peripheral Block Configurations

Set the peripheral block configurations for this model using the Hardware Mapping tool.

1. In the Simulink toolstrip, go to Hardware tab and click Hardware Mapping.

2. The following figure shows the PWM peripheral block configuration in Hardware Mapping tool. Similarly the model is configured for other peripherals. A preconfigured model is included for your convenience.

Simulate Model

Complete the following steps to simulate the model.

1. Open a model included with this example.

2. Click Run on the Simulation tab to simulate the model.

3. Click Data Inspector on the Simulation tab to view and analyze the simulation results.

4. Observe the speed feedback following the reference set point.

5. Run the model in open loop for 1 second and switch to closed loop with 0.25 and 0.9 speed per unit for 20 sec.

Generate Code and Deploy Model to Target Hardware

Complete the following steps to generate code and run the FOC algorithm on the target hardware.

1. Open tc4x_mcb_pmsm_foc_encoder model.

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

3. Follow the build process by opening the diagnostic viewer using the link provided at the bottom of the model canvas. You can observe the code generation report that contains code for model traceability. Infineon AURIX deploys the model to the hardware using a downloading tool.

Note: You can ignore the model advisor warning message while trying to build the model.

4. Download and install the One Eye tool from Infineon to monitor signals from the hardware. Before using the One Eye tool, ensure that you download and install the latest version of the DAS tool.

5. Open the One Eye tool. Load tc4x_mcb_pmsm_foc_encoder.OneEye file shipped with this example by clicking File > Load Configuration in the One Eye tool.

6. Load the tc4x_mcb_pmsm_foc_encoder.elf file generated in Step 3 and observe the measured currents (Iab_fb_PU1, Iab_fb_PU0), speed feedback (Speed_fb) following the reference set point (SpeedRef).

Known Limitation

This example model does not support simulation in Accelerator and Rapid Accelerator modes due to the lack of support for peripheral blocks in these modes.

More About: