1Hz clock, sleep, LCD


I would like to create a clock or stopwatch, which simply counts how many seconds elapsed, possibly very precisely. And displaying the number on LCD.

I use ATmega168 with 16MHz crystal, I use watchdog every second to check whether millis() returns something greater by 1000 than previous millis(). Basically everything works, even LCD.

Now I would like to prolong battery life, i.e. I would like to go into sleep mode between the changes. The problem is, that when I enter sleep mode clock millis() stop to work correctly and even LCD library doesn't like it.

What I was thinking was that I could somewhere [1] add 32kHz crystal, pre-scale it so that an interrupt fires at 1Hz rate only, [3] attach a handler to the interrupt which would update the display and go to sleep again. But that's just my theory! Would it work? Do you have any suggestions?

[1] Where should I add the crystal? Which pin? Will it wake up the ATmega from sleep?

[2] Is it even possible to pre-scale the other clock input? Or do I have to count somewhere up to 32768 and then update and reset to 0?

[3] how to even run a routine on external event?

Btw, I have the sleep mode code from here:
But other suggestion are very welcomed, too!

There not a sleep mode but five! All have drawbacks - you have to comprise.
You most likely have understood this article?

The 32kHz crystal is connected instead of the 16 MHz crystal, which means in that case the arduino must rum from internal 8 MHz RC clock (the "Lilypad variant")

Yes, I read that there are 5 modes. I would like to run into the deepest one.

Isn't it possible to run Arduino off 16 MHz crystal and still fire my routine at 1 Hz rate off another 32 kHz crystal?

Yes, it is possible but it doesn't appear to address either of your problems...

I thought it could: put Arduino to sleep, wake after 1 second at full speed, do everything I now do (sec_counter++, update LCD), go to sleep again. Why do you think it wont work? And more importantly, how is it possible to use additional crystal to fire my handler?

  1. There are certainly other/better software methods of getting around the millisecond problem you are seeing.

I'll gladly follow another path but I don't know any other solution.. Perhaps you could share more details?

It doesn't seem to do anything for the display problem

I thought it would because while updating LCD, Arduino would run at its original speed.

The DS1307 is popular for this kind of application.