Unevenly running hours


    The idea of ​​this watch is that the arrows on them move unevenly, either accelerating or lagging behind, but nevertheless, on average, the clock shows the correct time. Now I’ll tell you how to do these.

    Autopsy


    Based on wall quartz clock hands. They can be designed as you like, but in 99% of cases there is a standard Chinese movement with plastic parts inside. Here it is: We


    open the case, simultaneously noting the availability of free space, which is very beneficial to us.


    Carefully disassemble the mechanism, trying not to forget which gear is put where.


    The clock is driven by a stepper motor, which consists of a stator with a winding and a rotor with a permanent magnet. Electrical pulses are applied to the winding once a second, and with each pulse the rotor rotates 180 °. Here is the disassembled motor:


    The clock generator board is fixed on the reverse side of the winding. Here's what it looks like:


    Brain transplant


    The clock mechanism will be controlled by the ATtiny13A microcontroller , chosen mainly on the basis of the “put what is” principle. Alternating polarity pulses of approximately 100 ms must be fed to the motor. Each pulse moves the second hand one mark.
    As you can see, everything is very simple: we connect the controller with two outputs to the winding, apply power ... Stop! But the watch is powered by one and a half-volt battery, and the minimum operating voltage for the ATtiny13A is 1.8 volts. How to be In fact, AVR controllers can work even with a supply voltage of 1 volt or even lower ( for example ), but under two conditions. Firstly, the clock frequency should be low, in the region of tens of kilohertz. Secondly, timing should be from an external source.
    Where to get the external clock? The solution is obvious: from a regular clock generator. It generates a signal with a frequency of 32 768 Hz (2 15  Hz), which can be removed from one of the quartz leads (which one is determined experimentally). We take our board and solder wires to it to remove power, a clock signal, and also to control the engine. It is also necessary to cut the tracks from the native generator to the terminals of the winding.


    The microcontroller connection diagram is as simple as two pennies:


    Just please pay attention to two points. Firstly, at ultra-low voltage, the output keys of the ports are not fully opened, therefore, to reduce the resistance, the outputs are paralleled in pairs ( PB0 with PB1 , andPB2 with PB4 ). Secondly, the capacitor in the power circuit should be put tantalum, with a minimum leakage current.
    The controller is mounted on a trim of the breadboard and is perfectly located in the free space in the corner of the case:


    Since the MK cannot be reflashed directly in the circuit, I strongly advise you not to solder it intentionally, but to install it in the socket.

    Firmware


    The logic of the watch is as follows: the intervals between steps of the second hand have a random duration, but it must go through a full revolution in exactly one minute so that the accuracy of the movement is not disturbed. It was established experimentally that the minimum interval between pulses is 1/4 of a second, an attempt to move the arrow faster leads to skipping steps. We will build on this, let the duration of each interval be a multiple of this minimum value. It will be convenient to divide the minute into 240 "ticks" for a quarter of a second each.
    The main problem that occurred while writing the firmware was how to randomly split the minute into 60 intervals. After spending a couple of hours and writing a few sheets of paper, I made up two algorithms. The first was to form an array of 240 elements, in which the numbers of all the “ticks” were placed. Then 59 elements were randomly selected from the array, each of which was the number of the “tick” on which the arrow would move. The second algorithm consisted of dividing the four-second interval (16 ticks) at random into two parts, each of which was then also divided in two. After performing these operations over 15 intervals, 60 values ​​were obtained in the range from 1 to 13 “ticks”, and the sum of all these values ​​was exactly 240.
    Unfortunately, I could not implement the first or second algorithms on ATtiny13 due to the extremely small memory size of this MK (1 KB FLASH and only 64 bytes of SRAM). Probably some assembler guru could do this, but I did it easier and rigidly hammered into the code one table of interval durations. The fact that the rhythm of the movement of the arrow will be repeated every minute should not be immediately evident.
    The program is organized as follows. Each tick (1/4 of a second) by timer interruption is generated, during which the tick number is checked, and, if necessary, voltage is applied to the motor winding, and the duration of the next interval is extracted from the table. After 100 ms, a second interrupt is generated, by which the voltage supplied to the winding is turned off. The rest of the time, the controller is in sleep mode to reduce power consumption. A link to the full source code is provided at the end of the article.
    It is also necessary to flash the Fuse-bits of the controller in order to enable the external clock mode (values ​​other than the factory ones are highlighted):

    SELFPRGEN = 1
    DWEN = 1
    BODLEVEL1 = 1
    BODLEVEL0 = 1
    RSTDISBL = 1
    SPIEN = 0
    EESAVE = 1
    WDTON = 1
    CKDIV8 = 1
    SUT1 = 1
    SUT0 = 0
    CKSEL1 = 0
    CKSEL0 = 0

    I hasten to note that after installing the fuses in this way, the controller cannot be reflashed without an external clock source.

    Assembly


    So, the controller is programmed, installed on the board, which, in turn, is fixed in the case with a drop of glue. You can assemble the mechanism back, fix the arrows and enjoy the result:


    Yes, my watch also goes in the opposite direction, which further drives the random observer crazy.

    References


    1. Source code of the firmware: http://pastebin.com/P3y6wBUh
    2. Similar project: Vetinari's Clock
    3. Ultra Low Voltage AVR Operation: Using an AVR as an RFID tag

    Also popular now: