0
0
SimulinkHow-ToBeginner · 4 min read

How to Simulate DC Motor in Simulink: Step-by-Step Guide

To simulate a DC motor in Simulink, use the Simscape Electrical library blocks like DC Machine and connect them with voltage sources and mechanical loads. Set motor parameters, run the simulation, and analyze outputs such as speed and torque using scopes.
📐

Syntax

In Simulink, simulating a DC motor involves using these main blocks:

  • DC Machine: Represents the motor with electrical and mechanical ports.
  • Voltage Source: Supplies input voltage to the motor.
  • Scope: Displays simulation results like speed and current.
  • Mechanical Load: Optional block to simulate load torque.

Connect the blocks by linking electrical terminals and mechanical shafts. Set parameters like resistance, inductance, torque constant, and inertia in the DC Machine block.

simulink
DC Machine block + Voltage Source + Scope + Mechanical Load (optional)
💻

Example

This example shows how to build a simple DC motor simulation in Simulink using the Simscape Electrical library.

Steps:

  • Open Simulink and create a new model.
  • Add the DC Machine block from Simscape > Electrical > Machines.
  • Add a DC Voltage Source from Simscape > Electrical > Sources.
  • Add a Scope to observe motor speed.
  • Connect the voltage source to the motor's electrical terminals.
  • Connect the mechanical output shaft to a Rotational Load or leave free.
  • Set motor parameters like armature resistance = 1 Ohm, inductance = 0.01 H, torque constant = 0.1 Nm/A, inertia = 0.01 kg.m².
  • Run the simulation and open the scope to see speed response.
matlab
open_system('simulink');
model = 'dc_motor_sim';
new_system(model);
open_system(model);

% Add DC Voltage Source
add_block('powerlib/Elements/DC Voltage Source',[model '/Voltage Source'],'Position',[100 100 140 140]);

% Add DC Machine
add_block('ee_lib/Machines/DC Machine',[model '/DC Motor'],'Position',[250 90 350 150]);

% Add Scope
add_block('simulink/Sinks/Scope',[model '/Scope'],'Position',[450 100 480 130]);

% Connect blocks
add_line(model,'Voltage Source/1','DC Motor/1');
add_line(model,'DC Motor/1','Voltage Source/2');
add_line(model,'DC Motor/2','Scope/1');

% Set parameters
set_param([model '/DC Motor'],'Ra','1','La','0.01','Kt','0.1','J','0.01');

% Run simulation
sim(model,5);
Output
Simulink model 'dc_motor_sim' created and simulated for 5 seconds. Scope shows motor speed rising and stabilizing.
⚠️

Common Pitfalls

Common mistakes when simulating a DC motor in Simulink include:

  • Not setting motor parameters correctly, leading to unrealistic behavior.
  • Forgetting to connect both electrical terminals of the motor to the voltage source.
  • Ignoring mechanical load or shaft connections, which can cause the motor speed to increase indefinitely.
  • Not configuring the solver settings properly, causing simulation errors or slow runs.

Always verify connections and parameter values before running the simulation.

matlab
Wrong connection example:
% Missing connection from motor terminal to voltage source
add_line(model,'Voltage Source/1','DC Motor/1');
% No return path from motor to voltage source

Right connection example:
add_line(model,'Voltage Source/1','DC Motor/1');
add_line(model,'DC Motor/2','Voltage Source/2');
📊

Quick Reference

Tips for smooth DC motor simulation in Simulink:

  • Use Simscape Electrical blocks for realistic motor modeling.
  • Set all motor parameters based on datasheets or design specs.
  • Connect both electrical terminals properly to form a closed circuit.
  • Add mechanical load to simulate real-world conditions.
  • Use Scope blocks to monitor speed, torque, and current.
  • Adjust solver settings for accuracy and speed (e.g., use ode45 or ode15s).

Key Takeaways

Use Simscape Electrical blocks like DC Machine and Voltage Source to model a DC motor in Simulink.
Always set motor parameters such as resistance, inductance, torque constant, and inertia correctly.
Ensure both electrical terminals are connected to form a complete circuit.
Add mechanical load to simulate realistic motor behavior and avoid infinite speed.
Use scopes to visualize motor speed and current during simulation.