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 Embedded Coder® Support Package for Infineon® AURIX™ TC3x Microcontrollers and MCB library blocks from Motor Control Blockset.


Complete the following tutorials:

Required Hardware

  • Infineon AURIX TC387 Application Kit

  • 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 tc3x_mcb_pmsm_foc_encoder model.

You can use this model for both simulation and code generation. This model is configured for the TC387 Application Kit.

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 input currents to the motor $({i_a }, {i_b })$ 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 tc3x_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™ TC3x.

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.

During the simulation:

  • For the first 0.5 seconds, run the motor to calibrate the ADC current.

  • For the next 1 second, operate the motor in open loop to set up for offset calibration.

  • Spend the following 1 second calibrating the encoder offset.

  • At 2.5 seconds, switch to closed loop operation at 0.1 speed per unit, and then increase to 0.25 speed per unit at 4 seconds.

  • Apply the load at 6 seconds and continue to run the motor at 0.25 speed per unit and switch to 0.9 speed per unit at t=8 seconds.

Observe the speed feedback following the reference set point.

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. Click Build, Deploy & Start on the Hardware tab to deploy the target model to the hardware.

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

2. Infineon AURIX™ uses a downloading tool to deploy the model on the hardware.

3. You can observe the code generation report that contains code to model traceability or vice versa.

4. Use the One Eye tool from Infineon to monitor the signal from the hardware.

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.

See Also