Example Code

Differential Equations for Brushless DC (BLDC) Motor Model and Simulation

Code and Documents

Attachment

This block of code calculates the differential equations for a Brushless DC (BLDC) motor in fixed-point, FPGA math. The equations come from the standard BLDC model (these equations were taken from a book entitled Permanent Magnet Synchronous And Brushless Dc Motors by Krishnan Ramu).

The inputs to the model are the following: the state vector, Y, (which contains id, iq, speed, and position, theta); a cluster containing the motor constants for the system; input voltages vd and vq; and a mechanical torque, Tm. The code uses three single-cycle timed loops to calculate each of the first three elements of the dy/dt output vector. The equations for the elements of dy/dt are as follows:

element 0 -- did/dt = 1/L * vd - R/L * id + w * iq

element 1 -- dIq/dt = 1/L * vq - R/L * iq - w * id - lamda * w/L

element 2 -- dw/dt = 1/J * (Te - Fw - Tm) where Te = 1.5 * lamda * iq

L motor inductance

R resistance of the stator windings

vd, id voltage and current in d-direction

vq, iq voltage in q-direction

w angular velocity of the rotor

lamda amplitude of the flux induced by the magnets of the rotor in the stator phases

J inertia of rotor and load

F viscous friction of the model

Te electromagnetic torque

Tm mechanical torque

The fourth element is a trivial calculation in that dtheta/dt = w and is calculated outside of the single-cycle timed loop.

The three assumptions made in the development of this set of differential equation are 1) Lq = LD (the d and q inductances are equal), 2) P =1 (the number of pole pairs in the model is 1) which also means that 3) wd = wr (the mechanical angular velocity and electrical angular velocity are equal).

These equations can be seen in the image below.

motor_model.jpg

Using this block along with a differential equation solver (such as a simple first-order Euler solver) can provide the basis for a fixed-point, FPGA-based simulation of a brushless DC motor. The differential equations require only a few ticks of the FPGA clock, and the model can be optimized to run a full simulation in roughly 250 nano seconds.

The file "test model.vi" can be used to test the model and the solver. Increasing the external mechanical torque or increasing Vq will cause the motor to spin (note that increasing Vd will not cause the motor to spin due to the fact that current in the d-direction causes zero torque and only radial thrust on the motor bearings).

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors