Using the Microchip motor model library for Simulink, app note here (PDF!):
Microchip’s Motor Model Library is a set of components
(“blocks”) that can be used with the Simulink® simula-
tion tool from MathWorks®. These blocks are intended
to allow engineers to model a system with Permanent
Magnet Synchronous Motors (PMSMs) under closed-
loop control of an embedded microcontroller, such as
Microchip’s dsPIC® Digital Signal Controllers (DSCs).
Model-based engineering can be used to assist in the
development, testing and understanding of motor con-
trol systems. Simulation can be used to confirm the
behavior of real systems, and can also be used to
explore system behavior under conditions that are
impossible or cumbersome to test with a real system.