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™ TC4x Microcontrollers and MCB library blocks from Motor Control Blockset™.
Complete the following tutorials:
Infineon AURIX™ TC4x - TriBoards
AURIX™ TC3xx Motor Control Power Board
Nanotec DB42S02 Electric motor
WEDL5541-B14-KIT (5 mm) Incremental Encoder
Connect the required hardware as shown in this diagram.
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.
To open the model, type the following command in the MATLAB® prompt.
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.
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. 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.