I'm trying to debug a problem and need to reduce the speed of the clock on my Arduino Mega from 16MHz to 8MHz.
I can't find any simple way of doing so, so I wanted to know if there were any gurus here who knew if this was possible, as well as how to do it.
WITHOUT PRESCALER:
long int runTime;
void setup()
{
Serial.begin(9600); //Setting the data transfer rate
}
void loop()
{
delay(1000);
runTime = millis();
Serial.print("Runetime: ");
Serial.println(runTime);
delay(100);
exit(0);
}
OUTPUT: 999
WITH PRESCALER:
long int runTime;
void setup()
{
Serial.begin(19200); //Setting the data transfer rate for when CLK Freq. is Halfed
CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
CLKPR = _BV(CLKPS0); // divide frequency by 2
}
void loop()
{
delay(1000);
runTime = millis();
Serial.print("Runetime: ");
Serial.println(runTime);
delay(100);
exit(0);
}
OUTPUT: 999
noInterrupts()
andinterrupts()
. Otherwise there is a small possibility of this failing. Also, your test only proves the clocks ofdelay()
andmillis()
have changed consistently. Which is to be expected since it's the very same clock. – Edgar Bonet Jun 23 '16 at 18:05