3

So I just noticed that my Chinese Arduino Uno has a 12 MHz crystal instead of the original 16Mhz.

I made calculations and that turned out to be a quarter millisecond's difference.

My questions:

  1. Does this affect servos or tone(), or any other time sensitive hardware/library?
  2. Can I notify by code that "clock speed is 12,000"?
dda
  • 6,030
  • 2
  • 25
  • 34
Wadaane
  • 326
  • 2
  • 15

2 Answers2

3

The reduced clock speed will affect anything that uses a timer, unless that code can be altered to accommodate the slower clock. Delays, millis(), explicitly coded timer interrupts, etc. And one must remember that you'll get fewer overall instructions per second, so a fast interrupt that barely "fits" at 16MHz might not "fit" at all in the clock cycles available at 12MHz.

Hobby-level servos in particular are sensitive to timing...they depend on a pulse in the 0.5-2.0 millisecond range every 20 milliseconds or so. So if your project includes servos as so many hobby projects do, you'll want to be especially cognizant of timings.

In gcc-c programming the #define F_CPU = 12000000 directive would alert the compiler/preprocessor to compute delays with the 12 MHz clock in mind. Your toolset may vary.

TomServo
  • 7,248
  • 5
  • 30
  • 47
  • Thanx for the clarification, one more thing: if I set #define F_CPU = 12000000, won't that solve the delay issue with the servo ?! Since the pwm will be accurate – Wadaane Jun 17 '17 at 19:38
  • 1
    I believe it likely will. But would exercise caution when connecting servos and test for proper range and travel if possible. – TomServo Jun 17 '17 at 19:59
  • 1
    I already did that, also my solution was to not use servo.write(), but use servo.writeMicroseconds() – Wadaane Jun 17 '17 at 20:04
  • I testing now arduino mega from aliexpress which have 12MHz clock. Blink example, with 10 sec delay, delays exactly 10 secs. Via delay() and delayMicroseconds() – Matveev Dmitriy Nov 01 '18 at 13:17
2

The 12mhz crystal is NOT the Arduino clock source, it is used for the USB chip (CH340) on these clone boards. The Arduino is clocked as usual at 16mhz by a tiny resonator (probably between C5 and C6). You don't need to make any adjustments.

halfnuts
  • 51
  • 3
  • 1
    This is the right answer! I use mostly Chinese Arduino clones, and all the boards that I've seen, from quite a few manufacturers, have a 16 MHz crystal on pins 9 and 10 of the 328p, but often a 12,000 MHz crystal for the CH340G where the normal 16,000 MHz crystal would go. – dotancohen Nov 01 '19 at 15:06