For a project that runs on a battery I want to reduce the clockspeed of the Arduino Nano Every wich I am using to increase batterylife. For the nano V3 (and some other boards) this seems to work by adding 'CLKPR = 0x80;
CLKPR = 0x02;' to the void setup. However, since the Nano Every runs on the ATMEL 2809 this code doesn't work with the Every. I have been looking at the ATMEL 2809 datasheet for a while to find out a similair command to reduce the clockspeed of the Every board but unfortunately I couldn't find something that works. Possibly because of my lack of experience with clockspeed adjustments. Therefore my question is if anyone knows with what code I can reduce the clockspeed of the Every, similair to how I reduced it on the Nano V3 board?
I guess I have to take some more looks at the data sheet. The code of my project is actually really simple so there isn't a lot of computing and a reduced clockspeed
therefor wouldn't harm the practical results of my project. With the 'CLKPR = 0x80; CLKPR = 0x02;' code I achieved a very usefull consumption reduction with the exact same project on a counterfeit pro micro board. Because of that I am looking for similar reduction with this Nano Every board. Adding sleep modes would have been my next step in my quest for improving batterylife but at the moment I am not very known yet with how to get that feature to work properly on the Every as well.
I must admit I am not sure about what you mean by the question if the other chips on the Every are under my control?
Use MCUdude's MegaCoreX and you can set the clock speed in the Arduino IDE Tools menu. The clock speed on the Nano Every is set via the fuses every time you upload a sketch, and uses the internal oscillator because there is no external crystal or oscillator on the board.
More precise would be to choose between internal 16 or 20MHz clock source by means of fuse setting. All the rest is adjustable by software. However, I don't think the TO wants to change the clock source.
Your solution seems to be accepted when compiling however I get the error: 'expected ')' before ':' token'. Making several changes didn't fix that problem. Maybe I am missing something here... This is my code at the moment.
// this ...
CPU_CCP = CCP_IOREG_gc;
CLKCTRL_MCLKCTRLB = CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm;
/* ... or this here in setup
_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm);
*/
You're not supposed to include the CLKCTRL_PDIV_2X_gc = (0x00<<1), /* 2X */ line - those are values that are already pre-defined for you; you just have to pick the one you want:
// with 16MHz oscillator, divide by 16 to get a 1MHz CPU clock:
_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_16X_gc | CLKCTRL_PEN_bm);