DC Motor Controller and Quadrature Encoders

Hello all,

I would like to do a plug for a product we are selling here on Robotshop and offer support on the topic of controlling DC motors with quadrature encoders. We welcome feedback and would like to know what people need from such a product so that we can keep developing it. Here is a technical introduction on the subject.

The product in question is our Chipbotics QuadQuad2Drv: https://www.robotshop.com/en/chipbotics-quadquad2drv-connectorless-pid-motor-controller-with-quadrature-feedback.html

Common requirements are to be able to control DC motor velocity (such as 100 rpm forward/backward) or tell it to rotate by an exact angle (like 30 degrees forward/backward, what we call position control). This requires first to be able to measure change in angle, which can be done with quadrature encoders, and then to control the velocity or angular position using closed loop control. Finally, the digital output from the closed loop control must be converted into a high power signal that can power the motor.

For the uninitiated, DC motors are motors that you simply apply positive and negative DC power to and it will turn continuously. Not to be confused with stepper motors or brushless DC motors (BLDC) that have more wires, are more complicated to control and have their own characteristics. Some motors come with a quadrature encoder or they can added afterwards. A quadrature encoder is typically a small board with two magnetic (or optical) sensors that monitor a magnet disc (or optical encoder disc) mounted on either the front or rear motor shaft. As the motor turns, the two sensors output a simple “quadrature” binary signal that allows the direction of rotation and change in angle to be measured. In simple terms, the quadrature signal tells us that the motor shaft has rotated one transition forward or one transition backward, where one transition (or step) equates to a fixed angle, such as 1 degree. This minimum step angle depends on a number of factors such as motor gearing and number of “detents” on the magnetic or optical disc.

Decoding quadrature signals and calculating change in angle (what we call position) and velocity is another matter. In low cost, low performance systems the change in angle is often measured by triggering an interrupt for each quadrature transition, but this method can be a huge load on a microprocessor and increases with motor velocity. Calculating accurate velocity can also be difficult as it involves measuring intervals from microseconds to seconds, over one to tens-of-thousands of transitions, depending on velocity and amount of averaging required. If you want to calculate velocity and add closed loop control, you may have exceeded the limits of your microprocessor. Therefore it is best to off-load this work to external peripherals and that’s what we do at Chipbotics.

Closed loop control simply means having a goal, such as “rotate at 100 rpm” or “rotate backwards 30 degrees” and using feedback (quadrature in this case) to measure our progress and applying the necessary output to achieve this goal. This is a large and complex discipline. The most common method is called PID (Proportional, Integral, Derivative) control, which is what we are using. The output signal from such a control system can have many forms, but invariably describes something like “apply 25% of maximum power to the motor” and this signal can be updated hundreds or thousands of times a second.

Finally, the digital output signal must be amplified to produce enough current to drive the motor using a motor power driver. This is also a large topic that we won’t cover here, but note that the bigger the motor, the more current is required (bigger battery), the larger the power driver required and the hotter the driver might get.

It is worth explaining some differences between some of the many “DC motor controllers” I have come across online, as the term can have multiple meanings. Read the product description to make sure which kind they are.
(1) Most of these motor controllers are only power drivers that translate some input signal into power (such as 25% of maximum power) and describes the final stage power drivers on our board. The input signal could be digital PWM (pulse-width modulation), analogue voltage, sometimes SPI or serial and there are a few other rarities. Sometimes they only come with a physical potentiometer to set the power/velocity. Since power is roughly proportional to velocity, they allow you to spin the motor faster or slower, but the actual velocity also depends on the load on the motor. If you squeezed the motor shaft, it would slow down. You cannot specify a specific velocity or tell the motor to rotate a specific angle, since they have no feedback or closed loop control. These controllers can be “half bridge”, which rotates the motor in only one direction, or more typically “full bridge”, which can rotate in either direction.
(2) Direction-agnostic velocity controllers. These can read one of the two quadrature lines, which produces a PWM (pulse-width modulation) input signal, not a true quadrature signal. This allows the exact velocity and change in angle to be measured (at half resolution), but has no information about the direction of rotation. If you turned the shaft left-right-left-right, it wouldn’t know that the angle is where it started, for example. You can typically specify a drive direction and the controller will apply power in that direction and assume the motor is continuously rotating in the specified direction. It then varies the power to achieve the specified velocity. These are often sold as “position controllers” when they allow an analogue control input, such as an analogue joystick. The joystick produces a velocity and direction target that can be used to rotate a motor in the chosen direction and will stop when you let go, assuming there are no other forces on the motor. You cannot command the controller to hold position or rotate a specific angle, for example, because if you rotated the shaft by hand, it wouldn’t know which way it is rotating and thus in what direction to apply power. Since PWM signals are much easier to decode than full quadrature, this is a cost-effective solution if all you need is velocity control.
(3) Quadrature velocity and position controllers. This is what we have developed. These can measure the direction of each rotation step and calculate velocity and velocity direction. They can be commanded to rotate continuously at a specific velocity and direction, or move exactly 30 degrees in a specified direction and hold that position, fighting any external forces, or rotate 100 times and then hold. These come in many variations and may include advanced functions like velocity and acceleration limiting that produce smoother motion. These controllers are also called “incremental” or “relative” quadrature controllers, since they can only track rotation relative to the starting angle. For example, it knows it has rotated 30 degrees clockwise from where it was when it was turned on, but it does not know the angle when it was turned on. An absolute reference is sometimes supported in the form of a magnetic or optical sensor that turns on when a certain position is reached and the implementation depends on the application. For example, a 3D printer might move the head to the “home” position in the top right corner on start, where it will trigger the reference. Then the controller knows its absolute position. This can also be used to limit the range of movement to prevent a device from breaking itself, also called end-stops.
(4) Absolute position and velocity controllers. Similar to the above, but uses an absolute position encoder, which are often very expensive and typically do not have the same angular resolution as quadrature encoders. Absolute encoders come in many forms and protocols and may simply measure the angle of a motor output shaft or a linear encoder could measure the position of a lathe head. A combination of absolute and quadrature encoders are used in high performance systems - the absolute encoder gives a “rough” starting position and the quadrature encoder provides high resolution information about relative movements and velocity. This can be achieved relatively simply by reading an absolute encoder and writing this position to a quadrature controller on start-up.

We have developed a high performance, highly configurable, all-in-one microprocessor that can decode quadrature signals for four motors, produce position and velocity data and apply closed loop control on all four motors. The four motors are processed simultaneously and can be commanded simultaneously, which is important if you need to move them in concert. Communication is via SPI serial and we intend to add UART serial and I2C. External reference inputs are supported. Control can be PID velocity, PID position, direct power setting, or disabled. Advanced functions allow velocity and position ramps as well as power, velocity and acceleration limiting. The firmware can be upgraded via bootloader and we have free Arduino and PIC libraries.

Please have a look at the link at the top if you are interested and feel free to reply with questions or suggestions!