# Estimate Initial Rotor Position Using Pulsating High-Frequency and Dual-Pulse Methods

This example estimates initial position (in electrical radians) of a stationary interior PMSM by using pulsating high frequency (PHF) injection and dual pulse (DP) techniques.

The example determines the best possible initial estimation for the rotor position using open-loop PHF injection, which it uses further for running closed-loop PHF.

It executes closed-loop PHF by injecting a high frequency signal into the estimated rotor position to determine the actual rotor position, without spinning the motor. This technique works when the motor has a saliency ratio (Lq/Ld) greater than 1. Due to a limitation in the PHF method, the estimated position may show ambiguity of π(pi). The dual-pulse (DP) method uses polarity detection to resolve the ambiguity of π and applies π compensation if there is an error. The estimated rotor position ranges from 0 to 2π electrical radians.

The example uses the Pulsating High Freq Observer block to implement the position estimation algorithm. For more details, see Pulsating High Freq Observer.

The example runs only for Stage 1 - initial position estimation (IPE) (as defined in the Pulsating High Freq Observer block page), which includes 3 parts.

Stage 1 focuses on determining the initial position of rotor when the rotor is stationary. This stage includes the following 3 parts:

Note: Stage 2 is an extended operation mode where you can use this technique to compute position while the motor runs using closed loop control. The example does not cover Stage 2.

Part A: Find best possible initial estimation

The example relies on pulsating high frequency (PHF) injection technique. PHF injection needs initial estimation to start the algorithm.

When we use only one initial estimation, , (for PHF) for all possible rotor actual positions, the algorithm may not work accurately for certain rotor actual positions if motor has low saliency. These ambiguous positions are:

1. When lies in the range

2. When lies in the range

3. When lies in the range

To make PHF work for motors with low saliency, we need to pick different initial estimation for different rotor actual positions.

When executing this part, the example picks the best possible initial estimation among these three alternatives:

1.

2.

3.

Therefore, the example injects 3 high frequency voltage signals (approximately 2000 KHz) across the preceding 3 values and measures the resulting currents. For each :

Therefore, or .

Where,

— initial estimation of rotor position (which can be either 0, , or - (in degrees, per-unit, or radians)

— actual rotor position (in degrees, per-unit, or radians)

Let us define:

for

for

for

For , when we vary from 0 to 2π, we find that is maximum among the preceding 3 currents when the rotor lies in the following 4 highlighted regions.

If is used for all = 0 to 2π, the algorithm would have failed for the following ambiguous regions (when motor saliency is low):

1. When lies in the range

2. When lies in the range

3. When lies in the range

Because these ambiguous regions are not present in the preceding 4 regions, we eliminate the regions where the algorithm might fail.

For , when we vary from 0 to 2π, we find that is maximum among the 3 currents when the rotor lies in the following 4 highlighted regions.

If is used for all = 0 to 2π, the algorithm would have failed for following ambiguous regions (when motor saliency is low):

1. When lies in the range

2. When lies in the range

3. When lies in the range

Because these ambiguous regions are not present in the preceding 4 regions, we eliminate the regions where the algorithm might fail.

For , when we vary from 0 to 2π, we find that is maximum among the 3 currents when the rotor lies in the following 4 highlighted regions.

If is used for all = 0 to 2π, the algorithm would have failed for the following ambiguous regions (when motor saliency is low):

1. When lies in the range

2. When lies in the range

3. When lies in the range

Because these ambiguous regions are not present in the preceding 4 regions, we eliminate the regions where the algorithm might fail.

Therefore, using this approach we have three sets of regions corresponding to 3 different initial estimates. These three sets or regions cover all the motor sectors where the rotor may lie:

In part A, the example picks the corresponding to the maximum current value among , , and for Part B.

Part B: Pulsating High-Frequency (PHF) Method

After determining the best possible initial estimate , the example injects a sinusoidal high-frequency voltage along the finalized (resulting in unbalanced three-phase voltage in the motor) and reads the current response from the motor. The example then performs numerical analysis of the resulting stator current response to compute the initial position of the stationary rotor (in electrical radians) by making corrections to .

The example performs iterative tests on the motor. Therefore, when the example executes, the estimated position is initially , but it rises steadily to saturate at the actual rotor-angle (with respect to a-axis).

The PHF method has a limitation due to which it might compute rotor position with an ambiguity of π. If the rotor lies in the range electrical radians (region 1), the estimated position is accurate (π compensation is not required).

If the rotor lies in the range electrical radians (region 2), the estimated position shows an ambiguity of π (π compensation is required).

Therefore, the example uses the dual-pulse method to determine if the estimated position needs π compensation.

Part C: Dual-Pulse (DP) Method

The example injects two very short duration voltage pulses (with the same width and magnitude) into the following positions:

• Pulse-1 that uses the rotor position estimated in Part B

• Pulse-2 that uses the rotor position estimated in Part B + π

Because pulse width is very short, the motor does not run and the rotor remains stationary after pulse injection.

The interaction between the resulting stator magnetic flux and the rotor permanent magnets result in two current impulses along the d-axis of the rotor that rise and fall quickly.

Because the stator core is saturated, it shows a nonlinear behavior. A small results in higher current , and a high results in smaller current . Therefore the current impulses generated by Pulse-1 and Pulse-2 show different peak values.

Note: The pulse duration of the injected voltage pulses is large enough to obtain a measurable difference between the peak current values. At the same time the duration is not too high (when the pulse duration exceeds a certain limit, the rotor may start spinning).

The example computes the difference between the peak values of the two current impulses to determine if the position estimated in Part B needs π compensation.

PHF injection benefits the use cases that require rotor to remain stationary or when the position estimation must occur without starting the motor. PHF injection technique also benefits cases where open loop runs to estimate position (before transition to closed loop speed control) needs to be avoided or requirements where the motor should begin directly in closed loop operation. Stage 1 algorithm addresses these use cases by estimating position while keeping the rotor stationary and avoiding open loop run.

Note:

You can update the Pulsating High Freq Observer block parameters using the block mask. For details, see Pulsating High Freq Observer.

Alternatively, you can also update the variables defined in the model initialization script mcb_ipmsm_pos_est_f28379d_data.m to customize the algorithm.

The example also computes the following attributes using the motor parameters specified in the model initialization script:

1. PHF voltage frequency,

2. PHF peak voltage,

3. Duration of open-loop PHF injection during Stage 1 Part A, and duration between algorithm steps (belonging to Stage 1 Part A and Stage 1 Part B) to allow fading of transient dynamics,

4. Cut-off frequency for low-pass filter of PHF,

5. Proportional gain for PI controller of PHF, and integral gain for PI controller of PHF,

6. Voltage amplitude of injected pulses,

7. Duration of injected pulses, and duration between two pulses during dual pulse injection,

Where,

— Sampling time used by the example

— Stator d-axis inductance

— Stator q-axis inductance

— Stator resistance

— Base voltage for per-unit computation

— Base current for per-unit computation

— Maximum count of the ADC

— Base current of the control system

— Amount of time takes to settle

δ — Damping ratio of second order equivalent of PHF

Note that the example supports both floating point and fixed point data-types.

### Model

The example includes the target model mcb_ipmsm_pos_est_f28379d.

You can simulate this model or run it on the hardware. Use the open_system command to open the model.

open_system('mcb_ipmsm_pos_est_f28379d.slx'); 

Required MathWorks® Products

• Motor Control Blockset™

• Embedded Coder®

• Embedded Coder Support Package for Texas Instruments C2000™ Processors

• Simscape™ Electrical™ (only for simulation)

### Prerequisites

1. Determine the motor parameters. The target model uses default parameters that you can replace with values from either the motor datasheet or other sources.

However, if you have motor control hardware, you can estimate the parameters for your motor by using the Motor Control Blockset parameter estimation tool. For instructions, see Estimate PMSM Parameters Using Recommended Hardware. The parameter estimation tool updates the motorParam variable (in the MATLAB® workspace) with the estimated motor parameters.

2. Update the motor and inverter parameters in the model initialization script associated with the target model. For instructions, see Estimate Control Gains and Use Utility Functions.

### Simulate Model

Follow the instructions in the Simulate Nonlinear Stator Core Behavior section to introduce high saliency in the motor block. Then follow these steps to simulate the target model.

1. Open the target model included in this example.

2. Enter the initial rotor position value (that the Interior PMSM block should use for simulation) in the Input electrical rotor position (radians) field available in the Simulation Input & Output area of the target model.

3. Click Run on the Simulation tab to simulate the target model. The model estimates the rotor position using the PHF method. Then it uses the DP method to determine if the estimated rotor position needs π compensation. The target model applies π compensation if needed.

It then displays the estimated rotor position in the Estimated electrical rotor position (radians) field.

4. Observe the logged signals in the Simulation Data Inspector.

This plot shows the current along the d-axis during simulation.

This plot shows the estimated rotor position when the target model does not apply π compensation and when the target model applies π compensation .

5. The Estimated Rotor Position (Electrical Radians) display block in the Output area of the target model shows the initial rotor position estimated by the target model.

### Generate Code and Deploy Model to Target Hardware

Follow the instructions in this section to generate code and run the example on the target hardware.

This example uses a host and a target model. The host model is a user interface to the controller hardware board. You can run the host model on the host computer. Before you can run the host model on the host computer, deploy the target model to the controller hardware board. The host model uses serial communication to command the target Simulink® model and run the motor in closed-loop control.

Required Hardware

The example supports this hardware configuration. You can also use the target model name to open the model from the MATLAB® command prompt.

LAUNCHXL-F28379D controller + BOOSTXL-DRV8305 inverter + iPMSM (such as Adlee BM-180 motor): mcb_ipmsm_pos_est_f28379d

For connections related to this hardware configuration, see LAUNCHXL-F28069M and LAUNCHXL-F28379D Configurations.

Generate Code and Run Model on Target Hardware

1. Simulate the target model and observe the simulation results.

2. Complete the hardware connections.

3. By default, the model computes the ADC offset values for phase current measurement. To disable this functionality, update the value of the inverter.ADCOffsetCalibEnable variable in the model initialization script to 0.

Alternatively, you can compute the ADC offset values and update them manually in the model initialization script. For instructions, see Run 3-Phase AC Motors in Open-Loop Control and Calibrate ADC Offset.

4. Open the target model. If you want to change the default hardware configuration settings for the model, see Model Configuration Parameters.

5. Load a sample program to CPU2 of the LAUNCHXL-F28379D board. For example, load the program that operates the CPU2 blue LED by using GPIO31 (c28379D_cpu2_blink.slx). This ensures that CPU2 is not mistakenly configured to use the board peripherals intended for CPU1.

6. Click Build, Deploy & Start on the Hardware tab to deploy the target model to the hardware. Verify the variables that the target model adds to the workspace.

7. Click the host model hyperlink in the target model to open the associated host model. You can also use the open_system command to open the host model.

open_system('mcb_ipmsm_pos_est_f28379d_host_model.slx'); 

For details on serial communication between the host and target models, see Host-Target Communication.

8. In the host model, open the blocks Host Serial Setup, Host Serial Receive, and Host Serial Transmit, and select a Port

9. Click Run on the Simulation tab to run the host model.

10 Change the position of the Estimate Position switch to Start to start running the example algorithm. The target model estimates the rotor position using PHF method. Then it uses the DP method to determine if the estimated rotor position needs π compensation. The target model applies π compensation if needed.

The host model obtains the estimated rotor position from the target hardware and displays it in the Estimated rotor electrical position (radians) field.

11 To estimate a different rotor position, change the position of the Estimate Position switch to Stop. The Estimated rotor electrical position (radians) field displays the value 0.

Turn the motor shaft to a new position. Then change the position of the Estimate Position switch to Start to run the example algorithm again and estimate the new position.

12 Observe the estimated position, Id, and Iq signals in the time scope available in the host model.

This plot shows the estimated rotor electrical position () and the stator currents (Id) and (Iq).

13 The Status field displays the following statuses:

• "IPE not started" — Stage 1 operation not yet started.

• "IPE running" — Stage 1 operation is presently running.

• "IPE completed" — Stage 1 operation is complete.

• "IPE failed" — Stage 1 operation failed due to high error in estimated position.

### Simulate Nonlinear Stator Core Behavior

The DP method algorithm works only when the stator core saturates and shows a nonlinear behavior. To generate this behavior in simulation, the target model uses the PMSM (Simscape Electrical) block from Simscape™ Electrical™. Follow this procedure to experimentally determine the tabulated , , and data for the actual motor and use this data to make the motor block nonlinear for simulation purposes.

Determine Data

1. Create a target model to run a PMSM using open-loop control. Modify the algorithm so that it injects the voltages and into the actual motor. This generates the current in the motor where:

is the voltage that the algorithm computes and injects along the rotor's d-axis.

is the frequency at which we can measure the phase difference. This frequency should be approximately 10 times lower than the PWM switching frequency but should be high enough to keep the rotor stationary (a frequency value that is too low can spin the rotor).

is the AC component of (such that and ω are constants that the algorithm should assume).

is the DC component of that you provide as an input.

is the current along the d-axis of the rotor that the algorithm computes from the measured and phase currents.

is the AC component of (ϕ is the phase difference between and that the algorithm should measure).

is the DC component of , which is fixed for a input (the algorithm should compute this value by using and the motor resistance).

Note: Because , the rotor remains stationary.

a. Add an algorithm to read the and phase currents that the motor draws.

b. Add an algorithm to convert the and phase current values into the equivalent value by using Clarke and Park transforms.

c. Add an algorithm to compute ϕ and .

d. Add an algorithm to compute .

e. Add an algorithm to compute .

(for a fixed )

For details about designing a control algorithm and configuring it for deployment to the target hardware, see Control Algorithm Design and Deployment and Validation.

2. Create a model initialization script (.m file) to initializate the paramters and perform other calculations. Use the Model Properties > Callbacks to integrate this script with the target model. For details about how Motor Control Blockset™ uses this script, see Estimate Control Gains and Use Utility Functions.

3. Configure the target model to run on the target hardware. For instructions, see Model Configuration Parameters.

4. Create a separate host model to control and communicate with the target model running on the motor-control hardware in real-time. You can add an Edit box on the host model and use it to send input to the target hardware. Use Display boxes to obtain the computed and values from the target hardware.

For details about the host-target communication interface, see Host-Target Communication.

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

6. Simulate the host model. Send a input to the target hardware and record the and values that you obtain.

7. Change manually across a range between a negative and positive voltage and record the resulting and values for each operating point.

Determine Value

Perform these steps to determine a value that is higher than the sequence of values obtained from the Determine Ld section. This is necessary to maintain a high saliency ratio () for the simulated motor block.

1. Modify the target model that you used in the Determine Ld section so that it injects the voltages and into the actual motor. This generates a current in the motor where:

is the constant DC voltage that the algorithm injects along the d axis of the rotor. should be high enough to hold the rotor at zero position and keep it stationary.

is the AC voltage that the algorithm computes and injects along the q-axis of the rotor. (such that and ω are constants that the algorithm assumed in the Determine Ld section)

is the AC current along the q-axis of the rotor that the algorithm computes from the measured and phase currents (ϕ is the phase difference between and that the algorithm should measure)

a. Update the existing algorithm to convert the and phase current values into the equivalent value by using Clarke and Park transforms.

b. Update the existing algorithm to compute ϕ.

c. Update the existing algorithm to compute .

d. Add an algorithm to compute .

2. Update the model initialization script to perform the preceding modified calculations.

3. Update the host model to obtain and display the value computed by the target hardware.

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

5. Simulate the host model. Send a input to the target hardware and record the value that you obtain.

Design High Saliency Motor Block

Sections Determine Ld Data and Determine Lq Value provide the following data:

• Sequence of values

• Sequence of ( for a DC current) values

• Constant value

In addition, we can assume a set of values that we can use to add high saliency to the motor block.

Use the variables pmsm.nonlin.idVec, pmsm.nonlin.Ld_data, pmsm.nonlin.iqVec, and pmsm.nonlin.Lq_data to store this data in the model initialization script mcb_ipmsm_pos_est_f28379d_data.m associated with the example target model mcb_ipmsm_pos_est_f28379d.slx.

Note: This script is different from the model initialization script used in sections Determine Ld Data and Determine Lq Value.

In addition, define the variables pmsm.nonlin.LdMatrix, pmsm.nonlin.LqMatrix, and pmsm.nonlin.PmMatrix.

In the PMSM (Simscape Electrical) block parameter dialog box, set the Modeling fidelity parameter to Tabulated Ld, Lq and PM and add these variables as shown in the following figure.

The variables pmsm.nonlin.idVec, pmsm.nonlin.Ld_data, pmsm.nonlin.iqVec, and pmsm.nonlin.Lq_data help saturate the stator core and introduce a nonlinear behavior during simulation. This enables the algorithm of the DP method to generate the current impulses (corresponding to Pulse-1 and Pulse-2) with different peaks.

### References

[1] W. Zine, L. Idkhajine, E. Monmasson, Z. Makni, P. Chauvenet, B. Condamin, and A. Bruyere, "Optimisation of HF signal injection parameters for EV applications based on sensorless IPMSM drives", IET Electric Power Applications, Volume 12, Issue 3, March 2018, p. 347 - 356 (doi:10.1049/iet-epa.2017.0228).

[2] Gaolin Wang, Guoqiang Zhang, and Dianguo Xu, "Position Sensorless Control Techniques for Permanent Magnet Synchronous Machine Drives", Springer, Singapore, 2020 p. 41 - 43 (doi: https://doi.org/10.1007/978-981-15-0050-3).