Author Options:

What would happen if an Arduino had its crystal replaced with one at a different speed? Answered

Would the time functions (delay, delayMicroseconds, millis, micros) wait the same amount of time (or increment as fast as for millis and micros), or would their time or speed be affected?


Oh, I have just noticed that my chinese clones of Uno and Mega both have 12.000 crystals. Seems like it doesn`t affect anything though.

what will happen if i replace 12mhz instead of 16mhz

I tested it just barely and it works quite well but it is slow the difference is 16mhz(original) 8mhz(different) 1milisecond for the 8mhz is about 2miliseconds its about double the time.

Actually, the Arduino Uno's crystal is for the ATMega8U2. ☹ The ATMega328is clocked by a tiny surface-mount ceramic clock.

Steve is right (yes I have witnessed it although not with the Ardunio)

Not only do commands run faster some commands will not run at all at higher or slower speeds than intended.

I need something more specific. (For example, do delay, delayMicroseconds, millis, and micros remain the same speed?)

The arduinos have standard 16 MHz crystals although many times the actual ATMEGA chips are spec'd to run up to 20 MHz. Sometimes people change the crystal in order to reduce the chip's power consumption for projects that run on battery power. Some functions in the code will not behave correctly if you simply change the crystal without changing the code as well since the libraries expect 16 MHz. You can correct some of these by changing constants in the code to match your crystal before you compile and upload it.

Best Wishes

SO, to be more specific, delay, millis, micros achieve their delay limes by implementing 'busy' waits which are calculated based upon a macro called F_CPU. Change the crystal without changing F_CPU and your delays do not wait the advertised time. Take a look at the implementation in \hardware\tools\avr\avr\include\util\delay.h and elsewhere in the libraries.

It would change all the timings, in direct proportion.

Are you sure you witnessed it? My dad told me that a microcontroller can actually tune itself to its crystal, therefore being able to tell how fast its clock is and not have to be programmed for a certain clock speed.

I am working on embedded microcontrollers all the time - I have a desk of projects right now.

There are clever techniques you can use called "autobauding", where the first character you send it, if the processor knows what it is, it can work out the baud rate of the sender and set itself to that. If you always arrange to send at the same baudrate, then yes, if there is code present, it can deduce its clock speed from that.

Get your dad to ask himself HOW this magic would work.