I would like to use a 20 MHz Xtal on my ATmega328p in standalone mode (taking advantage of the microcontroller IC in a circuit that I am developing) in order to increase its processing power and work with faster PWM frequencies. After doing a research on the subject, I was not able to understand the following questions:
1- I know that the use of a 20 MHz Xtal results in an error/inaccuracy in the millis() and micro() functions (among others), but this error is a fixed ratio? For example, if the micro() function with a Xtal of 20 MHz returns 125, is that equivalent to 100 us in a 16 MHz oscillator? If the error is not a fixed ratio, is there a mathematical or logical formula for knowing the real time interval?
2- I found in internet some instructions that shows how to increase the clock of the arduino (considering the complete development board). In order to do that, it is necessary to update the bootloader. However, in the case of a standalone application, is it also necessary to update the bootloader or do some extra procedure?
If anyone could help me in any way, I would be very grateful. Thanks!
micros() and delay() may by off by 4/64ths - 64 gets divided by the clock cycles per microsecond - using integer math - in micros(), and delay is based on micros(). Using floating point math is far too slow, so that's not an option.
I'm pretty sure millis() works correctly in cases like this; it uses a different method to calculate it, since it doesn't need sub-millisecond accuracy (the ISR updates the millis count)
In my attinycore I use conditionals and hand-tuned combinations of bitshift and addition/subtraction to make micros() more accurate without making it so slow that it's not useful - but minicore uses the official arduino core, which doesn't do that.