Crazy Clock

A replacement controller for Lavet stepper clock movements

Similar projects worth following
Simple, run-of-the-mill wall clocks with second hands that step from one second to the next are driven by a Lavet stepper motor clock movement. Once you know how they work, it's relatively simple to design a microcontroller based replacement for the electronic part of the movement. If you do that, you can make the clock tick any way you want.

There are presently thirteen different firmware loads for the Crazy Clock. Five of them are "alternate timebase" clocks. They tick at a faster or slower rate so that a complete revolution of the hands occurs in more or less time than a normal Solar day. The rest of the clocks are "novelty" clocks. They tick at a long term average of 86400 ticks per day, but they alter the timing of the ticks for humorous effect.

At the end of the gear train of a Lavet stepper motor based clock movement is a gear with a permanent magnet attached to it. The gear sits in a stator with a coil wound around it. The coil is (ordinarily) pulsed at 1 Hz with alternating polarity. That causes the magnet to rotate 180°, which in turn causes the second hand to move 6° (one second's worth).

If you cut the traces on the board that lead to the chip from the battery and to the coil, and then tack on wires to those traces, you can wire in an alternative controller that can make the clock tick any way you want.

If you really want to have the minimum possible impact on how the movement works, it's desirable to reuse the AA battery holder built-in to such movements. Although a single AA battery starts out providing 1.5 volts, as it discharges, the voltage will drop even though it is still capable of putting out enough current to drive the movement acceptably. But a cheap microcontroller, like an ATTiny45, won't operate properly even on 1.5 volts, much less anything lower. Even more critical is the fact that varying the supply voltage may have a detrimental impact on the oscillator frequency. The solution is a boost converter to make a higher, stable voltage out of whatever voltage the battery is producing. The boost converter need only be capable of a burst current of about 5 mA, and most of the time the controller will draw less than 100 nA. This is because we strategically turn most of the internal peripherals off and put the controller to sleep most of the time. The boost converter chip is the XC9140C331MR-G. It's capable of providing at least 40 mA (at 0.8V in), but it remains highly efficient even at the low currents drawn by the crazy clock most of the time. The boost converter circuit is quite small - It's a SOT-23-5 chip, two ceramic caps and an inductor. Because the microcontroller runs at 3.3 volts instead of the original 1.5 volts, we place a 100 ohm series resistor on both outputs. Most of the coils out there have a resistance of around 200 ohms, so the total series resistance of 200 ohms drops the voltage presented to the coil down to close to the original 1.5 volts. The flyback diode array is just outside of series resistors. The flyback diodes prevents the negative coil collapse voltage from being presented to the controller, which would potentially damage it.

We use the AVR's "idle" sleep mode, because we use a timer interrupt to wake the controller at 10 Hz, and idle mode is the deepest sleep available that allows the timer to run. Every time the controller wakes up, it makes a decision whether to tick or not and then goes back to sleep.

The timer is driven by the clock's 32.768 kHz crystal. Because that crystal is also the controller's execution clock, it takes very little power even when it's not sleeping. But obtaining a 10 Hz interrupt source from a 32.768 kHz source requires some tricky arithmetic. The timer is configured with a divide-by-64 prescale setting, resulting in a 512 Hz counting rate. To go from 512 Hz to 10 Hz we must divide by 51 1/5. To do that, we count to 52 once, and then count to 51 four times. Some of the intervals will be about 2 ms longer, but for this application, that's not significant. The only downside to having such a slow system clock is that the ISP programming clock must be no faster than a quarter of the system clock, so programming must be done at no faster than 8 kHz. Most of the firmware is just a little more than 1KB, so it takes upwards of 15 seconds to load.

The accuracy required to keep a clock reasonably close to the correct time is quite demanding. Even a pedestrian standard of 10 parts per million (about 26 seconds in 30 days) requires at least calibrating each manufactured batch of boards. The result of the calibration is a standard average drift factor. Each individual board can be expected to run within 10 parts per million of this standard drift due to the manufacturing tolerances of the crystal, but...

Read more »


Schematic for T44 QFN generic variant

Adobe Portable Document Format - 25.22 kB - 03/09/2021 at 00:17



Eagle schematic for T44 QFN generic variant

sch - 159.39 kB - 03/09/2021 at 00:15



Eagle board file for T44 QFN generic variant

brd - 50.72 kB - 03/09/2021 at 00:15



Schematic for T44 QFN Q-80 variant

Adobe Portable Document Format - 26.60 kB - 03/30/2017 at 17:44



Eagle schematic for T44 QFN Q-80 variant

sch - 147.12 kB - 03/30/2017 at 17:40


View all 16 files

  • 1 × ATTiny45-20MU Microprocessors, Microcontrollers, DSPs / ARM, RISC-Based Microcontrollers
  • 1 × CM315D32768EZFT Frequency Control / Crystals
  • 1 × XC9140C331MR-G Power Management ICs / Battery Management ICs
  • 1 × BAT54A Discrete Semiconductors / Diodes and Rectifiers Schottky diode array
  • 1 × 10 µH inductor 1210

View all 11 components

  • Smaller inductor

    Nick Sayer03/20/2017 at 00:22 0 comments

    For the life of me, I don't know why I've been using such a huge inductor all this time.

    I got a rev 2.6.1 board fab'd with an 0805 footprint for the inductor and tested it out, and it works just the same as the 2.6 version.

    My inductor choice was a Taiyo Yuden LBR2012T100K 10 µH 360 mΩ inductor. As before, the boost converter had a 10 µF input cap and a 22 µF output cap. The rest of the circuit was the same (based on the ATTiny44A).

    EDIT: Ah. Now I see. The LBC3225T100KR 1210 inductor I have been using has about half the resistance and a reel of them costs 25% less.

  • XC9142 vs XC9140

    Nick Sayer02/27/2017 at 18:57 0 comments

    Well, the XC9142 was on a par with the TI chips that I tried - and about an order of magnitude higher than the XC9140. I've reached out to Torex to ask them about the future availability of the XC9140, but I really don't see any parts out there that are any better for this application.

  • ATTiny44A and more BOM fiddling

    Nick Sayer02/24/2017 at 01:53 0 comments

    I've just had a pile of boards manufactured with QFN ATTiny45s and with the XC9140 boost converter, (they're not yet arrived, though), but also ordered some prototype boards for an ATTiny44A variant.

    After a little bit of hacking about, it works just fine. It takes maybe 10% more power, but that's really a difference between ~18 µA and ~22 µA - not really outside the margin of error anyway.

    The biggest difference is in the calibration code. The feature pin mapping is (as you'd expect) quite different on the 44 versus the 45, so the pin I was using before changed from being OC0A to OC1A. So the calibration code for the Tiny44 has to use Timer 1 instead of Timer 0. That's not really significant, since the calibration code doesn't run from a battery (or even installed in a movement).

    The only changes were in calibrate.c and base.c, and all of it got handled by using the AVR processor type macros, so as long as you set the mmcu directive on the compiler properly, you'll get functional code.

    Meanwhile, I've ordered some XC9142 chips, which appear to be an updated version of the XC9140. They at least appear to be somewhat more plentiful on DigiKey, so they may be the way to go. I'm going to try swapping some of them out on my test boards to see what the impact is on power consumption.

  • More BOM shaving

    Nick Sayer02/15/2017 at 01:34 0 comments

    Hilarity ensues.

    The ATTiny44A QFN variant, it turns out, is cheaper than the ATTiny45. Go figure. Is it volume or something? Who the heck knows?

    I'm going to try a board variant with that to see if it works. It's silly though - I only need two pins, so most of the rest will be NC.

  • Shaving BOM pennies

    Nick Sayer12/19/2016 at 04:04 0 comments

    Huh. Turns out the ATTiny45-20MU is around 30% cheaper than the ATTiny45-20XUR, depending on how many you buy. Even buying them in a tube doesn't save you the kind of scratch that the QFN package does. Even if you were to buy them a reel at a time, the QFN package is 20% cheaper (of course, then you're buying 5 or 6 thousand of them).

    Well, it's all the same to Bob, of course, so I'm going to try a board with the QFN part and see how that works out.

  • For Great Justice

    Nick Sayer12/15/2016 at 04:12 0 comments

    On a whim, I built a board with a 10 µH inductor instead of 4.7 µH, and a 22 µF output filter cap instead of 10 µF. Now the draw with the calibrate sketch is around 24 µA! Ship it!

  • Torex it is

    Nick Sayer12/13/2016 at 03:33 0 comments

    The test boards came back today. It turns out that the Torex chip and the latest TI contender (the TPS61097A) are pin compatible, and I just misread the Torex datasheet. So one of the boards was a waste, but the other was able to test both.

    The TPS61097A wasn't a lot better than any of the other TI hysteretic chips, but the Torex was. It wasn't as good as the NCP, but it will do. With the bench supply (1.8v) running the calibrate sketch, it draws around 40-45 µA so far as I can tell. When you look at the current on the scope, what you see are big spikes spaced around 4 ms apart, with mostly noise between them. The output voltage has about 20 mV of sawtooth in it that has a period consistent with that. For this application, that much ripple is acceptable, as long as it's consistent.

    The price is a little higher than the NCP, but not critically. What worries me is that while DigiKey and Mouser both stock the part, their supply looks rather constrained to me.

  • More boost converters to try

    Nick Sayer12/08/2016 at 05:44 0 comments

    I think maybe I've figured out what the issue is with the boost converters.

    Both the TPS61221 and TLV61225 are hysteretic topologies. The NCP1402 was a PFM controller.

    I've put in two more prototype design boards, one for the TPS61097A (also from TI), and one for the Torex XC9140C331MR-G. It's the latter one that gives me some hope - the datasheet specifically describes it as a PFM controller.

    I have only read a little bit of the datasheet, but I am buoyed by the fact that the Torex and On Semi parts both claim to work the same way.

    The Q:250 price at DigiKey is, unfortunately, 19¢ more, and it appears as though the supply is a bit on the constrained side. But in any event, the next step is to test it out. Boards and parts should be here soon.

  • The next contestant

    Nick Sayer12/04/2016 at 02:26 0 comments

    The next boost converter contestant will be the Torex XC9140C331MR-G. It requires a new board, so that'll take a week and a half. Le sigh.

  • TPS61221 not much better

    Nick Sayer12/03/2016 at 22:05 0 comments

    Well, I guess the search for an alternative power supply continues. The TPS61221 samples arrived, and they're a little better than the TLV61225, but not much. It still draws over twice as much as the NCP1402 under test conditions.

    The NCP1402 circuit had inductors that were 10 times the value of the TPS/TLV recommendations (47 µH instead of 4.7 µH - with 2x22µF output filter caps). I'm almost ready to try putting one of those in just to see what happens (not hoping for much, unfortunately).

View all 27 project logs

  • 1
    Step 1

    These instructions are for retrofitting an existing movement with the "retrofit" variant of the Crazy Clock controller board. If you don't have a movement already, then the recommendation is to simply buy a complete movement from the Crazy Clock store. These movements have had their original PCB replaced with a dedicated Crazy Clock controller board, so the result will be more reliable in the long run.

    If you have a clock that already has its own movement, and you don't want to replace it, then you'll need to retrofit that movement with these instructions.

  • 2
    Step 2

    Either obtain a pre-built Crazy Clock board from my Tindie store or assemble your own. There's no particular instructions for building the board itself beyond just the generic steps for surface mount assembly.

  • 3
    Step 3

    If you wish, you can test the board by powering it with a AA battery or other 1.5 volt power source, and connecting a bi-color LED (that is, a red and green LED in a single package connected anode-to-cathode to two common leads) to the CLOCK terminals. If you use a 5 mm through-hole LED, the leads will be spaced properly for the terminal. Don't solder the LED, just insert the leads and bend them apart to make a temporary connection. The LED should blink alternately red and green in the expected pattern for the firmware in the controller.

View all 23 instructions

Enjoy this project?



Paul Andrews wrote 04/10/2018 at 21:41 point

Hmmm. Now I want to put an ESP8285 in my clocks for time synchronization and auto DST adjustment.

  Are you sure? yes | no

Nick Sayer wrote 12/11/2019 at 21:19 point

The problem is that with true Lavet stepper movements, you have no idea where the hands are pointing. With so-called "atomic" clock movements (which are just WWVB receiver clocks), they add sensors so they can tell when the hands are in a particular position, then they just count forward to set or reset the clock.

  Are you sure? yes | no

alpha_ninja wrote 12/07/2015 at 00:40 point

Checked your design files: you seem to be missing gerber files.

  Are you sure? yes | no

alpha_ninja wrote 12/02/2015 at 00:47 point

This is your one-week reminder to upload design documents:

  Are you sure? yes | no

Voja Antonic wrote 09/28/2015 at 19:10 point

Great idea. I like the videos (the ones with action).

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates