Author Topic: How to change the clock rate on the bootloaderconfig file and compile it?  (Read 2703 times)

zeno

  • Newbie
  • *
  • Posts: 3
I want to set my Digispark to run on 1Mhz (so it can run on coin cell batteries, even those that are not very new).

First I tried using it "on the fly" adding a code to my sketch. I could see the code worked, but when the Digispark is initialising it still runs on 16MHz (or 16.5?) so with low batteries (2.6V) it wouldn't start. Then I also tried to upload my code using the board option for 1MHz on Arduino IDE, but probably this gives the same result as I couldn't make it work on my battery (2.6V).

So I decided to try uploading a new bootloader (I already learned how to do this with micronucleus) but I'm not sure where to change this setting on the bootloaderconfig.h file. The file states:

#define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
 * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code
 * require no crystal, they tolerate +/- 1% deviation from the nominal
 * frequency. All other rates require a precision of 2000 ppm and thus a
 * crystal!
 * Since F_CPU should be defined to your actual clock rate anyway, you should
 * not need to modify this setting.
 */

So what should I change to make it 1Mhz?

After doing this, I just have to compile it using AVR-GCC right? I appreciate any help, thanks!

dl4ou

  • Newbie
  • *
  • Posts: 15
Re: How to change the clock rate on the bootloaderconfig file and compile it?
« Reply #1 on: February 03, 2018, 03:06:22 am »
It's a nice idea to run the DIGISPARK with 1MHz. But the USB-Software runs only with the "Legal values" of the clock rate.
That means, that the DIGISPARK needs at least 12 MHz clock rate to use USB.
If you choose a lower frequency for the clock rate in the bootloader, the boatloader will be useless.

To run the DIGISPARK at 1 MHz you have to change the fuses of the ATTINY85 (please refer to the datasheet).
To program the 1MHz-DIGISPARK, you could use the ISP interface. The USB Interface would not run with 1MHz.

The DIGISPARK is not made for low power operation.
« Last Edit: February 06, 2018, 11:03:48 am by dl4ou »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: How to change the clock rate on the bootloaderconfig file and compile it?
« Reply #2 on: February 03, 2018, 10:15:12 pm »
Yeah, I'm pretty sure the "Digispark (1mhz - No USB)" option is the same as your 'change on the fly'... for the USB connection it HAS to clock higher, and then can back off to 1Mhz. So only two options I see possible... try using the jumper-only bootloader option, or ISCP/ISP programming only... because as dl4ou said, the Digispark isn't optimised for low power / low speed.

zeno

  • Newbie
  • *
  • Posts: 3
Re: How to change the clock rate on the bootloaderconfig file and compile it?
« Reply #3 on: February 04, 2018, 09:22:19 am »
That's great, thanks a lot for your replies, it's much more clear now. I will be using 12MHz then (I have managed to compile it on Windows with WinAVR, Ruby and some manual work). I may try starting with 12MHz and then reducing on the fly to 1MHz to save battery, I think this will be enough for this project.

Thanks!