Arduino crystal replacement

Hello :slight_smile:

So I've got this idea (for fun) to replace the 16MHz Crystal with a 64MHz Crystal (with the ATmega328) I have laying around, so i did some research and found a tutorial to replace it with a 32MHz Crystal and they had to replace the 22pF capacitors with diffrent one's, so my question is how can I find out what kind of capacitors i need? And I know that the ATmega328 possibly die

I've drawn a basis schematic (See attachment)

Thank you :slight_smile:

"If the crystal frequency exceeds the specification of the device (depends on VCC), the CKDIV8 Fuse can be
programmed in order to divide the internal frequency by 8. It must be ensured that the resulting divided clock
meets the frequency specification of the device."

I don't know about "die" as you said, not sure how well it operate at >3X max clock speed.
Crystal caps - don't know. You're the test pilot on that one.

The maximum operating frequency of the ATmega328P is 20MHz.

Thanks for your reply's :smiley:

So first of all I know the maximum operating frequency of the ATmega328P is 20MHz but some people on Youtube naild it? And i've got a few ATmega328P laying around so why not give it a try?

"If the crystal frequency exceeds the specification of the device (depends on VCC), the CKDIV8 Fuse can be
programmed in order to divide the internal frequency by 8. It must be ensured that the resulting divided clock
meets the frequency specification of the device."

I will do some research on programming the CKDIV8 Fuse (I think It's gonna take a while) What would happen If I wouldn't change the Fuse and just power it on? Or will it just not boot?

Thank you anyway for your help :slight_smile:

Try it. The chip will certainly run hotter, as temperature is directly related to switching speed.
As far as stuff working reliably, who knows. One member here reports working at 32 MHz, I don't think I've seen any reports of much functionality of the chip has been checked out. I'm sure changes were made to support the baud rates so serial comm's could be understood - or he just halved the speeds so 9600 in code looked like 19200 to the outside world for example.

The clock divide by 8 - that just needs the upper bit of the Low fuse byte flipped, see Table 28-9 in the '328P datasheet.
Change that in boards.txt for the board type you are using:

So if you were to copy/update this section as a new board type for example, from uno to uno64:

##############################################################

uno64.name=Arduino Uno with 64MHz crystal
uno64.upload.protocol=arduino
uno64.upload.maximum_size=32256
uno64.upload.speed=115200
uno64.bootloader.low_fuses=0x7f
uno64.bootloader.high_fuses=0xde
uno64.bootloader.extended_fuses=0x05
uno64.bootloader.path=optiboot
uno64.bootloader.file=optiboot_atmega328.hex
uno64.bootloader.unlock_bits=0x3F
uno64.bootloader.lock_bits=0x0F
uno64.build.mcu=atmega328p
uno64.build.f_cpu=8000000L
uno64.build.core=arduino
uno64.build.variant=standard

changing low fuse to 7f enables divide by 8
64/8 = 8,
uno64.bootloader.low_fuses=0x7f

but system clock is then 8 MHz so this has to change from 16MHz to 8 MHz too?
uno64.build.f_cpu=8000000L

May take some experimenting with your setup.

You aren't limited to a prescaler of divide by 8 or 1. That's only true for when you first reset the processor. That's determined by that fuse. But once you're up and running you can change the prescaler to divide by 2, 4, 8, 16,... 256 by writing to a register.

So you could use the divide by 8 fuse to be safe and start at 8MHz. And then in your sketch change the prescaler to divide by 4 so you'd have a 16MHz clock.

I'm not sure what that means for how you set up your board though. I think the bootloader would need to run at 8MHz but you'd want 16MHz for the core. I don't know.

So first off all I'm currently on vacation (Using my laptop) In 5 days I'll be back but I thought I found this code for calculating Pi

int ledPin =  13;


void setup(){
  Serial.begin(9600);           
  
  Serial.println("integrating sinc to get pi");
}


void loop(){
  double a = -5000000;
  double b = 5000000;
  
  
   for(double N = 1; N <=100000000; N*=2){
      Serial.print("N:");
                float temp = N;
                Serial.print(N);
      Serial.print("  integration: ");

              digitalWrite(ledPin, HIGH);
              double intVar = integrate(a,b,N);
              digitalWrite(ledPin, LOW); 
        
              Serial.println(intVar,7);
                 
                delay(1000);
   }
  
  
  
  
}

double f(double x){
  if(x == 0)//lim(sin(x)/x,x,0) = 1
    return 1;

  return (sin(x)/x);
}
double integrate(double a,double b,double N){
     double dx = (b - a) / N;//delta x, not instantaneous
    double sum = 0;

    for(double iter = 1; iter < N; iter++){
        double x = a + iter*dx;
             sum += f(x);
    }
     return sum*dx;
}

And I was wondering what would happen if I didn't change the fuse at all and just add an 64MHz crystal and see what time it takes to get to

 N:65536.00  integration: 154.1663513

And than take a look how long it takes with a normal arduino, and then see how long it takes than with an Arduino with a 64MHz Crystal and fuse (That i already added to the board.txt )

Btw I found an website that could help if your interested: http://garagelab.com/profiles/blogs/atmega328-overclock-30mhz

So as soon as the testing is done I'll post it here :slight_smile:

If you have any tips feel free to leave them behind :smiley:

##############################################################

uno64.name=Arduino Uno with 64MHz crystal
uno64.upload.protocol=arduino
uno64.upload.maximum_size=32256
uno64.upload.speed=115200
uno64.bootloader.low_fuses=0x7f
uno64.bootloader.high_fuses=0xde
uno64.bootloader.extended_fuses=0x05
uno64.bootloader.path=optiboot
uno64.bootloader.file=optiboot_atmega328.hex
uno64.bootloader.unlock_bits=0x3F
uno64.bootloader.lock_bits=0x0F
uno64.build.mcu=atmega328p
uno64.build.f_cpu=8000000L
uno64.build.core=arduino
uno64.build.variant=standard

That site uses an oscillator, not a crystal and caps.
64MHz examples:

32MHz examples:

That is an extremely ambitious target...

You need an external clock generator (and external clock source selected) for best results overclocking, crystal+caps doesn't work as well.

That site uses an oscillator, not a crystal and caps.

Thank you I will take a look at oscillator

That is an extremely ambitious target...

You need an external clock generator (and external clock source selected) for best results overclocking, crystal+caps doesn't work as well.

I know but I don't need the best overclocking I'm just a random dude and I won't use it for real designs.
Thanks anyway! :slight_smile:

I have run many AVRs on 32Mhz using TTL oscillator (these are really cheap on ebay for SM device)
No problems to report on ATTinys, ATMega328's (even cheap chinese clones) and ATMega1284..
No heat issues, in fact no noticable heat increase
Timers, UARTS, SPI - all working fine even with sensitive timings for PAL TV and UART of 250kbps

And I havent killed one yet

Just remember your fuses settings - if you mess up you could end up with a bricked micro !

Is there a guarantee that the prescaler will operate at 64Mhz?

If you overclock you'll lose the high end of the temperature range first, generally CMOS clocks
faster cool and at higher voltages. Also unless you exercise all the different instructions and
functional blocks on the chip you don't really know when it starts failing

(resistance increases with temperature, capacitance is invariant and on-resistance
drops rapidly with gate voltage - hence the temperature and voltage dependences.
Power consumption depends on frequency and voltage-squared.

And I was wondering what would happen if I didn't change the fuse at all and just add an 64MHz crystal and see what time it takes to get to

What a futile endeavor.
What will happen is absolutely nothing.

aarg:
Is there a guarantee that the prescaler will operate at 64Mhz?

Not from Atmel.

But he says it's just "for fun". So what the heck, give it a shot.

I wonder what happens if I dunk my Uno in water? :slight_smile:

The oscillator in an Arduino is a pierce oscillator which is a parallel mode oscillator, and operates with crystals in their fundamental mode.
Crystals which are labelled as 64 Mhz are overtone crystals and will only run at their marked frequency in a oscillator circuit which is designed for such crystals.
Such an oscillator must have a loop gain greater than 1 at the marked frequency, but less than 1 at the fundamental mode frequency.
If you run an overtone crystal in a fundamental mode oscillator, then the crystal wont run at its marked frequency, but will run at a lower frequency which is usually approx a 3rd or a 5th of the marked frequency.