Skip to main content
Arduino

Return to Answer

+ demo code.
Source Link
Edgar Bonet
  • 45.1k
  • 4
  • 42
  • 81

You can set the clock prescaler for that:

void setup() {
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
}

This is explained in section 10.12 and 10.13 of the ATmega2560 datasheet.

Of course, changing the clock frequency will mess with the time-related function (millis(), delay() and co.) and the baud rate of the serial port.

Edit: Here is a small program to demonstrate the slowing of the clock:

//#define SLOW_CLOCK
void setup()
{
#ifdef SLOW_CLOCK
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
#endif
 pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
 digitalWrite(LED_BUILTIN, HIGH);
 delay(500);
 digitalWrite(LED_BUILTIN, LOW);
 delay(500);
}

This makes the LED flash at 1 Hz. If you uncomment the line #define SLOW_CLOCK, it instead flashes at 0.5 Hz.

You can set the clock prescaler for that:

void setup() {
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
}

This is explained in section 10.12 and 10.13 of the ATmega2560 datasheet.

Of course, changing the clock frequency will mess with the time-related function (millis(), delay() and co.) and the baud rate of the serial port.

You can set the clock prescaler for that:

void setup() {
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
}

This is explained in section 10.12 and 10.13 of the ATmega2560 datasheet.

Of course, changing the clock frequency will mess with the time-related function (millis(), delay() and co.) and the baud rate of the serial port.

Edit: Here is a small program to demonstrate the slowing of the clock:

//#define SLOW_CLOCK
void setup()
{
#ifdef SLOW_CLOCK
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
#endif
 pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
 digitalWrite(LED_BUILTIN, HIGH);
 delay(500);
 digitalWrite(LED_BUILTIN, LOW);
 delay(500);
}

This makes the LED flash at 1 Hz. If you uncomment the line #define SLOW_CLOCK, it instead flashes at 0.5 Hz.

+ ref and side-effects.
Source Link
Edgar Bonet
  • 45.1k
  • 4
  • 42
  • 81

You can set the clock prescaler for that:

void setup() {
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
}

This is explained in section 10.12 and 10.13 of the ATmega2560 datasheet .

Of course, changing the clock frequency will mess with the time-related function (millis(), delay() and co.) and the baud rate of the serial port.

You can set the clock prescaler for that:

void setup() {
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
}

You can set the clock prescaler for that:

void setup() {
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
}

This is explained in section 10.12 and 10.13 of the ATmega2560 datasheet .

Of course, changing the clock frequency will mess with the time-related function (millis(), delay() and co.) and the baud rate of the serial port.

Source Link
Edgar Bonet
  • 45.1k
  • 4
  • 42
  • 81

You can set the clock prescaler for that:

void setup() {
 noInterrupts();
 CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
 CLKPR = _BV(CLKPS0); // divide frequency by 2
 interrupts();
}

AltStyle によって変換されたページ (->オリジナル) /