Arduino UNO @ 20MHz

The bootloader is called (usually) when the chip resets. If it finds incoming suitable data it uses that to reprogram the lower part of the flash memory (not itself, of course). Once done, or if it finds nothing, it jumps to address 0 to start the "real" sketch. Thus the bootloader is only important for changing the existing sketch, and you don't even need it for that if you use ICSP programming instead (via the 6-pin SPI header).

I have found the boards.txt file that came with the IDE, and could cut and paste the fasteruno code you posted into it, but I am not sure that is what you are suggesting that I try, especially regarding your following "compiling errors" comment.

You could copy and pasting my suggestion to the end of that file, and restart the IDE. Then choose "Arduino Uno at 20 MHz" from the Boards menu. If that doesn't work, oh well, don't choose it again. It might.

I hope your end application is worth all this pain. You are going to quite a bit of effort for only a 25% speed increase. With most applications the chip is sitting around waiting for input, the raw chip speed isn't all that important.

I've been following this thread with some interest.
I have built several of my Arduinos and have never used a bootloader (only ICSP) so the higher clock speed won't be a factor, however I'm confused about timings relating to other functions.
Is it necessary to compensate in the code for example, delay(1000*20/16) for a 1 sec delay, or will a simple edit of the boards.txt file be sufficient?

WhatEver.upload.speed=144000
        :
        :
WhatEver.build.f_cpu=20000000L

Is the baudrate edit also required?

True, for most applications it wouldn't be of much use but when generating video (especially VGA it will be very handy.

Well I tried just that for my VGA output and got a bit frustrated with it.

However, re-testing with my suggested setup seems to work (however not on a Mac).

On the Mac, it didn't seem to like that baud rate for the sketch upload:

Binary sketch size: 2,594 bytes (of a 32,256 byte maximum)
avrdude: ser_setspeed(): tcsetattr() failed
avrdude: ser_open(): can't set attributes for device "/dev/cu.usbserial-FTFAYL28": Invalid argument
ioctl("TIOCMGET"): Bad file descriptor
avrdude: ser_close(): can't reset attributes for device: Bad file descriptor

On Windows however it did, and I got the ASCII table sketch to work, however not at 115200 baud. At 9600 baud it worked fine.

Here is my setup:

Hi Nick

I see your setup is different to mine, I use a AVRMKII ISP from Atmel but can't test it until I'm back at the office.
As regards your sketch not working at 115200, could it be that at 20MHz there is no division ratio that will generate that baudrate closely enough?
I will try get some other standard crystals at 20.48MHz and 19.8MHZ and test.

Another way is of course writing the sketch for 20MHz, uploading with the 16MHz crystal connected, then switching off and replacing the crystal with the 20MHz one.

CrystalSelector.jpg

UnoDueTre:
As regards your sketch not working at 115200, could it be that at 20MHz there is no division ratio that will generate that baudrate closely enough?

Looks like 230400 is the only bad choice...
http://www.wormfood.net/avrbaudcalc.php

UnoDueTre:
As regards your sketch not working at 115200, could it be that at 20MHz there is no division ratio that will generate that baudrate closely enough?

Quite possibly.

UnoDueTre:
Is it necessary to compensate in the code for example, delay(1000*20/16) for a 1 sec delay, or will a simple edit of the boards.txt file be sufficient?

Neither works perfectly. The millis / micros code is designed to only work correctly at 1, 2, 4, 8, or 16 MHz. millis is fairly easy to correct (I know of two proposed solutions). micros not so much. Serial has the same problems at either clock speed (some baud rates are too far from the target speed).

Is the baudrate edit also required?

The other choice is to rebuild / re-upload the bootloader built for 20 MHz. Either method works.

Reply #40 on: Today at 03:27:49 am
Reply #41 on: Today at 03:28:01 am

Twelve seconds. Close enough. I call jinx! Bwahahaha!

The calculator that Coding Badly linked to states that 115200 @ 20MHz

UBRR and clock speed are between 1% and 2% off

Could that be it?
Doubt it though as those percentages are too low.

OK so judging by the replies here, using a crystal of 20Mhz (or any other then the standard Arduino ones) would require changes to serial functions, millis, micros and possibly others like Tone, delay and maybe even the SPI functions (under rare circumstances).
The bootloader would also need changing.

I think it's more hassle then it worth it, too much messing about and too much stuff that would be non standard.
In a lot of cases any short comings of 16MHz versus 20MHz could possibly be made up by using direct register manipulation and/or the use of inline assembler.

On a side note, I can't be the only one that thinks that the gcc syntax for inline asm is just plain weird, so it would be nice to be able to use say AVR Studio to compile a function in pure asm then taking that binary (not the intel hex) and being able to include it as part of the sketch (similar to the POKE in Basic).
Anyone know if this is possible and how one tells the compiler (avr-gcc) to keep the position of this included binary code without trying to move it to where it thinks it should go and messing it up?
Maybe as part of a function?

The only disadvantage found so far with higher speed is serial communication
see this thread Software Serial delay table - Programming Questions - Arduino Forum

If you need more speed like i do for my DSLR remote control + Star Tracker then i will experiment with this setup.
ATMEGA328 is rate at 20MHz as maximum speed, but at this moment i have 4 who work just fine at 24MHz with the condition that i have to keep the serial speed under 115200.

the things you need to do this are posted here http://www.grozeaion.com/index.php?option=com_content&view=category&layout=blog&id=49&Itemid=110 including how to burn bootloader using one arduino board (no extra programmer needed).

Hi gvi70000

Thanks for the input, will slowly digest all of it.

I remember in the "old" days one could coerce a bit more speed from some of the Phillips 8051 derivatives by using a higher speed xtal and increasing the supply by 0.5V or so.
The current went up but never popped one.
Never tried it on an AVR, maybe one day I'll throw caution to the wind, connect something like a 25MHz (or higher) xtal and see if it works, what the extra current will be and how long it survives.

EDIT:

Just looked at the Mega2560 datasheet and the supply is rated to 5.5V
I wonder if there will be any advantage when running at high speed?

I'm also thinking that perhaps using an external TTL/CMOS level xtal osc may enable the AVR to go even higher.

UnoDueTre:
OK so judging by the replies here, using a crystal of 20Mhz (or any other then the standard Arduino ones) would require changes to serial functions

Your sketch would need to be changed if you use 230400 baud. Otherwise you should be fine. The same sort of problem exists when the processor is running at any clock speed (poison baud rate).

, millis, micros

Yes.

and possibly others like Tone,

No.

delay

No.

and maybe even the SPI functions (under rare circumstances).

The bitrate is specified indirectly by divisor so the only issue is if the final bitrate exceeds the slave device's maximum bitrate.

The bootloader would also need changing.

Only if you can't multiply by 20 then divide by 16. :wink:

...so it would be nice to be able to use say AVR Studio to compile a function in pure asm then taking that binary (not the intel hex) and being able to include it as part of the sketch (similar to the POKE in Basic).

I believe the Arduino IDE uses the assembler for sketch files that end in dot-S (I believe the S must be capital). Just create a new "tab" and end the file name with dot-S.

Edit: minor correction

Thank you for all the info Coding Badly.
I will look at the .S files.

I am thankful that more information on this subject has been presented here, but I can honestly say I still am unclear as to the answer of my previous question......

billcat:
...If I am dead set on using a 20Mhz crystal on a breadboarded Arduino, and not being required to account for this in any way every time I load a sketch...is this even possible?

I can speculate that it was answered by Coding Badly in reply #48, but can not say for sure.
If it is possible, I still do not know what I need to do to do so.

My reasons for wanting to use 20Mhz stem from a desire to build the Gen7 electronics for RepRap: Generation 7 Electronics - RepRap ....which calls for a 20Mhz oscillator....and is also the very reason I got started recently with Arduino......I understand most all parts of the hardware for Gen7, but nothing about the software.
So I have these 20Mhz crystals at my disposal, I'd like to use them if I could, but its obviously not a big deal since they are quite inexpensive.
It would be more realistic to ask myself is Arduino worth all this pain? I would estimate that I have spent at least 30-40 hours a week now for several months reading online tutorials, real books, forum posts, and related information, and still do not really understand the most basic of the Arduino examples, given the information supplied. Almost any application that I can immediately think of having a personal interest in using Arduino for........I can already accomplish using readily available hardware alone.
I am hopeful, yet still very uncertain, that eventually this will change........which is the sole reason I am still hanging on, at least for a little while longer.
anyhow....the rants over......again, thanks to all of you who give your time trying to help.
Cheers,

billcat:
I would estimate that I have spent at least 30-40 hours a week now for several months reading online tutorials, real books, forum posts, and related information, and still do not really understand the most basic of the Arduino examples, given the information supplied.

Learning curves are always very sharp at the beginning. Especially with technology. New terminology alone can be a huge burden. Give your brain time to digest.

billcat:
I am thankful that more information on this subject has been presented here, but I can honestly say I still am unclear as to the answer of my previous question......

billcat:
...If I am dead set on using a 20Mhz crystal on a breadboarded Arduino, and not being required to account for this in any way every time I load a sketch...is this even possible?

delay / micros will not work correctly (the delay time / micros value will have a small error). millis can be made to work with a relatively minor modification. Most everything else should work as you would expect it to work.

The first step is decide how you will be programming the "target" (the processor running at 20 MHz). Do you plan to use a bootloader or ISP (in-circuit serial programming)?

billcat:
I am thankful that more information on this subject has been presented here, but I can honestly say I still am unclear as to the answer of my previous question......

billcat:
...If I am dead set on using a 20Mhz crystal on a breadboarded Arduino, and not being required to account for this in any way every time I load a sketch...is this even possible?

I can speculate that it was answered by Coding Badly in reply #48, but can not say for sure.

Without re-reading all 4 pages, I think I responded earlier it should be possible if you change the boards.txt file, eg. to add:

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

uno20mhz.name=Arduino Uno @ 20 MHz
uno20mhz.upload.protocol=arduino
uno20mhz.upload.maximum_size=32256
uno20mhz.upload.speed=144000
uno20mhz.bootloader.low_fuses=0xff
uno20mhz.bootloader.high_fuses=0xde
uno20mhz.bootloader.extended_fuses=0x05
uno20mhz.bootloader.path=optiboot
uno20mhz.bootloader.file=optiboot_atmega328.hex
uno20mhz.bootloader.unlock_bits=0x3F
uno20mhz.bootloader.lock_bits=0x0F
uno20mhz.build.mcu=atmega328p
uno20mhz.build.f_cpu=20000000L
uno20mhz.build.core=arduino
uno20mhz.build.variant=standard

I have done this myself as part of testing VGA output. In fact I had it running using this method at 20 MHz, 24 MHz and 25 Mhz.

Serial output looks OK (in other words the baud rate is correctly calculated). A timing test shows that delay(500) seems to take a bit longer (533 mS). A test running at 25 MHz also gives a longer delay than expected (640 mS). However this is the inverse of what you would expect, right? A delay would be shorter if the code hadn't compensated. I'm not sure why delay is out in this way but I suspect rounding errors in the calculations for the timer interval.

Caveat: This only works on Windows, the Mac doesn't like the non-standard baud rates. I can't comment on Linux.

So I don't know why we are on page 4 of this thread. It looks like reply #5 described the changes required.

It would be more realistic to ask myself is Arduino worth all this pain?

The Arduino is fine. It is targetted at beginners. However you are not planning to use one, right? You are planning on a breadboarded Atmega328 setup with a non-standard crystal. Of course this is harder than buying an Arduino board and experimenting with it. Having said that, though, I have one working right here blinking an LED for the timing test. I posted a photo of it in reply #38.

How about actually assembling something like that and letting the fun begin? Asking on a forum if something will work, when you can find out for yourself, is surely not as satisfying?

I am grateful for your advice Nick, I am sorry you are frustrated with the length of this thread. I don't intend to bother anyone. I am happy with the effort you have made to help me. If reply #5 was clear to me, then of course I wouldn't continue asking. I am well aware that you are very busy helping many people here, and if you wish to ignore my replies in the future, I would not be offended, you've been more than generous with your time.
And I appreciate your pic on post #38. I examined it very closely. It also left me with questions. You have + / - one or two components in your circuit(resistors and caps, cant remember) than there were in the schematic I followed when I finally got my homemade board going. I bought this: http://www.digikey.com/product-detail/en/UM232R/768-1019-ND/1836397 for the usb connection to the breadboard. I figured it must serve the same purpose as your FTDI cable, but could not tell you the difference between the two. It took a lot of plain ol' guesswork on my part to get it working.

The point being that I have actually "assembled something like that" as you recommend, check the pic.

Thanks for the clarification about the timing issues. I've taken some replies in the thread to indicate that it could be done somehow that would eliminate the timing issues. I do not really understand how to use any of the timing functions right now anyway, except for maybe delay() and delayMicroseconds(). However, I do know that timing is of real concern involving machine motion control, thus my concerns with the 20Mhz crystal used for the 3d printing application.
About the programming the target; I am not sure........if you use an Uno with the ISP sketch on it to load a sketch onto the breadboarded target(or my homemade board), is this considered using ISP or considered using the bootloader? Would this be the situation where you do not have to worry about the altered boards.txt, optiboot, etc files, and where only the timing functions within the sketch need to be adjusted like delay(xxUL* 20/16); ?

Hello all,

In the second half of this page Overclocking ATMega328P i have posted an update for micros and also for software serial,i hope it will help you.