Overclocking Arduino... in 2018

Hello fellow microcontroller utilizers, I've been looking for resources on how to increase the frequency of my Arduino for a while, but sadly many of the websites, and entries on this very forum, are either very old or gone entirely (the name of this post stems from my last desperate Google-Fu attempt :wink: ).

So, I would like to run my microcontroller at higher frequencies. If you are interested in why, I need to detect a change so sudden, that I can just barely reliably detect it at my current, standard, 16MHz frequency.
So of course, when your system doesn't have enough horsepower, you give it more horsepower!

It would be great to get it to run at 32Mhz, just to have it easier with serial com and all that, but it would be fine to listen to the datasheet and not go over 20. I don't really care about timing/temperature, or anything that I've seen mentioned as a problem anyway.

So it would be great if someone could share some guide/insight into this. Or even better, make this thread a guide for the future!

About my current doubts:
-If I get a 20/32 MHz Crystal, can I just solder it in place of the other one, and be finished with hardware?
-Do I just need to change the boards.txt definition to get it all to work? I've made the mistake to read many old posts and now I'm really unsure of what to do.
-Right now I'm working with an UNO, but I might have to go with a Mega 2560. Would anything change?

Thanks again my commutating comerades for the help. I hope this will be of help to other makers as well!

Best option might be to get a faster board like a Due.

If I get a 20/32 MHz Crystal, can I just solder it in place of the other one, and be finished with hardware?

Yes… Up to the point where the processor stops working, or stops working reliably/properly. Exceed the chip’s specs at your own risk… (The Arduino, at least the Uno, uses a resonator, so you might have to add a couple of capacitors and remove the resistor if you use a crystal… Check the ATmega datasheet.)

The Blink Example runs a 2-second cycle (on for 1 second,off for 1 second). If you load the Blink Example into flash and then replace the resonator with a half-speed one, it will run a 4-second cycle. (Slowing it down will work… Overclocking might not…) And of course your code is now “wrong” because it says there’s a 1000mS delay.

I don’t know how to do it, but if the firmware doesn’t “know” what the clock rate is all of your timing & serial communications will be messed-up. And of course that includes the bootloader, so you’d have to modify the bootloader (if you wanted to use it after changing the clock). And, you’d have to modify the IDE to make timers & baud rates correct.

IMO - If you start modifying/customizing the IDE & bootloader you are throwing-away the main advantages of using an Arduino.

ondsinet:
About my current doubts:
-If I get a 20/32 MHz Crystal, can I just solder it in place of the other one, and be finished with hardware?

Sure, if your prepared to accept that it might not work at all, or worse that whilst it might work initially its OK for it to fail shortly afterwards.

srnet:
Sure, if your prepared to accept that it might not work at all, or worse that whilst it might work initially its OK for it to fail shortly afterwards.

For the kind of use I will be making, It should be fine as long as it doesn't initiate a termonuclear conflict.

The best reference I could find was this, but it's kinda old and I wanted to know if there has been some change in the IDE or in the definitions

Also problems might arise by consantly pushing the chip to it's limit. For what I need, it would be enough to keep the frequency high for a very short period (6-12 measures 5microseconds each) and using a prescaler all the other times. What I would like is some guide or practical how-to, since I've mostly found out what there is to do, but not how to do it.

Here's a good hardware package with hardware definitions and bootloader compiled for 20 MHz that supports your Uno's ATmega328P:

After installing it you can select Tools > Board ATmega328, Tools > Variant > 328P / 328PA, Tools > Clock > 20 MHz external, then do a Tools > Burn Bootloader to install the 20 MHz bootloader. After that remember to always use your Uno with those settings selected, rather than Tools > Board > Arduino/Genuino Uno.

If you are interested in why, I need to detect a change so sudden, that I can just barely reliably detect it at my current, standard, 16MHz frequency.

Have you looked at input capture mode?

What exactly is the signal you need to register that increasing frequency by 25% (from 16 to 20MHz) makes it work? Maybe some better code and/or external hardware will do the trick?

aarg:
Have you looked at input capture mode?

Not really, just gave it a quick look right now. I'm not sure if I can try it now. Do you know if it's just some regular C code, of if it uses black magic to detect stuff that lasts less than the time arduino takes to assign a variable? That's the hairy stuff I'm working with.

No, it doesn't use black magic, just simple repeatable code.

ondsinet:
Not really, just gave it a quick look right now. I’m not sure if I can try it now. Do you know if it’s just some regular C code, of if it uses black magic to detect stuff that lasts less than the time arduino takes to assign a variable? That’s the hairy stuff I’m working with.

No it’s a processor hardware feature that captures the value of a free running timer, in a register, when an input pin changes. Thus you can log an event at far greater accuracy than is possible with any software technique.

Maybe you should have a close look at the processor data sheet and see what relevant things it can do to improve your situation.

AWOL:
No, it doesn't use black magic, just simple repeatable code.

Then it might be too slow.

I took some inspiration by the code in this example. Changing the ugly looking series of identical IFs to a loop, renders the thing unusable (Took me some time to understand why some years ago).

Then it might be too slow.

?

Why don't you quit hand-waving, and hang some numbers on this?

DVDdoug:
IMO - If you start modifying/customizing the IDE & bootloader you are throwing-away the main advantages of using an Arduino.

IMO, once you start modifying the IDE and bootloader you start actually learning how stuff works.

ondsinet:
Not really, just gave it a quick look right now. I'm not sure if I can try it now. Do you know if it's just some regular C code, of if it uses black magic to detect stuff that lasts less than the time arduino takes to assign a variable? That's the hairy stuff I'm working with.

Input capture is not black magic. Perhaps you could be a little less coy about what you're dealing with. How often do you need to detect the signal? What is the pulse length of the trigger signal? Which parameter of the signal are you interested in measuring? Maybe the ICP can help you, maybe it can't.

Hardware always works faster than software.

aarg:
No it's a processor hardware feature that captures the value of a free running timer, in a register, when an input pin changes. Thus you can log an event at far greater accuracy than is possible with any software technique.

AH thanks then, that's what I meant, although probably not in a very clear way (sorry to AWOL too).

It's deep magic then (I just meant that in 5 years of arduinoing I never heard of it).

aarg:
it's a processor hardware feature.

I will certantly look into it then, many thanks again.

AWOL:
?

Why don't you quit hand-waving, and hang some numbers on this?

I would like to have those too, but everytime I try to add any sort of variable assignment, the Whole process just doesn't work. The code is very similar to the one in the page I sent earlier.

I only know that the signal lasts between 1 to 6

 if (*pin & bitmask) { cycles =  0;}

instructions.

also source
https://playground.arduino.cc/Code/CapacitiveSensor

You have exceeded the number of posts you can make in a 5 minutes period. Please try again later. I'm sorry that i won't be able to respond for a while. All the last posts have been very useful !

...and what aspects of this pulse are you trying to measure? The leading edge? Pulse width? Number of pulses?

aarg:
...and what aspects of this pulse are you trying to measure? The leading edge? Pulse width? Number of pulses?

It's similar to the link I've sent. It measures the time it takes for a pin to change state, which is influenced by the capacitance of your body. In my case I'm measuring other effects, that result in smaller values of capacity (in the nanofarads). I can measure those with the current code, but at a too small resolution (it takes 1 or 2 statements). Increasing the controller speed would probably be the easiest solution. I shall try both ways as soon as possible

ondsinet:
(I just meant that in 5 years of arduinoing I never heard of it).

5 years in? Go read the datasheet. That chip can do a LOT more than you will have seen just cutting and pasting code. It's a dry read, but if you're going to get into stuff like this you really can't do without it.

ondsinet:
I would like to have those too, but everytime I try to add any sort of variable assignment, the Whole process just doesn't work. The code is very similar to the one in the page I sent earlier.

I don't think he meant in the code. I think he meant to do some math and tell us how quick you need to measure.

ondsinet:
Increasing the controller speed would probably be the easiest solution.

Almost certainly not then. You're only going to get a small gain out before the chip just stops working. The timer on the 328 can get you 62.5nS resolution in input capture mode. Do you need it faster than that?