arduino mini pro 16 MHz to 20 MHz

Hi everybody.

I m working on a project that requires to be as fast as possible getting analog input.

So i wonder how to change the clock from a 16Mhz card to 20 MHz .

Indeed the atmega328p is a 20MHz chip.

Do you know a way to do that?

Thx

Fazz

Since you said your Arduino Mini Pro is running at 16MHz, I am assuming that it is one that runs off 5V instead of 3.3V. If that is the case, you can just replace the on board crystal with a 20MHz one.

I assume that what you do does not depend on timing (i.e. delay() ,etc.), and if this is the case, you should be able to run your program at the faster clock speed with no coding change. But if you are using timing functions, you will need to take into consideration that 25% clock speed increase as most of the Arduino timing functions assumed a 16MHz clock rate.

But wouldn't also the bootloader have to be recompiled and burned into the chip to keep the baud rate correct for the IDE?

Lefty

Good point retrolefty... I didn't think of that.

I m working on a project that requires to be as fast as possible getting analog input

Use of the onchip Analog Digital Converter (ADC) is a tradeoff between speed and accuracy. The Arduino core configures the ADC clock to run at 125kHz (for 16MHz boards) and one analog sample requires 13 ADC cycles to complete. Atmel recomends an ADC frequency in the range from 50kHz to 200kHz. So within that range you can double the ADC speed without changing the mcu clock frequency.

The crystal on a pro mini board is pretty tiny so replacing it may not be trivial. Also the anlaog converter speed gain is close to insiginificant compared to just changing the ADC frequency in your sketch. There is no support for changing ADC frequency in the Arduino core however so you will need to resort to low level coding.

Ben - could you elaborate on how to change ADC frequency? Do you just mean directly reading the ports that the ADC sets?

Is there info on this anywhere?

Initialization of the input clock to ADC is handled by the Arduino core just before your sketch setup function gets called. So this is a one off operation and you could therefore change it (again) in your setup function and expect it to remain effective for as long as your sketch runs.

Specifically you need to select another value for the ADCSRA prescaler bits. The Arduino default setting is dividing by 64 with a resulting 125 kHz ADC sampling frequency. You could change this to divide by 32 for a 250 kHz sampling frequency.

You may want to note however that tuning sampling frequency is primarily to allow designers choose an optimal ADC clock irrespective of the system clock (as is the case for the Arduino). For some applications however "optimal" may translate to faster and then changing it for higher speed is one way to go.