Arduino - ATmega328 - 12Mhz 3.3v

I am looking to start a project with a Arduino ATmega328 runing at 12Mhz 3.3v.

Is there a bootloader and does the Arduino platform support 12Mhz?

Thanks

Not sure about a bootloader but 12MHz at 3.3v is just about at or alittle below the rated voltage for the frequency. It may not may not work stably.

I have just looked at the datasheet, from the graph for the ATmega328p, 3.3V looks ok up to 13Mhz maybe 14Mhz?

Is there a bootloader

No. You'll have to build one or beg someone to build one for you.

and does the Arduino platform support 12Mhz?

Sort of.

Will you be able to build and upload sketches? Yes.

Will all the functions work the same? No. An example that pops to mind: millis / delay will not be accurate.

Thanks

What is the purpose of atmega328.build.f_cpu=16000000L for example in boards.txt ?

MarkEdwards: What is the purpose of atmega328.build.f_cpu=16000000L for example in boards.txt ?

The end result is that a macro named F_CPU is set to that value. The Libc and Arduino libraries use that macro to generate code correct for the processor speed. In your case, the value is "12000000L".

[quote author=Coding Badly link=topic=94670.msg712453#msg712453 date=1330805880]

MarkEdwards: What is the purpose of atmega328.build.f_cpu=16000000L for example in boards.txt ?

The end result is that a macro named F_CPU is set to that value. The Libc and Arduino libraries use that macro to generate code correct for the processor speed. In your case, the value is "12000000L".

[/quote]Remember, not all routines will work properly. Such as delayMicroseconds() which will need code changes.

I have been looking through some of the code, for example in SoftwareSerial.cpp where

if F_CPU == 16000000

static const DELAY_TABLE PROGMEM table[] = ...

and

elif F_CPU == 8000000

static const DELAY_TABLE table[] PROGMEM = ...

is used. Is it just a case of adding an

elif F_CPU == 12000000

option or are there binaries to worry about?

delay.h seems to deal with the clock speed automatically (from my limited experience)

has anybody else looked at this?

thanks

MarkEdwards: ...in SoftwareSerial.cpp where ... is used. Is it just a case of adding an

elif F_CPU == 12000000

Yes. And, obviously, the timing table.

option or are there binaries to worry about?

No.

delay.h seems to deal with the clock speed automatically (from my limited experience) has anybody else looked at this?

Yes. The functions in delay.h do a reasonable job of accurately delaying. The drawback is that the delay code is always inline. If the program has a large number of delays a single general purpose function will reduce the code size.

Bear in mind that the delay.h functions only work correctly when passed a constant.

[quote author=Coding Badly link=topic=94670.msg715100#msg715100 date=1330974787]

Bear in mind that the delay.h functions only work correctly when passed a constant.

[/quote] Otherwise, they pull in the floating point library which is very large. One easy meathod to implement milisecond delay is something like this:

void delay(int amount){
    while(amount--){
        _delay_ms(1);
    }
}

Works fairly well since loops are usually reasonably fast as far as milliseconds go.

Otherwise, they pull in the floating point library which is very large.

While that is certainly a problem it's actually the least significant problem. ;)

Looking at delay.h (arduino 1.0) , delay_us and delay_ms seems to use F_CPU to generate the correct timings.

So why would atmega328.build.f_cpu=12000000L generate incorrect timings?

Pass a variable instead of a constant.

Sorry, I mean

as delay.h (arduino 1.0) generates what seems (from the code) to be the correct timings for the delay_us and delay_ms why would timing such as in delayMicroseconds() still be and issue? Hardware configuration excluded

https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/wiring.c#L120

delayMicroseconds is coded to accurately handle three cases: 20 MHz, 16 MHz, and 8 MHz. All other cases are going to be inaccurate. For a clock frequency of 12 MHz, the 8 MHz case is used resulting in a delay 8/12 of what is expected.

The wiring.c that I downloaded seemed to be an older version, with no 20Mhz chages.

Just re-downloaded from github and things are now looking a little more clear.

Thanks!!