## Custom Electric Machine Modeling with PSIM blocks

PSIM stands as a dynamic platform for power system simulations, offering users the capability to create custom mathematical functions for a range of applications. In this article, we'll explore the versatility of PSIM in electric machine mathematical models, using DC machine modeling as just one illustrative example. This example can start as a starting point to grasp what is possible.

To get some background info into custom mathematical and component modeling with PSIM blocks, feel free to follow some relative articles first:

1. The fundamentals: How to calculate an integral or derivative using PSIM blocks
2. Basic custom passive component modeling:
3. More complex component modeling:

### 1. Deriving Equations:

To begin the modeling journey, it's crucial to derive the electrical and mechanical equations of the machine. For a DC machine, this involves expressing variables such as armature and field voltages and currents, back electromotive force (EMF), torque, and load torque. The derived equations serve as the foundation for the subsequent steps:

Where vt, vf, ia, and if are the armature and field voltages and currents; Ra, La, Rf, and Lf are the armature and field winding resistances and inductances; Ea is the back emf; J is the moment of inertia, ωm is the mechanical speed; φ is the field flux; and Tem and TL are the developed torque and load torque, respectively. If the magnetic saturation is neglected, the back emf and the developed torque can also be expressed as:

Where Laf is the mutual inductance between the armature and the field windings. It can be calculated based on the rated operating conditions as:

### 2. Implementing Equivalent Circuits:

Once the equations are obtained, they can be translated into equivalent circuits within PSIM. There are many blocks to help you in this process. For instance, the armature winding equation  (Eqn. (1)) may be represented by a resistor (Ra) in series with an inductor (La) and a controlled voltage source (Ea). The field winding equation can be represented similarly.

The mechanical equation, Eqn. (5), can be represented by either an inductor in series with two voltage sources, or a capacitor in parallel with two current sources. In PSIM, the capacitor convention is used to implement mechanical equations. Eqn. (1), (2), and (5), therefore, can be represented by the equivalent circuits as shown below:

The equivalent circuit consists of three parts, with each part representing one of the equations. Armature current (ia) and field current (if) are obtained through current-controlled voltage sources. Back electromotive force (Ea) and developed torque (Tem) are portrayed using nonlinear voltage sources with multiplication. In the circuit depicting Eqn. (5), torques are symbolized by currents, mechanical speed by node-to-ground voltage, and moment of inertia by capacitance.

A good rule of thumb is that everything in series affects the voltage of the equivalent circuit, influencing the speed. Conversely, everything in parallel (to ground) affects the current of the equivalent circuit, impacting the torque. For instance, if you intend to introduce friction, you can place a resistance in parallel to the ground path. Similarly, inertia can be represented as a parallel capacitance to the ground path:

The correspondence in measurements is as follows:

• 1V corresponds to 1 rad/s
• 1A corresponds to 1 Nm
• 1 kg*m^2 (inertia) corresponds to 1 Farad

To enhance clarity, labels replace physical wires in the circuit layout. It's important to note that the external load torque (TL), depicted by a current source, originates from outside the machine and is not inherently part of the DC machine model.

### 3. Packaging the Model in a Subcircuit:

To enhance usability, the constructed circuit is packaged into a subcircuit. This process involves:

• Subcircuit size definition
• Interface ports placement
•  Subcircuit image creation/editing [if necessary]

The subcircuit size is the size of the subcircuit block as it appears in the main circuit. It is set by selecting Subcircuit -> Set Size in PSIM. The size should be large enough to allow the proper placement of the interface ports.

After defining the subcircuit size, the subsequent step involves positioning interface ports, which serve as connectors to external circuits. In this instance, we designate two interface ports for armature winding terminals, two for field winding terminals, and one for the mechanical shaft. To place an interface port, navigate to Subcircuit -> Place Bi-directional Port.

In PSIM, an electrical machine's mechanical shaft exclusively links to another mechanical shaft or other mechanical elements. To establish this connection within the model's mechanical equivalent circuit, an Electrical-Mechanical Interface block must be affixed to the speed node. Here, the electrical side connects to the speed node, while the mechanical side connects to an interface port. More details on the Electrical-Mechanical Interface block can be found in this tutorial video. The resultant circuit configuration takes shape as depicted below once the ports are strategically placed.

Furthermore, model parameters are defined as block variables at the main circuit level. Specify armature/field winding resistances (Ra, Rf), inductances (La, Lf), moment of inertia (J), and the gain for Ea and Tem as Laf within the circuit. Then, navigate to Subcircuit -> Edit Default Variable List to add these variables with default values.  The dialog window of the default variable list is shown below, after the variables are added:

Finally, the subcircuit image can be modified or edited by navigating to Subcircuit -> Edit Image. You can use the utility tools to create the desired image. The figure below shows an image created for the DC machine model: