## 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**.

** 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—

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

where the input, *V** _{in}*(

*t*), is the voltage input to the motor, and the output is

*θ*(

*t*), the motor shaft’s angle (

*V*

*(*

_{in}*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.1*

*s*. Since this transfer function has two poles and no zeros, at high frequencies the phase of the frequency response of the motor,

*G*

*(*

_{ideal}*jω*), 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

*G*

*(*

_{ideal}*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 *G** _{ideal}*(

*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.

##### 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 (V_{CC} = 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.)

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 V_{CC} = 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 *G** _{ideal}*(

*s*) is not a good model for our DC 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.

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 *A** _{comp}* 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**.

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.015*s** *× 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°.

##### 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 *G** _{p}*(

*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

*A*

*, the amplitude of the component at the fundamental frequency is (4/π)*

_{comp}*A*

*.*

_{comp}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 *M*sin(2π*ƒ**t*), then after crossing the differencer, its value is –*M*sin(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/π)*A** _{comp}*sin(2π

*ƒ*

*t*). After being delayed by

*T*

*seconds, the signal will be (4/π)*

*A*

*sin(2π*

_{comp}*ƒ*(

*t*–

*T*)

*+*π). After crossing the motor, the signal will be

But we start by assuming that the output of the motor looks like: *M*sin(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 *G** _{p}*, 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

Sponsor this Article