Saturday Clock: An 0.000011574Hz ATtiny85 Clock

Saturday clock - 1 CPU clock cycle per day

In these times when we try to squeeze out extra clock cycles by adding more cores to our CPUs and by enlisting the aid of GPUs, [Ido Gendel] thought it would be fun to go in the exact opposite direction, supply a clock to the ATtiny85 that cycles only once per day, or at 0.000011574Hz. What application could this have? Well, if he could do it in seven instructions or less, how about turning on an LED at sunset Friday evening, to indicate the start of the Jewish Shabbat (Saturday), and turn it off again at sunset Saturday evening.

Notice the subtlety. A clock that cycles once per day means you can execute at most one instruction per day. Luckily on AVR microcontrollers, the instructions he needed can execute in just one cycle. That of course meant diving down into assembly code. [Ido] wasn’t an assembly wizard, so to find the instructions, he compiled C code and examined the resulting assembly until he found what he needed. One instruction turns on the LED and the instruction immediately following turns it off again, which normally would make it happen too fast for the human eye to register. But the instruction to turn it on runs on Friday evening and the very next instruction, the one that turns it off, doesn’t run until Saturday evening. Do you feel like you’re in a science fiction story watching time slowed down? Freaky. A few NOPs and the jump for the loop take up the remaining five cycles for the week.

For the source of the clock he chose to use an LDR to detect when the light level dropped at the end of the day. The problem he immediately ran into was that clouds, bird shadows, and so on, also cause drops in the light level. The solution he found was to widen the light and dark range by adding a TLV3702 push-pull output comparator and some resistors. [Ido] gives a detailed explanation of the circuit in the video after the break.

Our own [Elliot Williams] dug into the AVR microcontrollers and wrote up this wonderful article about the AVR microcontrollers’ clock.

https://www.youtube.com/watch?v=fQeSMwEnRCU

40 thoughts on “Saturday Clock: An 0.000011574Hz ATtiny85 Clock

    1. I think ISO/engineering notation would recommend micro hertz, to get two berfore and some after the comma. Usually up to three before the comma. Once it reaches four or less than 1 you switch to the next 10^3.

      1. How do you call an event which is periodic ?
        And trust me, it is. I made a (software) pll that was driven by this same process,but with a PV cell.
        It took time to stabilize, but it was accurate to the minute.

    1. Or use the reciprocal of Hz: period.Period time of 86400s or more usefully, 24 hours. But then the story about overclocking in the Ghz range doesn’t add up. A period of 250 picoseconds doesn’t sound as impressive as 4GHz :)

    1. No, but a pair of quad D-flip-flops could do it. Wire D input of the first FF high, wire the Q output of each FF to the D of the next, and wire the Q of the last FF to the R pin of all the others. Wire the clocks of all to your photo-detector circuit.

      When the last one goes high, it’ll reset the entire circuit to zero. You can alter the period by the number of D flip flops chained together.

        1. One isnt, but you can use them as a window comparator with flipflop. Thus, you can make logic gates and registers using 555s. It should be possible to make a cpu out of many of them

          1. Really? Diodes (real-world ones that is) can be used for some types of logic but can’t do complex things, even ideal diodes aren’t general (can’t do inverters).

    1. Reverse engineering code is often easier than reading documentation.
      I always read the source code of most libraries I use to find out their functions instead of opening a Doxygen-generated HTML page, which is often worse than the source code itself. Also, reading source code is the only way to use old and/or obscure poorly documented libraries.
      Searching for functions and keywords can be done with grep and its -r option, or by using an IDE.

      1. I agree that it’s easier to start from reading examples, but looking at compiled C/whatever code to learn assembly is masochistic. Assembly is a very simple language, and there are good guides out there.

        But hey, different people learn in different ways and getting the end result in a way that suits yourself is the most important thing.

        As an exercise I searched for some info on AVR assembly, and I think the required program is likely to be:

        NOP; // mon
        NOP; // tue
        NOP; // wed
        SBI DDRB,0; // set pin to output mode [thu]
        SBI PORTB,0; // turn on [fri]
        CBI PORTB,0; // turn off [sat]
        NOP; // sun

      2. atmel assembly is not poorly documented though… It was a hobbyist favorite way before arduino. (RTFM NOOB!)
        I don’t think reverse engineering is often easier than reading doc (ever).

Leave a Reply to bit0funCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.