Terms of service
Brokking
 
 
.net
Let's keep it simple
 

 
   Home
   Projects
 

   Articles
 

   Donation
         
 
 
 
 

 
Brokking.net - Video: The 20MHz Arduino Uno and bootloader tutorial.

The 20MHz Arduino Uno and bootloader tutorial.

This page contains the full script that I used for making this video.

Hello and welcome to another one of my videos. In this video I will explain how to build a 20MHz Arduino Uno. I will also explain the process of building a 20MHz bootloader and how to upload this bootloader to the 20MHz Arduino Uno.

And for those who missed it, the ATmega328P is not the same anymore since the beginning of 2016. I will explain this later in this video.

Yes, the microcontroller on the Arduino Uno, the ATMega328P, can safely run at 20MHz as you can see here in the datasheet. Just to get a little more processing power for your projects.

For this tutorial you need an Arduino Uno or clone, an Arduino Uno as ISP programmer, a 20MHz crystal and two 22pico farad ceramic capacitors.

You can't use any 20MHz crystal that you can get your hands on. Make sure that the crystal has a load capacitance of 18pF to get it to run reliable with the 22pF capacitors. The load capacitance can be found in the datasheet of the crystal.

Detailed information and calculations about the load capacitance can be found in the AVR042 application note. I'll put a link to this document in the description.

First thing to do is to remove the 16MHz resonator and the 1 meg-ohm resistor on the board.

After that there are tree pads available. The center pad is connected to ground. The outer pads are the connection for the crystal. Connect the crystal an capacitors like I have done here. A schematic can be found in the datasheet of the ATmega328P.

Next thing to do is to build a 20MHz bootloader. And this is where it's getting interesting. The latest version of the Arduino IDE when I made this video does not contain the tools that we need.

To get the right tools it's necessary to download the Arduino IDE version 1.0.6. For convenience just use the "Windows ZIP file for non admin install".

Unpack the downloaded folder and find this Makefile. Open it with notepad or in my case notepad++.

Copy the atmega328 lines and make the changes that I'm showing here (20MHz add).

Change the baud rate to 76.8kilo baud and change the AVR frequency to 20MHz.

Finally change the names of the hex and lst files and save the Makefile.

If you have trouble saving the file make sure that the file is not write protected.

Open the command line window and navigate to the optiboot directory where omake is located.

Now type omake atmega328_20MHz

After a successful make you are rewarded with two new files in the optiboot directory.

The only thing left to do is to modify the boards.txt file that can be found here.

Copy the Arduino Uno board info and change uno to uno_20MHz.

Change the name and the upload speed as I'm showing here.

And now it's getting really interesting. We need to set the correct fuse bits. This because the 16MHz resonator is replaced with a 20MHz crystal.

By default the ATmega328P of the Arduino is set to a low power crystal oscillator. As you can see in the data sheet the advised frequency range is up to 16MHz.

To get the 20MHz crystal to work reliable it's necessary to change it to the Full Swing Crystal Oscillator. This will extend the frequency range up to 20MHz.

Remember that I said that the ATmega328P isn't the same anymore sins the beginning of 2016? This is because Atmel removed the full swing oscillator as you can read in the datasheet.

So make sure that you have an ATmega328P from 2015 of earlier. You can check the date by the laser engraving on the package.

This ATmega328P was manufactured in 2014 week 49. And this one in 2013 week 44 and this last example is from 2015 week 17.

Ok, back to the full swing oscillator. In the datasheet of the ATmega328P we can find detailed information about the settings. If you are really interested you can have a look at it.

For now I will be using this fuse bit calculator. I'll put a link to this site in the description.

To get a better understanding of what is going on I will set the original 16MHz Arduino Uno fuse bits first.

Low fuse is set to FF in hexadecimal form.

The high fuse is set to DE in hexadecimal form

And finally the extended fuse bits are set to 05 in hexadecimal form.

The funny thing with fuse bits is the notation. Unused or not selected represents a 1. When a function is selected it represents a 0.

As you can see all the low bit fuses are unchecked. The fuse however is programmed to FF in hexadecimal form. Meaning all ones in binary form.

Here we can select the full swing oscillator with the longest startup time to get reliable results.

As you can see the clock select 3 fuse is now set. This changes the low fuse bit to F7 in hexadecimal form instead of FF.

The rest of the fuse bits can be left untouched.

In the boards file we can now set the correct fuse bits.

To use the correct bootloader it's necessary to change the name of the bootloader. It has to be the same name of the new bootloader file that was made earlier.

And finally we need to set the correct clock speed and save the board file.

So far so good. It's time to upload the bootloader to the ATmega328P.

For this we need the Arduino as an ISP programmer. The process on how to build an ISP programmer is explained in detail on this page. I'll put a link to this page in the description.

https://www.arduino.cc/en/Tutorial/ArduinoISP

This is my Arduino as ISP programmer. It's exactly the same as described on the Arduino website. The only difference is the enclosure and the ISP connector. And I used another Arduino as ISP programmer to program this Arduino as ISP programmer. This way I cannot accidentally overwrite the program in this programmer.

So restart or start the Arduino IDE version 1.0.6 and connect the ISP programmer to the computer. Click tools, board and select the 20MHz Arduino. Select the right com port of the ISP programmer and select the programmer, Arduino as ISP.

Click burn bootloader.

And that's it.

The 20MHz Arduino with bootloader is now ready and it is time to upload the first program.

Go to examples > basic and select the blink program. Connect the 20MHz Arduino to your computer. Select the 20MHz Arduino Uno, select the correct com port and upload the blink sketch.

The LED on the Arduino Uno should now start to blink. This is just an example because the timing of the delay function is not working correct.

To get this to work with the Arduino IDE version 1.6.11 you need to copy the 20MHz bootloader to the optiboot directory and change the board.txt file to this.

At this point, you might wonder why the Arduino Uno boards run on 16MHz instead of 20MHz. One of the reasons is that most timing functions only work correct at 8 or 16MHz.

So what is working and what isn't? Basically, everything in the datasheet will work. For example I2C, SPI, pulse width modulation, serial communication, EEPROM read / write, analog read, interrupts, etc will all work fine. As long as the 20MHz clock frequency is taken into account.

What will not work correct are pieces of code that rely on the 16MHz clock pulse. For example the Arduino delay, millis and micros functions. delayMicroseconds however works fine.

Because there are so many libraries and code examples available, my advice is just to try it and to check if the code runs on 20MHz.

And is it really running faster?

Let's perform a simple speed test with this program. As you can see it performs 500 float calculations. Before the calculations output 13 is set high. After the calculations the output is set low. As already explained in another video the time for setting the output is 125 nano seconds.

With the 16MHz Arduino the total time to finish the 500 float calculations is 4.687milliseconds. The 20MHz Arduino completes the 500 float calculations in only 3.75milliseconds.

This is indeed a 25% increase in speed.

And that wraps it up for this video. Thank you for watching and leave your thoughts in the comments below.