EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: philbx1 on June 01, 2010, 08:58:33 am

Title: Quartz clock module for reasonably accurate MCU wakeup
Post by: philbx1 on June 01, 2010, 08:58:33 am
Hi all,
Just looking back at an older Silicon Chip magazine "Circuit Notebook" article (Dec 2007 - Joe Colquitt)
where a cheap quartz clock module is used to wake up a PIC using an external interrupt
every 60 secs by clocking a 4040B binary counter plus 4081B divide-by-N-counter.
Apparently this setup only consumes around 100nA.
I have a timing project which I'm thinking of using this for, and although I might do better with a RTC module
thought I'd ask if anyone else here has used (or seen) this method.
And yes, I know many MCUs can use internal clocks, but I've yet to find something fairly accurate.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: stewartallen on June 01, 2010, 02:02:33 pm
Hi,

Have you looked at the Microchip PIC24 RTCC (Real Time Clock Calendar) with an external 32Khz watch crystal.  You can set up repeating alarms of almost any period.  The power consumption of the MCU and crystal in sleep mode was around 20-30uA with the device I was using it on.

You can pick up a watch crystal for a few cents, you'll also need two small 15-22pF caps (just check the datasheet for the crystal)

I've built a nice RTCC Lib, just shout and I'll put the code somewhere for you.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: alm on June 01, 2010, 08:54:02 pm
One strategy that might work if your temperature is fairly stable is to calibrate the internal RC oscillator periodically based on a 32.768kHz crystal, and run it from the RC oscillator the rest of the time. This might just be good enough. My guess would be that a power efficient micro which occasionally wake up will be more power efficient than thirty years old logic families, but I admit I didn't research it.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: philbx1 on June 03, 2010, 08:33:29 am
Hi Stewart,
Thanks for the suggestion and lib offer. Much appreciated, however I'm using AVR's (various)
so am pretty much after a generic solution.
Sounds like your lib is a good thing though.

...
You can pick up a watch crystal for a few cents, you'll also need two small 15-22pF caps (just check the datasheet for the crystal)
I've built a nice RTCC Lib, just shout and I'll put the code somewhere for you.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: philbx1 on June 03, 2010, 08:42:23 am
Hey Shafri,
Not so much a need for accurate timing, moreso low battery power usage.
I could handle up to 5 mins diff per day, and although my various Atmel MCU's could probably do
this OK internally (some won't) I'd just like them to sleep and be woken by an external interrupt.
BTW, the 'project' is a countdown timer for people to save electricity (especially the elderly).
Imagine a mains clothes-dryer type countdown timer maybe extended to 24 hours.

may i know you particular need for super accurate timing?
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: philbx1 on June 03, 2010, 08:48:05 am
Good comment Alm.

That would indeed work also I think. And you're probably right re. power usage of older logic chips.
Still, I haven't found anything that may be a more generic external wakeup solution.

One strategy that might work if your temperature is fairly stable is to calibrate the internal RC oscillator periodically based on a 32.768kHz crystal, and run it from the RC oscillator the rest of the time. This might just be good enough. My guess would be that a power efficient micro which occasionally wake up will be more power efficient than thirty years old logic families, but I admit I didn't research it.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: alm on June 03, 2010, 12:23:02 pm
What did the original circuit in Silicon Chip use as clock source, those counters only divide it down? You could obviously use any more modern logic family (whatever the most power-efficient is, note that dynamic power usage is often poorly documented in datasheets, and the power usage of CMOS depends on the amount of switching) with any counter (although you might not get exactly 60 seconds), but I wonder if driving a 32.768kHz crystal isn't the most power-hungry part? I know adding a crystal to a micro adds a significant amount of power draw compared to the internal RC oscillator, but that's with different kind of crystals. You need either a crystal or possibly ceramic resonator (I think they're more efficient, but also less accurate) as clock source, otherwise you might as well use the internal RC oscillator.

Something like that Microchip RTCC chip would probably be a more modern solution, if you don't want to do it all in the micro. You'll have to compare power usage, you might have to built the various options, since it's often hard to get power usage data when a chip is eg. 1% busy.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: NiHaoMike on June 04, 2010, 01:45:07 am
Hi all,
Just looking back at an older Silicon Chip magazine "Circuit Notebook" article (Dec 2007 - Joe Colquitt)
where a cheap quartz clock module is used to wake up a PIC using an external interrupt
every 60 secs by clocking a 4040B binary counter plus 4081B divide-by-N-counter.
Apparently this setup only consumes around 100nA.
I have a timing project which I'm thinking of using this for, and although I might do better with a RTC module
thought I'd ask if anyone else here has used (or seen) this method.
And yes, I know many MCUs can use internal clocks, but I've yet to find something fairly accurate.
Many RTC chips have a 1Hz output, which you can use to drive a low power CMOS counter. Or use a low power RC oscillator set to something like 50 seconds (just enough to cover inaccuracies), then have the microcontroller read the RTC and wait to get precise timing.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: stewartallen on June 04, 2010, 06:21:26 am
Hi, hissyfet

As NiHaoMike suggested a Real-Time clock will work.  All of them have some sort of configurable alarm with an interrupt output (http://www.maxim-ic.com/products/rtc/real-time-clocks.cfm), you can just set it for 1 sec and sleep the MCU, wake up on interrupt and reset the alarm for the next cycle.  The only problem is that they are pretty price parts, but if you also need to keep track of time and date in your product it might be the way to go.

A cheaper but more complex, software wise anyway, is..

Depending on what AVR family are you looking at using.  Almost all the AVR Mega and even some of the AVRTiny's have a built in RTC (Real Time Counter)(http://www.atmel.com/dyn/products/param_table_v2.asp?family_id=607&OrderBy=part_no&Direction=ASC). All you do is connect up a watch crystal TOSC1 TOSC2 pins,  Timer2 will now be able to run as a RTC.  You'll just need to config the clock source prescaler/timer value to cause an interrupt every 1s.  Have a look at " 8-bit Timer/Counter2 with PWM and Asynchronous Operation" section in the datasheets.  I see the AVRMega324P power consumption is specified as. In Power-save Mode: 0.6µA (Including 32 kHz RTC)
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: stewartallen on June 04, 2010, 06:26:45 am
Something like that Microchip RTCC chip would probably be a more modern solution, if you don't want to do it all in the micro. You'll have to compare power usage, you might have to built the various options, since it's often hard to get power usage data when a chip is eg. 1% busy.

Alm, that RTCC is not a separate IC, it's built into the PIC24 family of MCU's.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: horzza on June 19, 2010, 08:44:18 am
A cheaper but more complex, software wise anyway, is..

Depending on what AVR family are you looking at using.  Almost all the AVR Mega and even some of the AVRTiny's have a built in RTC (Real Time Counter)(http://www.atmel.com/dyn/products/param_table_v2.asp?family_id=607&OrderBy=part_no&Direction=ASC). All you do is connect up a watch crystal TOSC1 TOSC2 pins,  Timer2 will now be able to run as a RTC.  You'll just need to config the clock source prescaler/timer value to cause an interrupt every 1s.  Have a look at " 8-bit Timer/Counter2 with PWM and Asynchronous Operation" section in the datasheets.  I see the AVRMega324P power consumption is specified as. In Power-save Mode: 0.6µA (Including 32 kHz RTC)

I'm interested in this and was about to make a thread about it. I read two instructables where people had made wrist-watches using PICS which, in one of them at least, the firmware used an interrupt to wake the device every 2 seconds and increment the time by 2 seconds.

I'm wondering if someone can let me know if it's possible to only use the internal clock source on say an ATMEGA8, with no external crystal, to both handle this "wake from sleep and increment time" as well as output a unique pseudo-PWM on several output pins when the device is not in sleep mode.

I figured I was probably better off getting a yes or no now than wasting hours digging around just to find out it's not possible after all. I'm new to micros and only built an AVR programmer a few days ago. I'm finding it difficult to find out what C libraries and which C commands to use to make it do what I want, as well as being paranoid about fuse-bits and bricking my only device  ???
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: cybergibbons on June 19, 2010, 10:06:09 am
The DS3231 used on the Chronodot is quite a neat little RTC.

http://docs.macetech.com/doku.php/chronodot
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: MAN on June 19, 2010, 01:22:45 pm
A cheaper but more complex, software wise anyway, is..

Depending on what AVR family are you looking at using.  Almost all the AVR Mega and even some of the AVRTiny's have a built in RTC (Real Time Counter)(http://www.atmel.com/dyn/products/param_table_v2.asp?family_id=607&OrderBy=part_no&Direction=ASC). All you do is connect up a watch crystal TOSC1 TOSC2 pins,  Timer2 will now be able to run as a RTC.  You'll just need to config the clock source prescaler/timer value to cause an interrupt every 1s.  Have a look at " 8-bit Timer/Counter2 with PWM and Asynchronous Operation" section in the datasheets.  I see the AVRMega324P power consumption is specified as. In Power-save Mode: 0.6µA (Including 32 kHz RTC)

I'm interested in this and was about to make a thread about it. I read two instructables where people had made wrist-watches using PICS which, in one of them at least, the firmware used an interrupt to wake the device every 2 seconds and increment the time by 2 seconds.

I'm wondering if someone can let me know if it's possible to only use the internal clock source on say an ATMEGA8, with no external crystal, to both handle this "wake from sleep and increment time" as well as output a unique pseudo-PWM on several output pins when the device is not in sleep mode.

I figured I was probably better off getting a yes or no now than wasting hours digging around just to find out it's not possible after all. I'm new to micros and only built an AVR programmer a few days ago. I'm finding it difficult to find out what C libraries and which C commands to use to make it do what I want, as well as being paranoid about fuse-bits and bricking my only device  ???

It depends on what is the task like.

You may use ?alibrated internal RC oscillator on ATMEGA8 to wake up from IDLE mode. IDLE mode allows Timer/Counters to continue operating after SLEEP instruction. But power consumption in IDLE mode is too high (for battery power application for example).

If power consumption and timekeeping are the essential factors you may use Power Save mode. In this mode you have to use external 32 kHz crystal and program Timer/Counter2 for asynchronous aperation before SLEEP. Quote from datasheet 2486O–AVR–10/04: " The device can wake up from either Timer Overflow or Output Compare event from Timer/Counter2 if the corresponding
Timer/Counter2 interrupt enable bits are set in TIMSK, and the global interrupt enable bit in SREG is set."
Timekeeping function you may organize in software. When the device is not in sleep mode you may program Timer/Counter2 for real PWM operation.

If precise timekeeping is not essential (using internal RC oscillator you can archive 1% accuracy only) it is possible to use Watchdog Timer & Power Down mode. For example, I used this on MCU which doesn't have IRQ on pin change future. Just don't forget to enable WDT before SLEEP  :)

Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: horzza on June 19, 2010, 01:40:08 pm
Timekeeping function you may organize in software. When the device is not in sleep mode you may program Timer/Counter2 for real PWM operation.

Thank you for your help! What a great idea to re-purpose the timer on wake up.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: Zero999 on June 19, 2010, 10:23:41 pm
What frequency do you need, does it have to be once a minute?

A 1Hz timebase can be made using a 4.194304MHz crystal and a HEF4521 CMOS IC.

Of course, if you take the output from Q24, you'll get one pulse every 4 seconds and if you use a 3.2768kHz crystal you can get one pulse per 8 seconds up to 512 seconds, if you take the output from Q24.
Title: Re: Quartz clock module for reasonably accurate MCU wakeup
Post by: scrat on June 23, 2010, 11:26:53 am
What did the original circuit in Silicon Chip use as clock source, those counters only divide it down? You could obviously use any more modern logic family (whatever the most power-efficient is, note that dynamic power usage is often poorly documented in datasheets, and the power usage of CMOS depends on the amount of switching)

Just a tip. If you plan to use logic ICs like counters or gates...  Check NXP HEF/HEC or low-power HC/HCT series, they usually specify formulas for power dissipation on their datasheets.