Saturday Clock: An 0.000011574Hz ATtiny85 clock

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.

44 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).

  1. “[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.”

    This is what’s wrong with the whole “Maker” movement. God-forbid you actually hire one of these Snowflakes and expect a real return on your investment.

    1. I learned coding 8086 assembly by reverse-engineering* a FORTH (MVP FORTH) coded program that was “compiled” into an executable. Why would learning by reverse engineering C code be any different?

      IOW stop being an ignorant asshole.

      (* learned assembly, FORTH and learned how the virtual machine was constructed as a compiled program contained the whole FORTH system. Oh, I learned how to hack the graphics and sound on the machine too)

      1. How’s that again?

        It is generally understood that one of the major benefits of using FORTH is that it’s almost impossible to get the source code by dis-assembly or de-compilation, due to the very nature of how FORTH is built. This one factor is why Rockwell chose FORTH as their ONLY language with which to program the processor(s) on-board

        So, if you gained all that expertise by dis-assembling FORTH programs, you need to write a paper on your magnificent achievement, and submit it to both the IEEE and ACM, where publishing is almost guaranteed.

        You do need to be more careful with how much you reveal about your shortcomings, however, to wit: ” Why would learning by reverse engineering C code be any different?” With all your knowledge you should KNOW what the monumental differences are.

        I have one last delicate suggestion for an individual as learned as you obviously are: stop being an ignorant asshole

    2. I find it laughably coincidental that your comment is followed immediately by the following exposition of ANY lack of technical skills on the part of the commenter. What is pathetic is the writer’s attempt to PROVE his amazing skills. This is the kind of crap which will kill Hackaday, because it’s obvious that the editors/moderators either don’t have the knowledge (the editors know NOTHING about FORTH? Obviously not.) or don’t have the incentive to weed out this kind of horse shit before allowing it to be printed. One doesn’t have to look far in the Hackaday coments to find far too many similar examples (I’ve saved this in my ‘HUMOR’ file).
      *************************************************************************************************************

      “I learned coding 8086 assembly by reverse-engineering* a FORTH (MVP FORTH) coded program that was “compiled” into an executable. Why would learning by reverse engineering C code be any different?

      IOW stop being an ignorant asshole.

      (* learned assembly, FORTH and learned how the virtual machine was constructed as a compiled program contained the whole FORTH system. Oh, I learned how to hack the graphics and sound on the machine too)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s