A Translation Point

To read original PDF of the print article, click here.

Embedded Systems Programming

A Translation Point

Don Morgan

Initially, the introduction of the digital signal processor (DSP) into motion control was meant to solve problems relating to flexibility, size, precision, cost, and ease of maintenance in the motion control and drive. The DSP made it possible to replace a great deal of expensive and touchy analog circuitry with more stable and much more malleable digital circuitry. This meant that a math engine became the brain of the controller and the engineer was able-through software-to accomplish any transfer function that an analog controller was capable of doing, and much more.

Once manufacturers realized an interest in DSP for motion control existed, they increased on-chip capabilities and speeds. It is not uncommon now to find DSPs with one or more analog-to-digital converters on board, as well as encoder counters and hardware PWM generation. It's possible to create a very sophisticated motion controller using just a DSP, some memory, and logic elements.This kind of density is possible because the DSP now performs so many of the activities that used to require separate equipment, boards, processors, or ICs. In this column, we will examine some of the other duties that the DSP can perform while controlling the motor. We will start by re-introducing concepts from trigonometry and show how they allow the DSP to replace such ancillary circuits as the resolver-to-digital (RTD) conversion and to perform sinusoidal encoder interpolation.


Figure 1 is an illustration of a pair of right triangles superimposed on a circle with the angle a originating at the center. Trigonometric functions are ratios based on angles. For example, the sine of the angle a is the ratio of the opposite side (y) to the hypotenuse on the smaller triangle, while the cosine of the angle a is the ratio of the adjacent side (x) to the hypotenuse. Another useful identity is the tangent. In the figure, the tangent touches the circle at only one point, where the radius meets the unit circle. The tangent is perpendicular to the radius and stretches between this point and where it would meet the hypotenuse if the hypotenuse were extended beyond the unit circle. The tangent of a is the ratio of y to x.It is also possible to write the tangent function as:

What we derive from the forward trigonometric functions of angles are magnitudes.

The inverse functions-arcsine, arccosine, and arctangent-on the other hand, are angles. You read tan-1 z (or arctan z), for instance, as “tan-1 z is an angle whose tangent is z.” In the figure, if we know the length of the side marked as tan, we can find a by performing the arctangent function. We may write this as:

with y = sin a and x = cos a. What we recover from this function is an angle.

These relationships are remarkably useful. Because they provide such a simple translation point between a linear and rotary viewpoint, you will find them useful in untold engineering applications; we will see some in this column.

A common signal processing application

In signal processing for instance, the trigonometric functions are a standard part of many bilinear transform algorithms. Digital filters are based upon finite arithmetic with a finite sample rate; the corner frequencies (3dB point frequencies) of digital filters bear a highly non-linear relationship to continuous time corner frequencies. We can warp an analog frequency to a digital one by taking the arctangent of the ratio of the analog frequency to the sample rate. To be precise:

The second expression is the more pedagogical one and is seldom used as is. Here, fc is the corner frequency and fs is the sample rate. We can also make the transition back to the s-plane with the tangent. This is known as pre-warping:

In this equation and the previous one, wa is the analog frequency in radians, wd is the digital frequency in radians and T is the sampling period.

This process is called pre-warping because many people will design their digital filters through the use of an analog prototype. If they want a final digital frequency of 10kHz, then they must pre-warp this to create an analog frequency for their prototypes.These functions give us the ability to map a vertical segment on the s-plane to an angle on the unit circle in the z-plane and move it back again.

Encoding linear motion

It probably goes without saying that motion control depends heavily on position information. Devices for deriving this information abound and are usually called encoders because they take this linear information and encode it into some form that can be easily transmitted and received.

A common type of encoder is the digital quadrature encoder. It outputs position as a two-bit digital word, which means that it can represent four distinct positions. Depending on the resolution of the encoder, one complete revolution of the shaft will produce an integer number of these four position mappings. It is the responsibility of the device that receives this information to derive direction and count information from it. This is usually done with a flip-flop for direction and an exclusive-or gate to the two bits of quadrature information into a single serial bit stream.This is a crude form of encoding and ultimately expensive because for real precision and stiffness in servo applications, you need a very high-resolution encoder. Because the output is based on light shining through small holes in a wheel inside the encoder that is picked up by optical receivers, digital quadrature encoders become very expensive as the resolution goes up. To get higher resolution, you must put a greater number of holes on the wheel and confine the light to an increasingly narrower space, and this must be done with precision; an expensive mechanical problem.

As a result, analog encoders are becoming popular. These come in many flavors but all seem to be based on the concept of encoding the angular position of the shaft into the sinusoidal and cosinusoidal properties described in the earlier section entitled Trigonometry. Many cosinusoids may be output per revolution or just one. Whichever it is, encoding in analog offers infinite resolution, depending on the user's ability to decode it. The user may choose to employ a simple, low-resolution decoding scheme or a more complex higher-resolution scheme, depending upon his needs. One of two techniques is generally employed for using digital encoders. We'll examine both of them here.


The relationship between the sine and cosine waveforms can be seen in Figure 2. In the figure, I indicate the point in the rotation at which the sine and cosine of the angle are equal; this is the famous half-power or –3dB point. Here, both the sine and cosine are approximately 0.785 radians.

If I am monitoring these two waveforms with a simultaneously sampling analog-to-digital converter (ADC), I can take these values, perform an arctangent, and again have my angle, p/4:

Now, depending on the resolution of my ADC and the integrity of my electronics, I can get whatever resolution I wish in the angle. Pretty nice, huh? But unless you choose to perform the calculations each time you get samples, you will need simultaneously sampling ADCs and some lookup tables.


The second technique also uses the sine/cosine relationship and quadrature, but not in the same way. A resolver is basically a transformer with a rotating primary and two secondaries placed in quadrature on one another. See Figure 3. There, one secondary is rotated p/2 (90 degrees) relative to the other. In operation, the primary is located on the rotor as shown in the illustration. A constant sinusoidal frequency (called the reference frequency) is impressed upon this primary and is allowed to rotate along with the shaft passing the two secondaries, as shown in Figure 2.

Unlike the technique we discussed in the previous section, the output of each secondary is not out of phase (or in quadrature) with the others. Rather, the amplitude of the output from each secondary is a function of the primary's relative angular position. When the primary and one of the secondaries are on the same plane, we get a null output on that winding and a full amplitude output on the other secondary winding. At any other point in the rotation, we will get outputs-at the reference frequency-whose amplitudes are scaled by the sine and cosinusoidal relationships each winding bears to the rotor.

As shown in the figure, when the primary is at a p/4 (45 degree) angle to both secondaries, the amplitude is equal on both secondaries.

As with the previous example, if we were sampling these two windings with an A/D, we could perform an arctangent on the two values and again have p/4 as our resulting angle.

Calculating the result

A great deal of noise is often present in a motion control environment, especially in more recent designs in which the controllers are literally placed with the drives right on the motors they control. In high power applications, a great deal of current flows, and because the applications are overwhelmingly PWM-oriented, there is also a great deal of noise. Each time the integrated gate bipolar transistors (IGBTs) switch, large amounts of current flow or cease to flow, and the electrical state within the drive fluctuates; large current spikes result.

Switching high voltage in close proximity to other (albeit unrelated) circuitry in this manner can cause “sympathetic” currents to flow in those circuits (Ampere's law) and trash your analog feedback. Even differential signals can have difficulty in environments like this. This would be a difficulty whether you chose to do the conversions yourself or used an off-chip solution. With a DSP, however, it is possible to filter the input signals before using them in calculations and thereby reduce the amount of error caused by these noise transients. And you can tailor that filter mechanism to meet your needs regarding PWM frequency, motor velocities, and other things that influence your corner frequencies.Of course, you must be mindful of the phase distortion that can result when the data rates from your feedback device approach the turn-over frequency (-3dB)of your filter. You can overcome this by putting the appropriate all-pass filter in line with the primary filter.

These are useful techniques and definitely workable. In fact, a number of products on the market implement this them. Of course, there might be a better way.

Next month, we will discuss an enhanced approach to this technology, one that will incorporate the necessary filtering as an integral part of the transfer function; it is also easy to implement and requires less horsepower from your DSP.

Don Morgan is senior engineer at Ultra Stereo Labs and a consultant with 25 years of experience in signal processing, embedded systems, hardware, and software. Morgan recently completed a book about numerical methods, featuring multi-rate signal processing and wavelets, called Numerical Methods for DSP Systems in C. He is also the author of Practical DSP Modeling, Techniques, and Programming in C, published by John Wiley & Sons, and Numerical Methods for Embedded Systems from M&T. Don's e-mail address is .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.