Basics of Design CC Blog Research & Design Hub

Measuring the Frequency Response of a DC Motor

Using Linear and Non-Linear Techniques

A system’s frequency response, which describes how it reacts to inputs at different frequencies, is an important characteristic. DC motors look simple and are often treated as linear devices. In this article, we describe two systems built at Jerusalem College of Technology. One measures the frequency response of a DC motor directly, and the other uses non-linear control. The measurements are used to partially characterize a DC motor and to see how closely it resembles an ideal DC motor.

— ADVERTISMENT—

Advertise Here

Our systems for measuring the frequency response of a direct current (DC) motor use evaluation kits for the Analog Devices ADuC841 microcontroller (MCU), an 8-bit MCU that uses the 8051’s instruction set [1]. A motor driver module for the L298N H-bridge provides the power to drive the motor and to control the direction in which the motor turns [2]. Additionally, the systems use an MA702 (Monolithic Power Systems) angular position sensor [3] to measure the angle of the motor’s shaft. A level shifter [4] interfaces between the ADuC841, which operates at 5V, and the MA702, which requires 3.3V. We used two systems, to measure the frequency response in two ways—one by the direct method for a linear motor, and the other for a non-linear system. A schematic diagram of the first system is shown in Figure 1, and a photo of the system is given in Figure 2.

FIGURE 1 Schematic of the two-MCU system, showing all relevant pins. At all points in which 3.3V was needed, the output of the simple regulator was used. Wherever 5V was needed, the output of the voltage regulator on the evaluation kit for the ADuC841 MCU (not shown here) was used. Both UARTs were connected to a computer.
FIGURE 1
Schematic of the two-MCU system, showing all relevant pins. At all points in which 3.3V was needed, the output of the simple regulator was used. Wherever 5V was needed, the output of the voltage regulator on the evaluation kit for the ADuC841 MCU (not shown here) was used. Both UARTs were connected to a computer.

The Ideal, Linear, DC Motor: Without getting involved in the physics behind DC motors, you can say that a DC motor takes a voltage as input, and if the input is a DC voltage, in the steady-state, the motor rotates at a speed that is proportional to the voltage. Double the voltage, and you should double the steady-state speed of the motor. Of course, the motor does not respond to changes immediately—it has a time constant, τ.

— ADVERTISMENT—

Advertise Here

FIGURE 2 The complete two-MCU system with all major parts labeled. Note the “ring” at the tip of the motor’s shaft and the label directly above the ring. As the label shows, the ring is a diametrically magnetized magnet—that is, a magnet with north on one side of the cylinder and south is on the other side (not on the “top” and “bottom” of the cylinder). Our sensor senses changes in a magnetic field, so we had to mount a magnet on the motor’s shaft to allow the sensor to measure the shaft’s angular position.
FIGURE 2
The complete two-MCU system with all major parts labeled. Note the “ring” at the tip of the motor’s shaft and the label directly above the ring. As the label shows, the ring is a diametrically magnetized magnet—that is, a magnet with north on one side of the cylinder and south is on the other side (not on the “top” and “bottom” of the cylinder). Our sensor senses changes in a magnetic field, so we had to mount a magnet on the motor’s shaft to allow the sensor to measure the shaft’s angular position.

The simplest transfer function that has these properties and that is used to describe a DC motor is:

where the input, Vin(t), is the voltage input to the motor, and the output is θ(t), the motor shaft’s angle (Vin(t) and θ(t) are their Laplace transforms) [5]. See Figure 3 for the step response of a motor for which K = 300°/s and τ = 0.1s. Since this transfer function has two poles and no zeros, at high frequencies the phase of the frequency response of the motor, Gideal(), approaches -180°. That is, if you input a high-frequency sine wave to the motor, you expect its output to be 180° out of phase with respect to its input.

A Less Ideal Linear Motor: Though Gideal(s) is a reasonable first approximation to a motor, it does not actually reflect anything like the full complexity of a DC motor. A somewhat more complicated model is:

— ADVERTISMENT—

Advertise Here

When ε is small, this is not too different from Gideal(s), and it leads to similar behavior; but, as the denominator is third order, at high frequencies, the phase of the frequency response tends toward -270°. See Figure 4 for this system’s step response, and Figure 5 for its Bode plots.

What We Actually Saw: We built a system to measure the performance of a DC motor—a system that we describe shortly. First, we found that at high frequencies, the phase of the output was more negative than -180°, so the most ideal model cannot be the correct one. In fact, we also found that none of our motors would rotate at low voltages, so they are not even linear, though we continued to treat them as approximately linear. Simply put, a truly complete description of a “simple” DC motor is not simple.

FIGURE 3 The step response of a motor for which K=300°/s and for which the time constant is τ = 0.1s. Note that in the steady state, the angle increases linearly and the angular velocity (the motor’s speed) is constant. Note also that there is a short ramp-up period just after the step is input to the motor, when t = 0 where the output is clearly not increasing linearly.
FIGURE 3
The step response of a motor for which K=300°/s and for which the time constant is τ = 0.1s. Note that in the steady state, the angle increases linearly and the angular velocity (the motor’s speed) is constant. Note also that there is a short ramp-up period just after the step is input to the motor, when t = 0 where the output is clearly not increasing linearly.

FIGURE 4
The step response associated with the “less ideal” model of the DC motor. Note that it is similar (though not identical) to the step response of the ideal DC motor in Figure 3.
FIGURE 4
The step response associated with the “less ideal” model of the DC motor. Note that it is similar (though not identical) to the step response of the ideal DC motor in Figure 3.

FIGURE 5
The Bode plots associated with the “less ideal” DC motor. Note that here the phase tends toward -270° as the frequency tends toward infinity.
FIGURE 5
The Bode plots associated with the “less ideal” DC motor. Note that here the phase tends toward -270° as the frequency tends toward infinity.

A BRIEF DESCRIPTION OF OUR MCU—THE ADUC841

We made use of the ADuC841 MCU—which, from a programmer’s point of view, is essentially an 8052, but a very, very, souped-up 8052 [1]. In addition to having the standard features of the 8052—three timer/counters, a universal asynchronous receiver/transmitter (UART), and input/output ports—the ADuC841 has an additional timer, Timer 3, the sole purpose of which is to serve as the UART’s clock. The ADuC841 is designed to communicate via serial peripheral interface (SPI), and it has several pulse width modulation (PWM) ports and two digital-to-analog converters (DACs)—all of which are used by our system—and many additional peripherals that we did not use.

MEASURING THE FREQUENCY RESPONSE BY THE DIRECT METHOD

In principle, measuring the frequency response of a circuit is not difficult. You input signals at different frequencies, measure the circuit’s output, and calculate the amplification and the phase shift seen at each frequency. When working with a motor, things are more complicated, because the output is not a simple electrical signal, and running a motor requires more power than an MCU is capable of providing.

There are, of course, solutions to both problems, but they require adding hardware to the system. The ADuC841 has two DACs, but they do not provide enough power to run a DC motor. Rather than design linear power amplifiers to do this work, we switched tack, and used the ADuC841’s PWM outputs to control the effective (average) voltage of the signal sent to the motor. (A brief discussion of how to use PWM to change the “effective voltage” seen by a load is given in Chapter 18 of ADuC841 Microcontroller Design Manual: From Microcontroller Theory to Design Projects [1]).

After learning how to use the on-board PWM peripheral, we could output signals with any desired duty cycle by changing the settings of the pulse-width modulated signal. We still needed, however, to up the power of the signal and be able to switch the polarity of the signal. We used a motor driver module for the L298N H-bridge for this purpose.

An H-bridge is essentially a set of four user-controllable “switches” (generally solid-state, transistors) that can be used to drive the motor in a “positive” or “negative” direction (Figure 6). The power supply (VCC = 12V) to the H-bridge provided the motor with the voltage and current it required. We were now able to control the magnitude of the voltage seen by the motor by varying the duty cycle of the pulses output by the ADuC841’s PWM output. We controlled the direction by changing which of the MCU’s two PMW outputs we caused to output a PWM signal, and which was set to output a constant 0V. (The module we used made it simple to control the H-bridge’s switches.)

FIGURE 6
An H-bridge. The four heavy line segments represent user-controllable (solid-state) switches. In this configuration, VCC is connected to the left terminal of the motor, and the right terminal is connected to ground. By opening the closed switches and closing the open ones, one can switch the direction. By leaving the top two switches open and closing the bottom two switches, one can input 0V to the motor to cause it to slow down.
FIGURE 6
An H-bridge. The four heavy line segments represent user-controllable (solid-state) switches. In this configuration, VCC is connected to the left terminal of the motor, and the right terminal is connected to ground. By opening the closed switches and closing the open ones, one can switch the direction. By leaving the top two switches open and closing the bottom two switches, one can input 0V to the motor to cause it to slow down.

It was also necessary to measure the angle of the motor shaft. Though the ADuC841 has a multi-channel ADC, this was not of use to us, because the signal we needed to measure—the motor shaft’s angle—was not an electrical signal. We measured the angle using an MA702 angular position sensor. This sensor communicates via SPI—a communication protocol supported by the ADuC841. There was a small, practical problem, however. The MCU is a 5V device, and the MA702 is a 3.3V device. Buying a level shifter [4] solved that problem. Each measurement was transmitted from the ADuC841 to MATLAB using the MCU’s UART. In this way, we recorded the motor’s output—its shaft’s angle, and then we analyzed it.

At this point, we almost have a system that can measure the frequency response. There is one problem, though. To measure the phase shift, it is necessary to know the “relative phase” of the input and the output. We measure the output, but how can we measure the phase relative to a PWM signal?

Initially, we tried using a single ADuC841, but we found it best to separate certain of the system’s functions by implementing them on different MCUs, as detailed below.

We used one MCU to output a signal to the H-bridge that controlled the motor. A second MCU measured the motor shaft’s angle and reported it to MATLAB (Figures 1 and 2). Each time the first MCU started a new period of the signal it was outputting, it caused an external interrupt to occur on the second MCU. As a result, the second MCU inserted an additional symbol in the data it transmitted via the UART, indicating when the sine-wave output to the motor had begun. In this way, MATLAB was able to determine the phase of the output signal relative to that of the input signal.

The Bode plots of one of our motors as measured by our system, preprocessed by MATLAB and plotted using Python, are given in Figure 7. The measurements were made with the H-bridge powered by a VCC = 12V power supply, and the magnitude values in Figure 7 were not normalized. Because the same power supply was used for both methods of measuring the frequency response, this made no real difference. Since the motor is relatively low pass, we were not able to measure its response to very high-frequency signals; the output was too small. However, we saw that the phase fell below -180°, showing that Gideal(s) is not a good model for our DC motor.

FIGURE 7
The Bode plots of one of our DC motors as measured by our system with two ADuC841 MCUs. The dashed red line in the phase plot shows where -180° is attained. The minimum phase is clearly less than -180°, so Gideal(s) cannot be the correct transfer function for our motor.
FIGURE 7
The Bode plots of one of our DC motors as measured by our system with two ADuC841 MCUs. The dashed red line in the phase plot shows where -180° is attained. The minimum phase is clearly less than -180°, so Gideal(s) cannot be the correct transfer function for our motor.

MEASURING THE FREQUENCY RESPONSE USING A NON-LINEAR SYSTEM

We built a second system that was designed to provide an independent check on parts of the frequency response. We used a single ADuC841 MCU and all the rest of our equipment (H-bridge, the angle sensor, and so on) to implement the system, which is depicted in Figure 8. This was a closed-loop control system, with a controller that was a simple comparator, implemented in code on the MCU. It also had a delay, implemented in code using a circular buffer, between the controller and the motor. In addition to implementing the control system, the MCU reported the measured values of the shaft angle to MATLAB. The schematic diagram of this system is shown in Figure 9. As we discuss next, this output can be used to determine points on the Bode plots.

FIGURE 8
Block diagram of the closed-loop system. The sensor (which measures the motor shaft’s angle) and H-bridge (used to drive the motor) are not shown, but they are present. The differencer, the comparator, and the T-second delay are implemented in software by the MCU.
FIGURE 8
Block diagram of the closed-loop system. The sensor (which measures the motor shaft’s angle) and H-bridge (used to drive the motor) are not shown, but they are present. The differencer, the comparator, and the T-second delay are implemented in software by the MCU.

FIGURE 9
The schematic of the one-MCU system that we built to provide an independent check on parts of the frequency response.
FIGURE 9
The schematic of the one-MCU system that we built to provide an independent check on parts of the frequency response.

Even when non-linear systems like the one shown in Figure 8 have no external input (or, in this case, equivalently, an input of 0), you often find that they output sine waves of fixed amplitude and frequency. These signals are known as “limit-cycles” [5]. For such systems, limit cycles occur at the frequency ƒ0, at which the phase of the linear portion, the delay-motor pair, is -180°. The amplitude of the limit cycles is shown in the following equation:

where Acomp is the (effective) amplitude of the comparator-H-bridge combination. The phase at that point satisfies:

where T is the length of the delay. (A short explanation of where these equations come from is given in the sidebar.)

How does all this help? First, suppose that we do not add a delay—that T=0. Then, the second equation says that the limit cycle’s frequency will be the frequency at which the phase of the motor’s transfer function is -180°. In addition, its amplitude will be a known constant value multiplied by the absolute value of the transfer function at that same frequency. That is, by measuring the amplitude and frequency of the limit cycle, we can calculate the phase and amplitude of the frequency response at the frequency of the limit cycles.

By changing the value of T, we can change the frequency and amplitude of the limit cycles, and those changes will give us other points from the frequency response of the motor. In this way, by adjusting the length of the delay, we can determine the frequency response of the motor for all frequencies at which its phase is ≤ -180°.

We performed measurements with a variety of different delays, and the results are given in Figure 10.

FIGURE 10
Results when using the closed-loop system of Figure 8. The upper plot shows the observed frequency, which decreases as the delay increases. The middle plot shows the magnitude of the oscillations (given in degrees), which increases as the delay increases. (A magnitude of 60 degrees means that the shaft angle varied over a range of 2 × 60° = 120°.) The lowest plot shows the phase change that the delay causes at the observed frequency. (This value is calculated using the equation: phase change = -360ƒT°, where ƒ is the observed frequency and T is the delay. The phase change is not measured.)
FIGURE 10
Results when using the closed-loop system of Figure 8. The upper plot shows the observed frequency, which decreases as the delay increases. The middle plot shows the magnitude of the oscillations (given in degrees), which increases as the delay increases. (A magnitude of 60 degrees means that the shaft angle varied over a range of 2 × 60° = 120°.) The lowest plot shows the phase change that the delay causes at the observed frequency. (This value is calculated using the equation: phase change = -360ƒT°, where ƒ is the observed frequency and T is the delay. The phase change is not measured.)

We now check that the new measurements are in reasonable agreement with the previous one (Figure 11). Let’s consider the results when we introduce a 15ms delay into the system. The observed frequency of the limit cycles is 4.9Hz. This can be seen fairly well in Figure 10, but 4.9Hz is the actual value we measured. This contributes a phase change of -360° × 0.015s × 4.9Hz (s-1 ) ≈ -26.5°. We should find that this phase added to the motor’s phase at this frequency equals -180°. The motor’s phase, as shown in the Bode plots in Figure 7—as we measured it—is -158.4°, and the sum of the two phases gives -184.9°, which is pretty close to -180°. At this frequency, we find that the motor’s “amplification” is 17.8. Multiplying by 4/π, we find that the amplitude of the limit cycle should be about 22.7°. The observed amplitude was 24.2°.

FIGURE 11
The percentage error in the phase and magnitude. Note that the smaller the delay, the higher the frequency of the oscillations and the smaller their amplitude. This may explain the relatively large error in the magnitude when there is no delay.
FIGURE 11
The percentage error in the phase and magnitude. Note that the smaller the delay, the higher the frequency of the oscillations and the smaller their amplitude. This may explain the relatively large error in the magnitude when there is no delay.

CONCLUSIONS

We built two systems that allowed us to measure a motor’s frequency response (where the input is taken to be voltage and the output to be the shaft angle) by using MCUs and inexpensive hardware. One measures the frequency response directly, and the second system uses non-linear control (using a comparator) and a delay to “push” the system into oscillating at different frequencies and amplitudes. Making use of a bit of theory from non-linear control, we are able to use the second set of measurements to measure the frequency response in a second way. We present measurements on one motor showing that the two sets of results are in good agreement—as they must be. Over the course of this project, we spent a lot of time working with “simple” DC motors, and we found that though very interesting, they are more complicated than you would expect

LIMIT CYCLES IN SYSTEMS WITH A COMPARATOR NON-LINEARITY

Consider the system of Figure 8, and suppose that when the input is zero, the DC motor oscillates—something that can happen. We would like to try to determine at which frequencies and with what amplitude the motor oscillates.

Assuming we see relatively “nice” oscillations of the phase angle, the output of the comparator—which sees an input of minus the phase angle—will be a square wave. This square wave is filtered by the motor whose transfer function is Gp(s), and if this system is reasonably low pass, its output should contain a sine wave at the fundamental frequency of the square wave. For a square wave of amplitude Acomp, the amplitude of the component at the fundamental frequency is (4/π)Acomp.

If we now consider what happens to a limit cycle as it traverses the entire circuit in Figure 8, we find that if the shaft angle is assumed to be Msin(2πƒt), then after crossing the differencer, its value is –Msin(2πƒt). The output of the comparator will be a square wave, but only the fundamental frequency of the square wave, ƒ, is of interest to us. Its value will be –(4/π)Acompsin(2πƒt). After being delayed by T seconds, the signal will be (4/π)Acompsin(2πƒ(tT)+π). After crossing the motor, the signal will be

But we start by assuming that the output of the motor looks like: Msin(2πƒt). For these two expressions to be equal, we must have

and we must have

where here all angles are expressed in radians. With a mild abuse of notation regarding the units of the phase of Gp, we convert to degrees (by multiplying -2πƒt by 180°/π) and find that the frequency of the oscillations is fixed by the requirement that

REFERENCES
[1] S. Engelberg, ADuC841 Microcontroller Design Manual: From Microcontroller Theory to Design Projects. Vernon, Connecticut, Circuit Cellar, Inc., 2011.
[2] Last Minute Engineers, “Interface L298N DC Motor Driver Module with Arduino.” https://lastminuteengineers.com/l298n-dc-stepper-driver-arduino-tutorial/. Last retrieved 2 February 2023.
[3] Monolithic Power Systems, “MA702 Angle Sensor.” https://www.monolithicpower.com/en/ma702.html. Last retrieved 2 February 2023.
[4] SparkFun, “SparkFun Logic Level Converter—Bi-Directional. https://www.sparkfun.com/products/12009. Last retrieved 2 February 2023.
[5] S. Engelberg, A Mathematical Introduction to Control Theory, 2nd ed., Series in Electrical and Computer Engineering, Vol. 4, London, Imperial College Press, 2015.

PUBLISHED IN CIRCUIT CELLAR MAGAZINE • June 2023 #395 – Get a PDF of the issue

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.


Note: We’ve made the Dec 2022 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Sponsor this Article
+ posts

Shlomo Engelberg (shlomoe@jct.ac.il) received his bachelor’s and master’s degrees in Engineering from The Cooper Union and his PhD degree in Mathematics from New York University’s Courant Institute. He is the dean of the school of Engineering and Computer Science at the Jerusalem College of Technology and is the author of many articles and several books, the latest of which are ADuC841 Microcontroller Design Manual: From Microcontroller Theory to Design Projects (Circuit Cellar, 2011) and A Mathematical Introduction to Control Theory, 2nd Ed. (Imperial College Press, 2015). Shlomo’s research interests include applied mathematics, instrumentation and measurement, signal processing, coding theory, and control theory.

Shlomo Huta (huta@g.jct.ac.il) is currently completing his BS degree in Electrical and Electronics Engineering at the Jerusalem College of Technology – Machon Lev. His interests include speech recognition methods.

Avraham Zerbiv (avi842@gmail.com) is currently completing his BS degree in Electrical and Electronics Engineering at the Jerusalem College of Technology – Machon Lev. His interests include algorithm development.

+ posts

Shlomo Engelberg (shlomoe@jct.ac.il) earned Bachelor’s and Master’s degrees in Engineering from The Cooper Union. He holds a PhD in Mathematics from New York University’s Courant Institute. He is the Dean of the School of Engineering and Computer Science at the Jerusalem College of Technology. Shlomo is the author of many articles and several books, the latest of which are ADuC841 Microcontroller Design Manual: From Microcontroller Theory to Design Projects (Circuit Cellar, 2011) and A Mathematical Introduction to Control Theory, 2nd Ed. (Imperial College Press, 2015). Shlomo’s research interests include applied mathematics, instrumentation and measurement, signal processing, coding theory, and control theory.

Supporting Companies

Upcoming Events


Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2024 KCK Media Corp.

Measuring the Frequency Response of a DC Motor

by Shlomo Engelberg, Shlomo Huta, and Avraham Zerbiv and Shlomo Engelberg time to read: 13 min