Does the 'Clock Divide' fuse reduce power consumption of the Microcontroller?

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to run an ATMega328 at 1 MHz to conserve battery power.

For the program I'm running on it, 8 MHz is a waste of power. 1 MHz should be enough.

 

But the internal oscillator for ATMega328 has only one frequency to be set: 8 MHz. (While working with ATMega16, I've seen a host of clock speed options: 1 MHz, 2 MHz, 4 MHz and 8 MHz.)

 

There is another option for the 328: Divide the clock by 8.

 

I was wondering, would this option get the MCU running at 1 MHz and most importantly, reduced power consumption like running ATMega16 at 1 MHz (without Clock Divide Fuse)?

 

Or does this option simply runs the MCU oscillator at 8 MHz, consumes as much power as at 8 MHz, but executes instructions at 1 MHz speed?

This topic has a solution.

Last Edited: Sat. Jul 4, 2015 - 12:23 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

The internal oscillator always runs at 8 MHz (or whatever frequency you've tweaked it to with OSCCAL).  The CKDIV8 fuse preloads the CLKPR register after a reset so that the core and peripherals run at 1/8th of that frequency.  While the current drawn by the oscillator won't change (about 96 uA, depending on the device), the current drawn by the rest of the device will be proportional to the divided clock:

 

All of this is in the datasheet (which you should read!):

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perfectly answered my question! Thanks a lot!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Glad to help.

 

If power consumption is your goal, consider going to sleep instead of slowing down.  In general (and it does depend), it is better to run fast and sleep longer, than to run slow and sleep less.

 

State your overall goal.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

YES AND NO. YES, as shown above. But NO on the basis of energy per instruction; that remains unchanged.

 

If you have some time where the MCU does not need to do anything, then run it at max clock speed and sleep the rest of the time. THAT will give you the lowest power consumption.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

ka7ehk wrote:

YES AND NO. YES, as shown above. But NO on the basis of energy per instruction; that remains unchanged.


That actually depends upon the clock source.
If you are using a fixed clock source but are dividing it for use by the core and peripherals, then the cost per instruction actually goes up as the divided clock goes down. This is because the oscillator has a constant draw whick doesn't depend upon the divisor.
If you can control the clock source directly, then yes the cost per instruction remains relatively constant. For example you could use OSCCAL to slow down the internal RC oscillator instead of using a divided clock. The extent to which you can slow the clock is of course much less vs. a divided clock, and you can't do that easily with an external clock or a resonator.
There may be other reasons for running with a divided clock. For example when VCC=1.8V, you must run no faster than 4 MHz. OSCCAL alone may not get you there (although typically it can).

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now I get a clear idea. Thanks so much, everyone! smiley

 

Jim, you are right! Running at full speed and sleeping at idle is indeed a great idea. I have seen computers save power like that.

 

Joey, my project is a clock, a temperature and humidity sensor and a barometric pressure sensor, polled every second. Is there any possibility of the processor sleeping in the meantime?

 

I have another question. Most AVR chips nowadays are capable of going upto 16 MHz. But we need an external crystal to achieve that rate because the internal oscillator does only 8 MHz. So why isn't there a fuse setting that can multiply the internal clock by 2?

Last Edited: Tue. Jul 7, 2015 - 01:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simple answer: because there isn't! RC oscillators integrated were bleeding edge when the AVR was released. Even having flash, eeprom and adc on the one chip was revolutionary. Nowadays, the new chips have plls and much more stable internal oscillators. Such is progress. If you want new features, go for a new chip.
I could ask -'why doesn't my car have iphone integration'?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there any possibility of the processor sleeping in the meantime?

That's the CORE of any design that is battery powered. You should be thinking all the time "how can I get back to sleep". Don't throw this in as an afterthought at the end - make it one of your primary design decisions at the start.

So why isn't there a fuse setting that can multiply the internal clock by 2?

Clock multiplication is done by a PLL. A lot of modern micros have PLLs. On the whole AVR8's don't though some model like AT90PWM models do have a PLL for specialist purposes. If you want to play the clock multiplication game look at Xmega or SAM chips. (generally all 3.3V too)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So why isn't there a fuse setting that can multiply the internal clock by 2?

If you really want to go a bit faster...

 

But why?  Your original post says that you want to go slow.  Now you want to go fast?

 

Pick an AVR8 for tasks that are suited to an 8-bit microcontroller running at a relatively modest clock rate. Compared to a design with a system clock in tens or hundreds of MHz, tools are cheaper; layout less critical; less emissions.  Over the past fifteen years we have many scores (probably hundreds) of production AVR8 designs.  Only one runs faster than 8MHz.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

But the internal oscillator for ATMega328 has only one frequency to be set: 8 MHz. (While working with ATMega16, I've seen a host of clock speed options: 1 MHz, 2 MHz, 4 MHz and 8 MHz.)

 

There is another option for the 328: Divide the clock by 8.

It seems that you are not aware of the clock prescaler register that is on [all?] recent AVR8 models, CLKPR.

 

The "option" to divide by 8, the CKDIV8 fuse, does nothing but jam a corresponding value into CLKPR.

 

And, re your initial question, what does the datasheet say about CLKPR?

 

l9.11 System Clock Prescaler
The ATmega48A/PA/88A/PA/168A/PA/328/P has a system clock prescaler, and the system clock can be divided by setting the ”CLKPR – Clock Prescale Register” on page 387. This feature can be used to decrease the system clock frequency and the power consumption when the requirement for processing power is low. This can be used with all clock source options, and it will affect the clock frequency of the CPU and all synchronous peripherals. clkI/O, clkADC, clkCPU, and clkFLASH are divided by a factor as shown in Table 29-12 on page 324.

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Your original post says that you want to go slow.  Now you want to go fast?

But it was pointed out that going slow is not necessarily the best way to minimise the system power consumption - so the change of tack goes to show he's listening...?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bagho wrote:
Joey, my project is a clock, a temperature and humidity sensor and a barometric pressure sensor, polled every second. Is there any possibility of the processor sleeping in the meantime?
It will depend upon the sensors you are using, but yes it should be possible to sleep almost all of the time.

 

With a 328P, the general approach I would take would be to run from the internal calibrated RC oscillator, while using a 32.768 kHz watch crystal to clock TIMER2 for timekeeping.  This will give you speed when you need it (to poll and process data while awake), and accurate timekeeping even while asleep.  Current consumption while asleep can be as low at 750 nA.

 

Can you tell more about the specific sensors you will be using?  Part numbers would be best.

 

Also, what will you be doing with all of this data?  Display locally (LCD, etc.)?  Store locally (EEPROM, SD, etc.)?  Transmit (wireless, serial, etc.)?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bagho wrote:
my project is a clock, a temperature and humidity sensor and a barometric pressure sensor, polled every second.

None of those sensors is reading anything that's likely to be changing very fast at all - so do they really need to be polled every second?

 

Quote:
Is there any possibility of the processor sleeping in the meantime?

Look at the datasheets for your sensors; they will tell you how long each one takes to read - a bit of simple arithmetic will then tell you how long is left for sleeping!

 

Have you taken care to select low-power sensors?

 

And a low-power clock "display"?

 

As Cliff says, this is all basic stuff that needs to be considered at the outset for a low-power system.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Jul 7, 2015 - 05:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you! Thanks a lot for such detailed, excellent answers. Now I get the hang of internal oscillators and how the chip works.
 

 

"Now you want to go fast?"

 

Not really. It was just my curiosity that asked the question. That said, after reading in this thread that running the chip at full speed and then sleeping would be very useful for battery powered projects. So I was also considering running at 16 MHz for a few miliseconds and sleeping the rest of the time. smiley

 

Yes, I'll be running a DHT-11 and a DS3231 for now (I'm leaving the BMP180 right now for the sake of simplicity on the I2C bus.) The project works fine. The clock is polled every second to update the 'seconds.' But I can very well do away with polling the DS3231 and DHT-11 every minute and sleeping the rest of the time. smiley

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The DS3231 can be configured to give a pulse every second (or when matching either of the internal alarm registers).  You can use it to wake up the 328P.  No need to fetch the time from the DS3231 every second, either.  Poll it once on power up, and maybe once an hour or once a day after that.  Maintain your own hour/minute/second variables internal to the 328P.  Much faster, much less time spent in active mode, much less power consumed.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You still haven't said what kind of "display" or "output" this system has ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, Joey! Yes, I just edited the code to poll the RTC and Sensor once every minute, and display the seconds as an internal counter of the ATMega328.

Awneil, sorry I missed it. The project uses a 20x4 LCD.

A little off topic question: Does polling the RTC every second i.e., 86,400 times a day, 31 million times a year, cause the RTC to get damaged quickly? Is there a theoretical limit to chip reads just like EEPROM writes (100,000 times)?

Last Edited: Wed. Jul 8, 2015 - 01:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Is there a theoretical limit to chip reads just like EEPROM writes (100,000 times)?
In theory yes there is a limit to everything.  I don't think reads have been profiled for this device.  I suspect if they were, the projected lifetime would be something approaching the heat death of the universe wink

 

So I wouldn't sweat the thunder showers...

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Really? Haha, that's a nice answer! smiley So there's nothing to sweat over. Now my project is ready to poll the RTC once a minute (so the RTC would last 60X the time till the end of the universe) and make the MCU sleep for the whole minute, just wake for a second to update the time, temp, humidity and barometer, and go off to sleep. But the big challenge is minimizing power consumption. If the wake is triggered by a 555 IC, the 555 would consume at least 5 miliamps. Any ideas?

 

By the way, nice video! smiley

Last Edited: Thu. Jul 9, 2015 - 11:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you not read #16 ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...