estimate pmsm parameters using custom hardware -凯发k8网页登录
this example includes an algorithm to determine the parameters of a permanent magnet synchronous motor (pmsm) using any custom motor-control hardware (hardware not used in the motor control blockset™ examples). the algorithm determines these parameters:
phase resistance, (ohm)
d
axis inductance, (henry)
q
axis inductance, (henry)
back-emf constant, (vpk_ll/krpm, where vpk_ll is the peak voltage line-to-line measurement)
motor inertia, (kg.m^2)
friction constant, (n.m.s)
the algorithm accepts the minimum required inputs and runs tests on the target hardware to estimate the pmsm parameters.
the example needs a quadrature encoder sensor to measure the rotor position and provide real-time rotor position feedback. this workflow helps you to integrate the parameter estimation algorithm with the drivers for your motor-control hardware. it supports any three-phase pmsm.
the workflow includes these four steps to prepare, deploy, and run the pmsm parameter estimation algorithm on your hardware:
1. generate code for the parameter estimation algorithm using embedded coder®
2. obtain c code for the custom hardware drivers
3. integrate parameter estimation algorithm code with the driver code
4. deploy the integrated code to hardware
note: this workflow does not support simulation. you can use any motor-control hardware to run this example.
prerequisites
ensure that the pmsm has a quadrature encoder sensor and calibrate the sensor.
the parameter estimation alogrithm needs the motor position as detected by a quadrature encoder position sensor. to detect the motor position correctly by using the sensor, calibrate the quadrature encoder that is attached to the motor under test. for instructions, see .
calibrate the offset values of the adc (or current sensor) peripheral available in your hardware. for instructions, see .
ensure that the pmsm is in no-load condition.
custom hardware configuration
controller hardware
inverter hardware
a pmsm with a quadrature encoder sensor
dc power supply
required mathworks® products
to build the parameter estimation algorithm included in this example, you need these products:
motor control blockset™
fixed-point designer™
embedded coder®
open matlab® project and prepare parameter estimation model
use one of these methods to open the matlab project:
click open example.
run the command
mcb_parameterestimationalgorithmstart
at the command prompt.
the matlab project opens and shows the following files:
(model containing the parameter estimation algorithm)
(model initialization script for the parameter estimation algorithm)
note:
verify and update the motor, inverter, and other parameters related to the target hardware and parameter estimation algorithm in the model initialization script
parameter_estimation_init.m
.
the rated speed of the motor (variable
motorparam.ratedspeed
) must be less than 25000 rpm.
the tests protect the hardware from over-current faults. however, to ensure that these faults do not occur, keep the rated current of the motor (variable
motorparam.nomcurrent
) less than the maximum current supported by the inverter.
if you have an smps-based dc power supply unit, set a safe current limit on the power supply for safety reasons.
generate code for parameter estimation algorithm using embedded coder
1. after you open the matlab project, double-click the parameter_estimation_algorithm.slx
model.
2. select modeling > model settings > model settings to open the configuration parameters dialog box.
3. in the solver selection area of the solver tab, update the type and solver fields.
4. in the hardware implementation tab of the configuration parameters dialog box, configure the parameters according to your hardware.
5. update the hardware setup parameters (including the quadrature encoder and adc offsets) in the model initialization script ().
6. in the simulink toolstrip of the model, select apps > embedded coder to open the embedded coder application.
7. in the simulink toolstrip, select c code > code interface > default code mappings to open the code mappings - c dialog box.
8. in the code mappings - c dialog box, open the functions tab.
9. for a listed c function, click the hyperlink under the function preview column to open the configure c initialize function interface dialog box.
10. use the configure c initialize function interface dialog box to configure the interface and arguments of the c function.
11. click apply and ok to complete configuring the c function.
12. repeat steps 9 to 11 for all the listed functions.
13. in the simulink toolstrip of the target model, select c code > generate code > build to build the model and generate a .c
file for the target model for the current controller.
this image shows an example of a c function available in the generated current controller code.
note: the generated c function uses the interface that you configured in step 10.
obtain c code for custom hardware drivers
you can use the code generation software supported by the hardware manufacturer to configure the hardware peripherals and generate c code for the hardware drivers.
alternatively, you can also use a manually written driver code.
integrate parameter estimation algorithm code with driver code
1. call the parameter estimation algorithm functions from the driver code using the configured function parameters. this image shows a call to a parameter estimation algorithm c function.
2. use the return value from the function call to complete integrating the driver with the parameter estimation algorithm.
this figure describes the program control flow of the example.
for other details about the recommended code structure (that is used by the motor control blockset™ examples), see .
deploy integrated code to hardware
1. complete the hardware connections.
2. use the code generation and deployment software supported by the hardware manufacturer to compile, build, and generate a binary (for example .hex
) file from the integrated code. use the software to flash the binary file to the target hardware.
3. the integrated code running on the target hardware saves the computed motor parameters in these global variables:
rs
— phase resistance
ld
—d
axis inductance
lq
—q
axis inductance
bemf
— back-emf constant
j
— motor inertia
b
— friction constant