Slow Zero

Hi, I have a solar recharged battery powered project that used an AVR 328p at 8Mhz, it drew about 4mA which was acceptable. Well actually, because I ran out of memory I had two MCUs on the board sharing the load, but one was asleep most of the time. Well I thought it was time to step up to the SAMD21, so I'm tinkering with a Zero.

The ARM draws quite a bit more current running at 48Mhz. I don't want to sleep the MCU because it is monitoring a very slow moving (if at all) signal, and using interrupts would be problematic. 8Mhz is plenty quick for what I'm doing so I changed the division factor of GCKL0 to 6, ie 48/6 = 8Mhz. Great, that brought the current draw down to what the AVR was using. But now everything "Arduino' is out of whack. Delays take 6 times longer than requested. The USB no longer works. Who knows what else is broke.

What changes to the core code can you think of to get the ZERO working again in the IDE, with a CPU of 8Mhz?

void setup() {

 GCLK->GENDIV.reg =  0x600 ; // Generic Clock Generator 0

Edit the boards.txt file and change the line for the board type you're using that is similar to:

(Better yet, create a new board type just for your 8MHz projects.)

You would be better off leaving the clock at 48MHz and using sleep mode. This won’t prevent your circuit from monitoring the sensor. Just sleep for short periods, e.g. 8ms, and check the sensor each time it wakes. The samd21 is not like esp8266, where deep sleep can only be ended by a reset which looses the program state and all the variables. Is more like the sleep modes on the ATmega. Using sleep modes will achieve far lower current consumption than lowering the clock speed.

If you are concerned about current consumption, then the model of Zero-compatible Arduino you use is important. Some are not really designed for very low power and contain components that waste a lot of current all the time, no matter what the samd21 is doing. Other zero compatible boards have components much more carefully chosen to minimise wasted current.

Thanks for your replies.

westfw, I changed the frequency in boards.txt for the ZERO native port but it didn't affect any change. Odd.