algorithm-凯发k8网页登录
this example enables you to use any custom motor-control hardware (hardware not used in the motor control blockset™ examples) to run a three-phase permanent magnet synchronous motor (pmsm) using field-oriented control (foc). using the algorithm export workflows, which involve generating code for the control algorithm by using simulink® and embedded coder® and then integrating it with either manually written or externally generated hardware driver code. this example explains the algorithm export workflows along with the intermediate steps.
the example uses the following hardware as a reference, but you can use any motor-control hardware:
controller: stmicroelectronics® stm32f302r8
inverter: stmicroelectronics® x-nucleo-ihm07m1
motor: bly171d (includes quadrature encoder sensor)
you can use this example to customize the control algorithm and integrate it with the drivers for your motor-control hardware. in this example, we use the software to configure and generate code for the hardware drivers. this example supports any three-phase pmsm.
implementing the foc algorithm needs real-time rotor position feedback. this example uses a quadrature encoder sensor to measure the rotor position. for details about foc, see .
the example includes three workflows.
1. open-loop control and adc offset calibration — this workflow uses an algorithm that runs a pmsm using open-loop control (also known as scalar control or volts/hz control). you can use this workflow to check the integrity of the hardware connections and calculate the adc offsets for the current sensors available on the hardware.
2. quadrature encoder offset calibration — this workflow uses an algorithm that calculates the offset between the d
-axis of the rotor and the index pulse position as detected by the quadrature encoder sensor. the control algorithm (available in the field-oriented control workflow) needs this offset to accurately compute the rotor position, which is necessary to implement foc.
3. field-oriented control — this workflow uses an algorithm that runs a pmsm using closed-loop field-oriented control (foc). the workflow uses the adc and quadrature sensor offsets as inputs.
each workflow includes these steps to prepare, deploy, and run the algorithm on your hardware:
1. generate code for the control algorithm using embedded coder®
2. obtain c code for hardware drivers
3. integrate control algorithm code with the driver code
4. deploy the integrated code to hardware
5. control the motor using a host simulink® model.
open matlab project
use one of these methods to open the matlab® project:
click open example.
run the command
mcb_focalgorithmexportdemostart
at the command prompt.
the project contains three folders, one for each workflow required to run the final foc algorithm. each folder contains these contents:
data script containing motor, inverter, and target hardware details.
algorithm model for generating code for the control algorithm. the generated code will be available in the folder
[project_root]/work/code
.
host model for communication with the target hardware.
c code which shows how to integrate the generated algorithm code and the hardware driver code (specific to stm32f302r8 & x-nucleo-ihm07m1).
in addition to the three folders, the project also includes an .ioc
file. you can use this file with stm32 cube mx to configure the peripherals of the target and generate code. the .ioc
file available in the project is specific to the stm32f302r8 and x-nucleo-ihm07m1 hardware.
workflows for custom hardware
follow these workflows in sequence.
1.
2.
3.