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.
A good ‘bin day’ indicator!
Not sure if 11.574 micro-hertz or 11574 nano-hertz.
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.
First let me say I like this, the expertise of solving a problem, and see it through.
However, I don’t think I would say it’s clocked at .000xxx he, more of an event driven clock pulse
What if he added a clock, powered by a solar cell, so the hour hand trips a contact approximately every 24 hours.
Seems noisy… unless you *want* disco lights on cloudy days.
You’re implying that there is someone out there who wouldn’t want disco lights on cloudy days. Sounds like a good time to me
Yes, “event driven” is more accurate, but I couldn’t resist the comparison to the common MCU clock frequency figures.
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.
Cycle? ;)
ok, but it’s still a very jittery clock, since the duration of nights and days varies throughout the year (depending on your latitude of course).
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 :)
Couldn’t be done with a 555. :D
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.
http://www.longlandclan.id.au/~stuartl/hackaday/2017/03/22-sunday-clock/sunday-clock.png
Long time delays can be had in much simpler ways. A capacitance multiplier can be constructed with a single transistor or an op-amp.
http://www.tradeofic.com/uploadfile/ic-circuit/2009723224024423.gif
https://en.wikipedia.org/wiki/Capacitance_multiplier
Use that with the standard 555 timer and it’s possible to make considerably long delays because you can make a virtual 1000 F capacitor.
Interesting ideas here, I’ll study them further. Thanks!
I thought that it had been scientifically proven than any electrical circuit ever done could be replicated with 555’s :-)
Wow. So a 555 is, like, Turing complete?
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
Diodes are Turing complete.
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).
Many types of devices can be used to construct Turing complete machines. NOR/NAND gates, 2-1 MUXes, or even simple automatons like Conway’s game of life.
Once you have NOR or NAND you can make all possible logical gates.
Makes a new meaning of the word ‘sun-clock’ ;)
Well, he proved “fully static design, down to DC” from the datasheet. Well done.
Rather than NOPs, he could have it calculating Pi or finding primes on a glacial scale.
Shomer Shabbos!
Why must one go to this amount of trouble to write the simplest of assembly-language programs on the AVR (I am not familiar with that family of devices; thanks for enlightening me)?
I’m not sure whether you’re asking why write the program at all (to make the device work, of course! :-) ) or why it took so much effort (because I know very, very little Assembly).
One mustn’t … this was an exercise in masochism.
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.
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
And of course I forgot to jump back to the start of the loop.
I probably should have looked at some compiled examples instead of just skimming the datasheet!
:-)
Yeah the last NOP should be a jump indeed :).
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).
5 months from this date, it might gain a day though.
“[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.
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)
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
Or maybe the description here is simply incomplete. Did you read my original blog post?
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)
@ Drone–
Meant to be attached to your comment ending with “…This is what’s wrong with the whole “Maker” movement…”