DC motor at very slow precise "clockwork" speed

Thread Starter


Joined Feb 11, 2008
Hi, this is something that comes up on the forums from time to time, with things like solar tracking and clock mechanisms etc.

It's a system using a cheap common PIC microcontroller to run any DC motor at a very precise speed, including error correction if the motor is bumped forward or backward etc.

It requires that the DC motor has an encoder fitted (a standard quadrature encoder), or in my case I just pulled an encoder disc from an old Microsoft mouse and glued that to the motor. (Motors with encoders already fitted are commonly available on ebay and from hobby robot suppliers like Sparkfun and Pololu etc.)

As you can see the circuit required is very simple with practically no parts, just enough to get the encoder working (3 resistors) and something to drive the motor with PWM (a transistor and a diode).

The "precise stuff" is all done in software using a Bresenham math system to make a precise xtal-locked reference frequency and a simple algorithm so the motor must maintain the same average speed as the reference frequency (and it auto-corrects any short term speed errors).

Like any good clock system it can be tweaked with one number to set the motor speed, in very fine adjustment steps.

You can set the DC motor to exactly 1 rev per second, and it will keep clock accuracy for weeks or months afterward.

This is a viable alternative to using stepper motors for clock type applications, and will run much quieter, smoother and many times less energy consumption than a stepper motor, and no motor driver IC's are required.

The whole project is here, with C source code supplied;


Joined Sep 7, 2009
Very nice, I had no idea they could turn that slowly. Now I know why I've been keeping old mice.
Even optical mice tend to have a encoder for the scrollwheel. The one I've got here has 12 slots, so would be good for faster speeds.


Joined Nov 30, 2010
This is the kind of thing I put in my blog space on AAC so I can point people at it without leaving this site.