Control Tutorials For MATLAB and Simulink - Time-Response Analysis of A DC Motor
Control Tutorials For MATLAB and Simulink - Time-Response Analysis of A DC Motor
Diode
Transistor (MOSFET)
Jumper wires
encoder pulses are counted on the Arduino board via two of the board's
The Arduino board is also used for controlling the speed of the motor.
recorded data to Simulink for visualization and analysis. The logic for
within Simulink. In Part (b), the logic for controlling the motor's speed will
Purpose
model for the motor based on its step response. This type of model is
here.
2 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
For this example, we will treat the voltage source (V) applied to the
motor's armature as the input, and the rotational speed of the shaft
as the output. For modeling purposes, the rotor and shaft are
motor torque constant and the back emf constant (since the two
constants are equal when consistent units are employed). For the details
(1)
quadrature encoder.
Hardware setup
In this experiment we will control our motor through one the board's
digital outputs. Since the board cannot supply enough current (only
about 40 milliamps) to drive most motors directly, we will use the low-
3 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
power signal from the board to connect and disconnect the motor to a
used to switch a transistor on and off. When the transistor is turned "on"
it will behave like a closed switch thereby completing the circuit and
causing the motor to spin. When the transistor is turned "off" it will act
like an open switch such that current won't flow through the circuit and
the motor will coast to rest. Since the motor is an inductive load, when
we attempt to switch the motor off and it continues to spin (due to its
inertia) the motor will generate a back emf (a voltage). This back emf
can damage our transistor. In order to prevent this back emf from
causing damage, we will put a "flyback" diode in parallel with our motor.
The diode will only allow current to flow in one direction, thereby
drives the Gate pin. When voltage is supplied to the Gate, it closes the
circuit between the Source and Drain pins. One possible choice of power
MOSFET is the IRF1520 whose datasheet can be found here. For our
diode, we will employ the general purpose 1N4007 whose datasheet can
be found here.
(PWM). Recall, a PWM approach alternately turns the motor "on" and
"off". Since the motor has dynamics (inertia, friction, etc.), it doesn't
4 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
immediately come to a stop when turned off. It takes time for the motor
sufficiently fast. It's as if the motor is filtering the PWM command. In this
the percent of time the PWM signal is on compared to the overall period
(the duty cycle). Further details on PWM can be found in Activity 1b and
Activity 4.
We will also employ the Arduino board for sensing the position/speed of
the motor. There are different means for achieving this with one of the
the emitter/detector pair. When the phototransistor detects the light its
output goes high, and when it doesn't detect light its output goes low. By
the disk will encounter Pair A first and Pair B second, thereby causing
5 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
One motor with Hall-effect encoder that could be used for this activity
can be found here, though there are many other choices. This particular
motor can be driven by a 6-V lantern type battery. The encoder provides
48 counts per revolution (if you count both rising and falling edges). The
1633 counts per revolution at the output shaft of the gearbox. A version
of this motor can be purchased without the gearbox for less money here.
Various accessories for the motor (brackets, wheels, etc.) can be found
from the same website. The setup of the motor with encoder and its
connection to the Arduino board is shown below. The color band on the
diode indicates its cathode. The Gate, Source, and Drain pins of the
6 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
Software setup
the switching of the transistor, to read the encoder output, and to plot the
data in real time. In particular, we will employ the IO package from the
following link. We will build the Simulink model for this activity in a step-
need to change the port to which the Arduino board is connected (the
port is COM4 in this case). The Pulse Generator block toggles between
transistor between its OFF state and its ON state, respectively. Double-
clicking the Pulse Generator block we set the Sample time equal to
"0.02". In the downloadable model, the sample time is set to the variable
0.02 before the model can be run. We will also define the Pulse type to
As the gate of the MOSFET is triggered from Digital Output 5, the Digital
double-clicking on the block allows us to set the Pin to 5 from the drop-
down menu. We will leave the Sample time as "-1" to inherit the value
from the Pulse Generator block. The Encoder Read block is used for
reading the quadrature encoder signal. The encoder pulses are counted
via the program running on the Arduino board. The Encoder Read block
polls the board every sample period to get the latest number of counts
block, we will leave the Encoder Number as "1" (we only have one
encoder so it doesn't matter). We will also set Pin A to "2" and Pin B to
7 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
encoder signals. For the Arduino Uno, this is the only option. For the
Mega, for example, we could also use pins 18 and 19, or pins 20 and 21.
The Sample time is again set to "0.02". Finally, we connect the output of
The Arduino Digital Write block, the Encoder Read block, the Arduino IO
Setup block, and the Real-Time Pacer block are all part of the IO
package. The remaining blocks are part of the standard Simulink library,
specifically, they can be found under the Sources and Sinks libraries.
Running the above model for 30 seconds generates the figure shown
after 2 seconds the motor is turned on (the transistor is switched on) and
motor was spinning in the opposite direction, the encoder counts would
number of encoder counts "rolls over." This happens because the buffer
numbers between -32768 and 32767 (i.e. it uses 16-bits, 15 bits for the
8 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
rollover has occurred (at 32767 or at -32768) and then modifies the
9 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
rollover subsystem, shown below, you can inspect the logic used for
If we re-run our Simulink model with the rollover correction, we now get
the motor's speed over a specific interval of time as the change in the
essence, this is the motor's average speed over that time interval.
position (in counts) and the first Gain block divides by the sample time.
workspace before the model can be run. For the motor described above,
10 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
Reducing the length of the simulation then running the model generates
Examining the above, we can see that the estimate for motor speed is
quite noisy. This arises for several reasons: the speed of the motor is
timing at which the board is polled doesn't exactly match the prescribed
sampling period and can add a filter to "smooth" the motor speed
here.
11 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
Running this model with the sample time increased to 0.05 seconds and
a filter time constant of 0.15 seconds produces the following time trace
for the motor speed. Make sure to define the necessary variables at the
filter_constant = 0.15;.
By increasing the sampling period and adding the filter, the speed
This can be seen by looking at the estimate with and without filtering at
the point at which the input is "turned on." The filtered output lags behind
motor's actual response. In this case, this makes identifying a model for
the motor more challenging. In the case of feedback control, this lag can
constant of the filter will reduce this lag, but the tradeoff is that the noise
In this activity we are attempting to infer a model for the motor based on
its observed response. Considering that our input is a 6-Volt step, the
response. Looking at the filtered speed, the DC gain for the system is
better see the true speed of the motor. Looking at the unfiltered data,
and reducing the sample time to 0.01 seconds, we get the following
speed response.
12 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
achieve 63.2% of its total change, we can estimate the time constant
from the above graph. We will attempt to "eye-ball" a fitted line to the
motor's response graph. This too is like adding a filter, but since it
doesn't have to occur in real-time, we can use future data (as well as
past data) to avoid the introduction of lag. Assuming the same steady-
estimate the time constant based on the time it takes the motor speed to
seconds and the input appears to step at 1.02 seconds, we can estimate
(2)
but the response looks more like a first-order model. The explanation is
that the motor is overdamped (poles are real) and that one of the poles
mechanical dynamics are much slower than the electrical dynamics, and
(3)
aspects of the true physical motor. Based on our linear model, the
example, the response of the motor to a 6-Volt step should have the
13 of 14 28/03/2022, 12:19
Control Tutorials for MATLAB and Simulink - Time-response Analysi... file:///D:/DATA/Automatique/Automatique/TP%20asss/Travaux%20A...
won't move at all. This is due to the stiction in the motor. If the motor
torque isn't large enough, the motor cannot "break free" of the stiction.
Extensions
parameters of the motor. You could then compare the predictive ability of
response, similar to what was done with the boost converter in Activity
International License.
14 of 14 28/03/2022, 12:19