Pages: [1] 2   Go Down
Author Topic: [solved] Changing CPU speed & boards.txt  (Read 4200 times)
0 Members and 1 Guest are viewing this topic.
Bristol, United Kingdom
Offline Offline
Newbie
*
Karma: 0
Posts: 23
ARGH dwee No!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I've asked this before, but never got a definitive answer... I have an ATMega2560-8AU chip that I want to make a standalone circuit from. Its given speed is 8MHz, not the normal 16MHz.

If I make a new board profile in boards.txt based on the current 2560 one, such as;

Code:
##############################################################

mega2560.name=Arduino Mega 2560

mega2560.upload.protocol=stk500v2
mega2560.upload.maximum_size=258048
mega2560.upload.speed=115200

mega2560.bootloader.low_fuses=0xFF
mega2560.bootloader.high_fuses=0xD8
mega2560.bootloader.extended_fuses=0xFD
mega2560.bootloader.path=stk500v2
mega2560.bootloader.file=stk500boot_v2_mega2560.hex
mega2560.bootloader.unlock_bits=0x3F
mega2560.bootloader.lock_bits=0x0F

mega2560.build.mcu=atmega2560
mega2560.build.f_cpu=8000000L
mega2560.build.core=arduino

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

what will this effect? Do I also have to fiddle with the bootloader somehow? The datasheet says that the timer fuse settings won't change (apparently there is one setting for an external xtal at 8-16MHz).

Thanks
Tom
« Last Edit: March 14, 2011, 03:09:54 pm by TND » Logged

Tom

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 206
Posts: 12850
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what will this effect?

Sketches built for that board will run correctly at 8 MHz.

Quote
Do I also have to fiddle with the bootloader somehow?

Possibly.  To upload at 115200 baud, you will need to install a bootloader built to run at 8 MHz.  You may be able to halve the baud rate and leave the existing bootloader.
Logged

Bristol, United Kingdom
Offline Offline
Newbie
*
Karma: 0
Posts: 23
ARGH dwee No!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply.

Quote
Quote
what will this effect?

Sketches built for that board will run correctly at 8 MHz.
Everything will still work? The only info I could find relating to this was from several versions ago, and apparently some things like PWM could stop functioning properly. Have all the functions been made CPU speed-independent now, then? Just want to make sure, as this chip has a range of tasks to do, from servo control to serial comms.

Quote
Quote
Do I also have to fiddle with the bootloader somehow?

Possibly. To upload at 115200 baud, you will need to install a bootloader built to run at 8 MHz.  You may be able to halve the baud rate and leave the existing bootloader.

I thought this might be the case. I suppose that changing the mega2560.upload.speed parameter will change the upload speed, but as for modifying the bootloader I've no idea where to even start. If I want to use the Arduino bootloader, I can just modify that, right? I found the .hex files, but couldn't make head nor tail of them (What with them being a long list of hex numbers...).

Thanks for the help so far...

Tom
Logged

Tom

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The bootloader as hardcoded values, as are the prescallers of the pwm..
With the correct code changes all will work, for the pwm you need to change the prescallers, so they are twice as small as the ones used for 16Mhz, and you could also try to upload at half the baud rate that the bootloader is expecting because he will be indeed running at half the normal baud rate.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 206
Posts: 12850
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
for the pwm you need to change the prescallers

That's a bit strong.  There are lots of people using PWM @ 8 MHz who haven't changed the prescalers.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 206
Posts: 12850
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Everything will still work?

Yes.

Quote
Have all the functions been made CPU speed-independent now, then?

Independent-ish.  The PWM frequency is halved.

Quote
servo control, serial comms

You're good.

Quote
I thought this might be the case. I suppose that changing the mega2560.upload.speed parameter will change the upload speed

Yup.

Quote
but as for modifying the bootloader I've no idea where to even start

Don't.  Try altering the upload speed.  If that doesn't work, then go after the bootloader.

Quote
If I want to use the Arduino bootloader, I can just modify that, right?

The source files and makefiles are in this folder...
{ArduinoRootFolder}\hardware\arduino\bootloaders

Someone else will have to help with the details.
Logged

Bristol, United Kingdom
Offline Offline
Newbie
*
Karma: 0
Posts: 23
ARGH dwee No!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay well to get it to run at 8MHz I wouldn't need to change the prescaler, surely, as 8MHz is still the default 'Full speed' of the chip.

Thanks for all this info though - I fininshed soldering the chips to their breakout boards yesterday, so I should be able to test burn the bootloader some time next week. I'll report back then!

Tom
Logged

Tom

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How can the servos work if the ppm signal is halved?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 206
Posts: 12850
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How can the servos work if the ppm signal is halved?

Are you using PWM to signal Servos?  (you shouldn't)  Or are you asking about the Servo library?
Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I really want precise control I use the timers and hardware pwm.
Logged

Bristol, United Kingdom
Offline Offline
Newbie
*
Karma: 0
Posts: 23
ARGH dwee No!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, I'm in the process of writing the code and getting a PCB made to do the testing. But as we all know, PCBs are cheap, so I only get one test, and even then I can't call it a test. :S

I'm developing the system using a normal Arduino MEGA until then (the old 1280 version), and I think a better approach would be for me to ask - If i change the speed, what difinitely *WON'T* work?

Thanks
Tom
Logged

Tom

Bristol, United Kingdom
Offline Offline
Newbie
*
Karma: 0
Posts: 23
ARGH dwee No!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

An update.

I got my breakouts made, and soldered on the ATMega2560-8AUs.

I added a new board to boards.txt, the burnt the default bootloader using a USBTinyISP from Adafruit.

Something odd then, that maybe someone with an Arduino MEGA 2560 can help me with. With the old MEGA (the 1280), the bootloader put a program like 'blink' onto the chip, such that the 'L' LED would flash periodically. I'd best drescibe it as a 'dash-dash-dash...' sequence, if you think in morse code.

But when I put the bootloader on my reduced-speed 2560s, I get a 'dot-dash-dot-dash...' light sequence. Is this an indication that the bootloader upload didn't go quite right, or does the MEG2560 bootloader just have a different default flash sequence...?

I assumed that it was just a different flash sequence.

Next, I tried to upload my program using an FTDI Friend. I had managed to upload to the Arduino MEGA1280 using this method, but when I tried to do it on my 2560, it would sit at the 'uploading to board' status.

So then I added a new board to boards.txt that would use the USBTinyISP to upload the program. When using that, the program would upload but then there were two new issues;

The serial output is garbage now. I've tried receiving at half the baud I was expecting it to send at (and I even tried double, just to see), but it was always garbage.

Uploading the first program after burning the bootloader was fine, but if I tried to upload again then I'd get an error (something about verification - I forgot to write it down) and the program wouldn't be uplaoded.

...I know it's a lot, but any thoughts?

Tom


Logged

Tom

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 206
Posts: 12850
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can think of two possible problems...

1. Fuse settings are not correct.  Try a one-second blink Sketch.  You will have to use the USBTinyISP  to upload.  Does it appear to blink about once a second?

2. Atmel guarantees that the internal oscillator will be ±10% when a processor leaves the factory.  This can be tuned to ±1%.  Around 4.5% from the target frequency, high-speed serial communication starts to be troublesome.  It is possible the internal oscillator is too far from the target value.  Try a Serial Sketch with a very low baud rate (300).
Logged

Bristol, United Kingdom
Offline Offline
Newbie
*
Karma: 0
Posts: 23
ARGH dwee No!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the quick reply.

I did the blink-check already - it seemed okay at the time, but I will test it more thoroughly and properly tomorrow.

As for your second point, I forgot to mention that I am already using an 8MHz crystal in place of a 16MHz one. This is also why I'm not sure why the fuse settings wouldn't be correct - the datasheet gives one setting for external crsytals in the frequency range 8MHz-16Mhz. And as that's all that's really changed, surely the fuse settings should be the same...

Tom
Logged

Tom

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 206
Posts: 12850
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As for your second point, I forgot to mention that I am already using an 8MHz crystal in place of a 16MHz one. This is also why I'm not sure why the fuse settings wouldn't be correct - the datasheet gives one setting for external crsytals in the frequency range 8MHz-16Mhz. And as that's all that's really changed, surely the fuse settings should be the same...

The settings for 8 MHz external crystal are the same as the settings for 16 MHz external crystal.  The fuse settings in your first post look OK.  Disregard the part in my previous post about the internal oscillator.

Quote
...using the USBTinyISP to upload the program...Uploading the first program after burning the bootloader was fine, but if I tried to upload again then I'd get an error (something about verification - I forgot to write it down) and the program wouldn't be uplaoded.

In my experience, once you switch the fuse settings to an external crystal, if there is a problem with the external crystal, then the processor will not communicate through an ICSP.  Once the crystal issue was resolved everything worked.  Your experience sounds similar to mine but not identical.

Do you have anything connected to the board?
Logged

Pages: [1] 2   Go Up
Jump to: