Microchip logo
  • All
  • Products
  • Documents
  • Applications Notes

MATLAB® and Simulink® for Motor Control Development

Motor Control Simplified

Prototyping your next motor control design doesn’t have to be hard. We offer a rapid prototyping solution that allows you to compile and flash a Simulink model of a motor control system into a dsPIC33 DSC or a PIC32 MCU with a single push of a button. Our Simulink blocksets and models support our devices and development boards for a complete hardware and software motor control solution.

Six Steps to Simplify Your Motor Control Development

Step 1: Make sure that MPLAB® X Integrated Development Environment (IDE) and the Simulink tools are installed on your computer

System Requirements

For simulation, you will need

  • MATLAB R2013a or later, 32-bit or 64-bit Windows® operating system
  • Simulink
  • Fixed-Point Designer™

For code generation, you will also need

  • Simulink Coder™
  • MATLAB Coder™
  • Embedded Coder®

Compilation and programming of the code generated with this blockset requires the latest MPLAB® XC compiler and MPLAB X Integrated Development Environment (IDE).

Step 2: Build your Simulink model using:

Simulink Motor Control Library Blockset

MPLAB Device Blocks for Simulink

Simulink PMSM Motor Model

Library Blockset

Simulation blocks and code generation for motor control algorithms


Blocks for PWMs, ADCs and other peripherals for use in simulation and code generation


Used to a simulate PMSM motor in Simulink


Step 3: Generate code using the Simulink embedded code generator and MATLAB plug-in for MPLAB X IDE

Step 4: Compile the MPLAB X IDE project and load code onto target MCU or DSCs

Demo examples are available for the following motor control development boards:

dsPICDEM™ MCHV-3 High-Voltage Motor Control Development Board

dsPICDEM MCHV-3 High-Voltage Motor Control Development Board

dsPICDEM MCLV-2 Low-Voltage Motor Control Development Board

dsPICDEM™ MCLV-2 Low-Voltage Motor Control Development Board

Step 5: Connect your board to your motor

Step 6: Run your code to spin a motor

Other Helpful Resources

Example Simulink Model for Sensorless FOC with PLL Estimator

Motor Control with Embedded Coder® for Microchip MCUs

This webinar demonstrates how to use Simulink to generate motor control code for a dsPIC33EP DSC-based system

dsPIC33 Motor Control DSCs

Explore our portfolio of dsPIC33 devices with specialized motor control peripherals

MATLAB and Simulink Components from Microchip

Motor Control Library Blockset for MATLAB and Simulink

Simulation blocks and code generation for motor control algorithms

The Motor Control Library blockset contains several basic Simulink blocks that can be used to jump start model-based design of your motor control applications using the dsPIC33 family of DSCs and the PIC32MK and SAM E70 families of 32-bit MCUs. These blocks include reference frame transforms, a Proportional-Integral (PI) controller and trigonometric functions, all of which can be used with the Embedded Coder to generate efficient code by utilizing our Motor Control Library.


  • Download the Motor Control Library blockset
  • Unzip the archive file into a directory of your choice
  • Add this directory into the MATLAB search path, which makes the Motor Control Library Blockset appear in the Simulink Library Browser the next time you start MATLAB


  • These blocks may be placed in a Simulink model like any other Simulink block
  • For best results in code generation, turn on Inline Parameters
  • The Proportional-Integral (PI) controller block requires mchp_MC_PISTATE_T in the MATLAB base workspace to contain a particular structure definition, which can be automatically set up by creating the required structure in the Simulink model's InitFcn
    • In a Simulink model using the Motor Control Library Blockset, select File > Model Properties > Model Properties > Callbacks > InitFcn
    • Add the ‘mchp_MC_PISTATE_T’ statement to the model initialization function shown in the InitFcn dialog box
    • Save the Simulink model
    • These steps need to be followed only once per new model file

Block Listing

Block Name



Clarke transform (ab → αβ)
2 → 2 transform from per-phase measurements (ab) to stationary orthogonal (αβ) reference frame



Inverse Clarke transform (αβ → abc)
2 → 3 transform from stationary orthogonal (αβ) reference frame to per-phase values (abc)
Legacy form with swapped inputs



Park transform (αβ → dq)
2 → 2 transform from stationary orthogonal (αβ) reference frame to rotating (dq) reference frame



Inverse Park transform (dq → αβ)
2 → 2 transform from rotating (dq) reference frame to stationary orthogonal (αβ) reference frame



Proportional-integral controller with antiwindup



Sine and cosine calculation (table-based with interpolation)



Arctangent (xy → θ)
Compute angle of input coordinates (x,y) using the CORDIC algorithm.



Space vector modulation
Legacy form, with gain and phase shift

MPLAB Device Blocks for Simulink

Code generation blocks for dsPIC33 DSCs and PIC32 and SAM7x support package for Embedded Coder

Create stand-alone applications from a Simulink discrete time model and with just one click generate, compile and load the code for your application onto your target device. The MPLAB Device Blocks for Simulink is a free set of user interfaces and Simulink peripheral blocks for developing complex designs based on dsPIC33 Digital Signal Controllers (DSCs) and PIC32 and SAM E70 microcontrollers (MCUs). The package also includes many examples in the form of demo models to further simplify your development, including a complete BLDC motor control application.

Supported Peripherals:

  • Digital I/Os
  • Analog-to-Digital Converters (ADCs)
  • Motor control Pulse-Width Modulators (PWMs)
  • Interrupts, resets and change notifications
  • Output Compares (OCs) and Input Captures (ICs)
  • Quadrature Encoder Interfaces (QEIs)
  • I2C, SPI and UART communication

PMSM Simulink Motor Model

Simulate a PMSM motor in Simulink

Our PMSM Motor Model blockset is a set of components to be used with the Simulink simulation tool. These blocks allow you to model a closed-loop control system of a PMSM using our range of MCUs and dsPIC33 DSCs. This PMSM model assists in your development, testing and understanding of motor control systems based on your motor’s specification. You can use this free simulation block to confirm the behavior of real systems and explore the system behavior under conditions that are impossible or cumbersome to test in the real world.