# 3 Hz from a watch crystal

I have a stepper motor which step angle is 2 degrees. I want to display seconds using a needle attached to this stepper.

The watch crystal divides nicely to produce 1Hz pulses, so every second I can command the stepper to rotate CW 3 pulses (360 deg / 60 seconds = 6 degrees per second. Since the stepper goes 2deg per step, I need 3 of such pulses).

Now suppose I want to use each step to display seconds in a more smooth manner. I would need to step the motor every 1/3 of a second, or at 3Hz.

I'm trying to find out what's the best way to do that.

One obvious trick is to use a higher frequency (I'm using 64Hz) and tolerate some jitter. Is there any other way that will give me the exact 3Hz out of the 32.768kHz? (even knowing that one is not divisible by the other?)

BTW I'm using an MSP430, but this problem could be ported to any other platform.

-
PLL and a frequency divider. –  Ignacio Vazquez-Abrams Aug 9 at 4:27
What if use three 1Hz crystals, each shifted by 1/3 of phase? –  Vi0 Aug 10 at 19:03

You could do a 3:1 gear ratio and do the divisor at 32768.

32768 = 10,923 + 10,923 + 10,922 which indicates a state machine that first counts to 10,923 repeats and then drops a count, it would be accurate every 3 seconds. The worst absolute error you would see is 31 PPM which is about what the crystal can do (depending on your crystal).

-

Take the 32,768 Hz square wave and feed it through a 98 kHz band pass filter to leave (mainly) its 3rd harmonic - this is fairly trivial. Now you have 3 times 32,768 Hz which you can divide with the previous circuit you used to get 3 Hz.

-

It is true that 32768 Hz does not divide by 3 Hz, but it is not off by much.

You need a solution which appears visually smooth and is accurate on average over time.

Simply create logic which:

Counts 10923 input clocks and takes a step
Counts 10923 input clocks and takes a step
Counts 10922 input clocks and takes a step

and repeats.

You would need instrumentation or a sensitive experiment to determine that every 3rd pulse is .009% shorter.

-

The digital solution is to take something like an 8 bit accumulator and add 3 to it every 128 pulses. Whenever it carries, step the motor. The resulting jitter will not be noticeable and will cancel longterm. A longer accumulator (and consequently shorter pre-divider) will reduce the jitter, a shorter will increase it. You can probably go down to a four-bit accumulator (and predivision by 2048) without much of a discernible difference: it would then interpolate by taking 5 clocks to carry in 2 out of 3 cases, and 6 clocks to carry in 1 out of 3 cases.

-

Wait for the 1 second pulse and do the first step, then delay 333ms before doing each of the other two steps. you may not get exactly equal steps, but it should be close enough that you won't notice the difference (and the average frequency will be exactly 3Hz).

-

The stepper moves in discrete steps every time you change the state on the coils, so a certain amount of 'jumpiness' is unavoidable if you drive the stepper that way.

If you micro-step the motor you can get a large number of steps per revolution, avoid the jumpiness essentially entirely (there will be some nonlinearity of motion, but it should be unnoticeable unless your needle is very, very long), and get smooth sweep motion of the needle (a holy grail among some aficionados of timepieces). It would also avoid the any vibration from underdamping.

If you want to stay with the 2° steps, you can add 0x0C to an 8-bit register at 64Hz and step the motor every time you get a carry.

Here is what the jitter looks like-- less than +/-8 milliseconds, which will not be visible:

 Time = 0.328125 delta = 0.328125 Time = 0.656250 delta = 0.328125 Time = 0.984375 delta = 0.328125 Time = 1.328125 delta = 0.343750 Time = 1.656250 delta = 0.328125 Time = 1.984375 delta = 0.328125 Time = 2.328125 delta = 0.343750 Time = 2.656250 delta = 0.328125 Time = 2.984375 delta = 0.328125 Time = 3.328125 delta = 0.343750 Time = 3.656250 delta = 0.328125 Time = 3.984375 delta = 0.328125 Time = 4.328125 delta = 0.343750 Time = 4.656250 delta = 0.328125 Time = 4.984375 delta = 0.328125 Time = 5.328125 delta = 0.343750 Time = 5.656250 delta = 0.328125 Time = 5.984375 delta = 0.328125 Time = 6.328125 delta = 0.343750 Time = 6.656250 delta = 0.328125 Time = 6.984375 delta = 0.328125 Time = 7.328125 delta = 0.343750 Time = 7.656250 delta = 0.328125 Time = 7.984375 delta = 0.328125 Time = 8.328125 delta = 0.343750 Time = 8.656250 delta = 0.328125 Time = 8.984375 delta = 0.328125 Time = 9.328125 delta = 0.343750 Time = 9.656250 delta = 0.328125 Time = 9.984375 delta = 0.328125 Time = 10.328125 delta = 0.343750 Time = 10.656250 delta = 0.328125 Time = 10.984375 delta = 0.328125 Time = 11.328125 delta = 0.343750 Time = 11.656250 delta = 0.328125 Time = 11.984375 delta = 0.328125 Time = 12.328125 delta = 0.343750 Time = 12.656250 delta = 0.328125 Time = 12.984375 delta = 0.328125 Time = 13.328125 delta = 0.343750 Time = 13.656250 delta = 0.328125 Time = 13.984375 delta = 0.328125 Time = 14.328125 delta = 0.343750 Time = 14.656250 delta = 0.328125 Time = 14.984375 delta = 0.328125 Time = 15.328125 delta = 0.343750 Time = 15.656250 delta = 0.328125 Time = 15.984375 delta = 0.328125

The same method could be used to control a micro-stepped motor, just with finer steps such as 2°/16.

-

For those of you who like hardware, following is a schematic of placeholder's dual-modulus counter solution, but without the possible 31PPM error.

If you want to play with the circuit, the LTspice circuit list and supporting files are here.

The schematic below shows the presets for a 32768Hz clock, while the LTspice version has the count - and the timing - shortened drastically in order to keep the sim from running forever, but to still show the operation of the dual-modulus counter.

-