Kyle’s Motor Controller

Background

There are many ways to control a motor’s speed. For some applications it’s sufficient to turn the motor on or off via a switch or transistor. For more critical applications, the motors speed and direction should stay close to the target values- even when load is applied.

Kyle, a budding robot enthusiast (he’s 11 years old), is currently investigating different methods of locomotion. For his robot projects, he and his dad have used continuous rotation servos, as well as car motors driven by speed controllers. For his latest project, he chose to measure the motors speed using a quadrature encoder and to drive the motor via an H-bridge. A quadrature encoder outputs 2 signals whose frequency and phase correspond to the motor’s speed and direction- this technology is used in most non-optical mice. An H-bridge drives a motor at any speed and direction by varying the length and polarity of the power supplied to the motor. Driving an H-bridge requires at least 3 pins- forward, backward, and enable. Since all of these signals are time critical, and the control logic difficult to calculate empirically, Kyle faced quite a challenge.

Problem

To measure the motor’s speed and adjust it’s power, 2 inputs and 3 outputs needed to be monitored. Furthermore, the feedback loop for the controller- in this case a full PID controller, required debugging and tuning. Without the ability to see the IO signals or adjust the PID’s parameters, this project would have taken much more time than it did.

Solution

Once the hardware was ready, Kyle was ready to tune and debug the controller. At first, he used Viewport to inspect the Quadrature Encoder signals. Once he understood how the phase determined the motor’s direction, he came up with an Assembly program to measure rpm on multiple motors and to drive the H-bridge for a given value. What was left was tuning the PID loop. A PID loop takes 3 parameters- the gain multipliers for the Proportional error, the Differential error, and the Integral error. Kyle used Viewport’s scrollbar to manipulate these parameters while monitoring the motor’s performance. He started by increasing the P constant, then adding I and D to yield a controller which accurately and quickly kept the motor at the desired speed.

Add Comment Register



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>