Author Topic: How to underclock CPU speed  (Read 24407 times)

skyforce

  • Newbie
  • *
  • Posts: 3
How to underclock CPU speed
« on: February 25, 2014, 11:21:24 pm »
Hi,everyone:

 

In my on-going project, I use one CR2025 battery to push digispark.
CR2025 have 3v output, and it's safe for ATTiny85 working at 8MHz .

 

But Digispark's CPU seems working at 16 or 16.5MHz.
3v should be not enough for 16MHz, only if I underclock to 8MHz.
I found this page say underclock can save power, but did't explain how to ...
http://digistump.com/wiki/digispark/tricks#underclock_the_cpu_to_save_power
 

According other ATTiny post on internet, change fuse in ATTiny can modify the CPU speed.
But Digispark disable the RESET pin, so ISP programming is impossible, otherwise using HVSP(High-Voltage Serial Programming), but it needs extra circuit to go.
 

Can someone teach me some simple method to solve this problem, thanks.

 
« Last Edit: February 26, 2014, 04:30:30 am by skyforce »

gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: How to underclock CPU speed
« Reply #1 on: February 26, 2014, 01:02:28 am »
Just use from the boards "Digispark 8MHz - No USB (Tiny Core)", when you are compiling!

With fuses you are setting the clock start conditions of the attiny, which you can change later at run time.  The fuse settings determine the start condition for the boot-loader.
The Micronucleus bootloader needs always to be able to initialize first.  The bootloader hands over control to your compiled sketch aka firmware, which initializes the clock settings, depending on the selected board.

However your question rises one question, Bluebie or cpldcpu should be able to answer:

I checked the recommended fuse settings from the boards.txt, and realize, that the digispark starts with CKSEL[3:0] being 0001, so the attiny85 starts with PLL 16MHz.
What happens now, if its only powered by 3V? Is there an risk, that the application will not start, because its overclocked related to the voltage?
Should the bootloader not start with a recommended low-power fuse setting, and rise the clock only to the needed USB speed, when powered with 5V or USB connection is detected?

The Attiny85 needs at 16MHZ around 3.8V (Atmel documentation page 163)
The upcoming PRO (attiny167 ) needs at 16MHz at least 4.5V (Atmel documentation page 245)

Or am I wrong with my idea?

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: How to underclock CPU speed
« Reply #2 on: February 26, 2014, 01:39:40 am »
@gogol - I'm running Attiny167s (and Digisparks) at 3.3v at 16Mhz with no issues - not to say it can't happen, but I haven't see any issues in normal usage at normal temps.

gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: How to underclock CPU speed
« Reply #3 on: February 26, 2014, 03:32:58 am »
As the time, the cpu is running to fast for the voltage is very short (only the time, the bootloader needs to change to the users firmware), the risk seems to be small.
I am only curios, if someone has thought about.  The speed/voltage diagram of the attiny167 looks more critical, than that of the attiny85.
I have two digisparks running with 16MHz from 3.7V LiIon batteries without any issues; however that is almost in the range.

Palatis

  • Newbie
  • *
  • Posts: 1
Re: How to underclock CPU speed
« Reply #4 on: March 04, 2014, 12:21:38 pm »
Okay, I find that tricky.

When I select the 1MHz variant from the board menu, the cpu is still running at 16MHz.
I had to manually set the CLKPR by doing:
Code: [Select]
noInterrupts();
CLKPR = 1 << CLKPCE;
CLKPR = 0b00000100; // prescaler 16
to get 1MHz system clock.

my doubt is, i'm also on a CR2032, when the device is running fine, it's just fine because we can run 4mhz down to 1.8v (according to the datasheet).
but when the user plugged in a half-way dead battery (like 2.7v only), the device is gonna get into a embarrassing reboot-loop, even though we have enough power to run the "firmware" at 1MHz.

btw, my chip works with 16MHz on a new battery (air temperature at 14 deg celcius), considered overclock I guess...

skyforce

  • Newbie
  • *
  • Posts: 3
Re: How to underclock CPU speed
« Reply #5 on: March 05, 2014, 10:17:53 pm »
I had do three experiment :

 
1.  I use internal timer for controling the LED on and off, when I select 1MHz, 8MHz and 16MHz, the interval between LED on and off is different, so cpu speed is correct as I select.

2. I set cpu speed to 8MHz, plug USB 5V as power source, and load a sketch for lighting LED on and off.
After 5 seconds booting, Digispark start working and light the LED, then I attached the CR2025 and unplug the USB, the power voltage is change from 5V to 3V, but LED is still working and good behavior(but light from LED is getting dim).

If I use CR2025's 3V to boot Digisparl, it is almost fail, LED is not working fine.

3. I use multimeter to measure current , in first 5 seconds it cost 12~15mA.
When sketch is load and LED is lighting, it cost 7~8mA.
I guess in the first 5 seconds, the time bootloader micronucleus wait for sketch uploading, cpu speed is 16MHz.
After 5 seconds, sketch is working, and cpu speed is turn to what you select.

In my case cpu speed is down to 8MHz.

Maybe it can explain why my CR2025 is hard to boot Digispark and work:
3V is not enough for 16MHz.

« Last Edit: March 06, 2014, 07:55:30 am by skyforce »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: How to underclock CPU speed
« Reply #6 on: March 05, 2014, 11:15:35 pm »
To avoid the 5 second time of it running at 16mhz try installing one of the new bootloader versions that either requires a jumper to activate or only activates when a USB signal is present

gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: How to underclock CPU speed
« Reply #7 on: March 06, 2014, 01:16:37 am »
I guess in the first 5 seconds, the time bootloader micronucleus wait for sketch uploading, cpu speed is 16MHz.
After 5 seconds, sketch is working, and cpu speed is turn to what you select.

In my case cpu speed is down to 8MHz.

Maybe it can explain why my CR2025 is hard to boot Digispark and work:
3V is not enough for 16MHz.

That was exactly, what I was guessing, when I answered you. 
Digistump is right, that the new bootloaders could solve this issue.
In that case, it would be even more helpful, when the  fuses would be set to 8 or 1 MHz, the bootloader would only increase to 16MHz, when asked to do so.
Otherwise the init of the sketch would change the speed to the selected speed of the sketch.

@Bluebie , @cpldcpu :  Is that possible?


cpldcpu

  • Newbie
  • *
  • Posts: 30
Re: How to underclock CPU speed
« Reply #8 on: March 06, 2014, 01:33:40 am »
Gogol, you can configure micronucleus in many ways, so this is entirely possible. You may however need to compile your own version adapted to your needs.
« Last Edit: March 06, 2014, 01:41:28 am by cpldcpu »

salukikev

  • Newbie
  • *
  • Posts: 1
Re: How to underclock CPU speed
« Reply #9 on: July 27, 2019, 08:21:58 am »
I registered here because of this thread, and was wondering if the newer Digispark's have addressed this.  I just started experimenting but am hoping my application will be able to use a cr2032 reliably.  Just flashing an LED and delivering a beep every few minutes ad infinitum, so clock speed isn't a big issue, certainly not compared to battery life.  I'm actually a little surprised there aren't more chips prioritized toward power saving at super low clock speed.   Anyway, now that I've sorted out the drivers of this digispark, I'm having fun- it's a neat little module.

PS.  My only change so far has been selecting the alternate drivers in the arduino IDE.  It seems I don't need to change any of the code... do I?  (like user "Palatis" cited)