Main Content

Field-Oriented Control of BLDC with Encoder Using Infineon AURIX TC3xx 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.

Prerequisites

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. Open tc3x_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 TC3x_MotorControl.OneEye file shipped with this example by clicking File > Load Configuration in the One Eye tool.

6. Load the tc3x_mcb_pmsm_foc_encoder.elf file generated in Step 3 and observe feedback current following (Iq_fb) the reference set point (Iq_ref), speed feedback (Speed_fb) following the reference set point (SpeedRef).

You can also view Iq_fb, Iq_ref, Speed_fb, and SpeedRef signal values in the circular gauges during simulation.

Monitor and Tune the Model

1. Open the tc3x_mcb_pmsm_foc_encoder model

2. Specify the COM Port. To see a list of available COM ports on your computer, select Start > Control Panel > Device Manager > Ports (COM &LPT).

3. In your Simulink model, press Ctrl+E or click Modeling > Model Settings to open the Configuration Parameters dialog box. Navigate to Hardware Implementation > Target hardware resources > Connectivity. Set Connectivity interface to Serial(ASCLIN0) for external mode.

4. On the Hardware tab, click Monitor & Tune to configure the model for simulation. At this point, your model runs on the Infineon AURIX TC387 Application Kit and communicates with Simulink so that you can monitor and tune the parameters (Iq_ref, SpeedRef).

5. On the Simulation tab, click Data Inspector to observe the feedback current following (Iq_fb) the reference set point (Iq_ref), speed feedback (Speed_fb) following the reference set point (SpeedRef). signals.

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