ATmega328P targeted at low-power battery use: help needed with baby steps!

OK, used the settings from the tutorial (with the core/variant adjustment) in the IDE's boards.txt:

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=stk500
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.path=arduino:atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino
atmega328bb.build.variant=standard

to burn a new bootloader, and that all works fine. I can upload the blink sketch via my FDTI cable, and adjust it and re-upload, just fine.

So my USB and auto-reset and so on is fine by the looks of it.

So I think that nominally, using a baud of 7200 with the 1MHz clock should work. Maybe I have to adjust some of the delays in the ArduinoISP, or get myself a new bootloader .hex file with the F_CPU set for 1MHz and baud set for 9600 at that clock speed? (If the latter, I don't yet know how to do that.)

Rgds

Damon

as I do with the PICAXE for example

Why? If you jut put in a minijack and down load circuit, you can program a PicAxe in circuit.

I don't understand your point, sorry!

That is what I do with my PICAXE, eg here, with jack plugged in:

I would like a load/test of new code to be as easy for the AVR version, even when the chip cannot be removed and has <5V peripherals as on the board above.

Rgds

Damon

Just put this circuit on your board with a mini-jack - though that is optional - and you can program in circuit:

And use the serial monitor for debugging.

I'm really not following.

That is how I use the PICAXE already.

Rgds

Damon

Then why can't you program and debug in circuit? Why do you pull the chip out to reprogram?

I don't.

What I'm trying to achieve with the ATmega is the same ease of reprogramming as I already have with the PICAXE.

Rgds

Damon

Oops, when you mentioned the PicAxe it was an example of what you want to do with the AT chips. Sorry I misunderstood.

Anyone got a precompiled 1MHz-friendly ATmega328P bootloader.hex file?

I've tried a few others without success.

I do fine at 8MHz, and have been working on the low power 'scheduler' core for my code instead, with rather more progress!

Rgds

Damon

DamonHD:
Anyone got a precompiled 1MHz-friendly ATmega328P bootloader.hex file?

Here you go. They're untested I'm afraid, but I'm using Optiboot on other boards at non-standard frequencies and baud-rates with no problems.

atmega328_1a.hex (Optiboot for 9600baud at 1MHz)

:107E0000112484B714BE81FFE6D085E08093810001
:107E100082E08093C00088E18093C10086E0809377
:107E2000C2008CE08093C4008EE0BFD0259A86E02B
:107E300023EC3FEF91E0309385002093840096BBC4
:107E4000B09BFECF1D9AA8958150A9F7EE24FF2480
:107E5000AA24A394B5E0CB2EA1E1BA2EF3E0DF2E45
:107E600098D0813461F495D0082FA5D0023829F13B
:107E7000013811F485E001C083E083D07FC08234F3
:107E800011F484E103C0853419F485E09CD076C0F8
:107E9000853579F47ED0E82EFF247BD0082F10E0C2
:107EA000102F00270E291F29000F111F84D07801E1
:107EB00065C0863521F484E086D080E0DECF84364C
:107EC00009F040C066D065D0082F63D080E0E81686
:107ED00080E7F80618F4F701D7BEE895C0E0D1E0D6
:107EE00058D089930C17E1F7F0E0EF16F0E7FF06A2
:107EF00018F0F701D7BEE8955ED007B600FCFDCFBD
:107F0000A701A0E0B1E02C9130E011968C9111977F
:107F100090E0982F8827822B932B1296FA010C0160
:107F2000A7BEE89511244E5F5F4FF1E0A038BF0770
:107F300051F7F701C7BEE89507B600FCFDCFB7BE05
:107F4000E8951CC0843761F424D023D0082F21D0B9
:107F500032D0F70185917F0114D00150D1F70EC0C6
:107F6000853739F428D08EE10CD085E90AD08FE02E
:107F700084CF813511F488E018D01DD080E101D084
:107F80006FCF982F8091C00085FFFCCF9093C600E3
:107F900008958091C00087FFFCCF8091C00084FDD0
:107FA00001C0A8958091C6000895E0E6F0E098E150
:107FB000908380830895EDDF803219F088E0F5DF4B
:107FC000FFCF84E1DECF1F93182FE3DF1150E9F7D5
:107FD000F2DF1F910895282E80E0E7DFEE27FF27CC
:027FE000099402
:027FFE0000057C
:0400000300007E007B
:00000001FF

atmega328_1b.hex (Optiboot for 4800baud at 1MHz)

:107E0000112484B714BE81FFE6D085E08093810001
:107E100082E08093C00088E18093C10086E0809377
:107E2000C20089E18093C4008EE0BFD0259A86E02D
:107E300023EC3FEF91E0309385002093840096BBC4
:107E4000B09BFECF1D9AA8958150A9F7EE24FF2480
:107E5000AA24A394B5E0CB2EA1E1BA2EF3E0DF2E45
:107E600098D0813461F495D0082FA5D0023829F13B
:107E7000013811F485E001C083E083D07FC08234F3
:107E800011F484E103C0853419F485E09CD076C0F8
:107E9000853579F47ED0E82EFF247BD0082F10E0C2
:107EA000102F00270E291F29000F111F84D07801E1
:107EB00065C0863521F484E086D080E0DECF84364C
:107EC00009F040C066D065D0082F63D080E0E81686
:107ED00080E7F80618F4F701D7BEE895C0E0D1E0D6
:107EE00058D089930C17E1F7F0E0EF16F0E7FF06A2
:107EF00018F0F701D7BEE8955ED007B600FCFDCFBD
:107F0000A701A0E0B1E02C9130E011968C9111977F
:107F100090E0982F8827822B932B1296FA010C0160
:107F2000A7BEE89511244E5F5F4FF1E0A038BF0770
:107F300051F7F701C7BEE89507B600FCFDCFB7BE05
:107F4000E8951CC0843761F424D023D0082F21D0B9
:107F500032D0F70185917F0114D00150D1F70EC0C6
:107F6000853739F428D08EE10CD085E90AD08FE02E
:107F700084CF813511F488E018D01DD080E101D084
:107F80006FCF982F8091C00085FFFCCF9093C600E3
:107F900008958091C00087FFFCCF8091C00084FDD0
:107FA00001C0A8958091C6000895E0E6F0E098E150
:107FB000908380830895EDDF803219F088E0F5DF4B
:107FC000FFCF84E1DECF1F93182FE3DF1150E9F7D5
:107FD000F2DF1F910895282E80E0E7DFEE27FF27CC
:027FE000099402
:027FFE0000057C
:0400000300007E007B
:00000001FF

boards.txt entries:

atmega328_1mhz_9600baud.name=Optiboot 1MHz 9600baud
atmega328_1mhz_9600baud.upload.protocol=arduino
atmega328_1mhz_9600baud.upload.maximum_size=32256
atmega328_1mhz_9600baud.upload.speed=9600
atmega328_1mhz_9600baud.bootloader.low_fuses=0xff
atmega328_1mhz_9600baud.bootloader.high_fuses=0xde
atmega328_1mhz_9600baud.bootloader.extended_fuses=0x05
atmega328_1mhz_9600baud.bootloader.path=optiboot_v50
atmega328_1mhz_9600baud.bootloader.file=atmega328_1a.hex
atmega328_1mhz_9600baud.bootloader.unlock_bits=0x3F
atmega328_1mhz_9600baud.bootloader.lock_bits=0x2F
atmega328_1mhz_9600baud.build.mcu=atmega328p
atmega328_1mhz_9600baud.build.f_cpu=1000000L
atmega328_1mhz_9600baud.build.core=arduino
atmega328_1mhz_9600baud.build.variant=standard

atmega328_1mhz_4800baud.name=Optiboot 1MHz 4800baud
atmega328_1mhz_4800baud.upload.protocol=arduino
atmega328_1mhz_4800baud.upload.maximum_size=32256
atmega328_1mhz_4800baud.upload.speed=4800
atmega328_1mhz_4800baud.bootloader.low_fuses=0xff
atmega328_1mhz_4800baud.bootloader.high_fuses=0xde
atmega328_1mhz_4800baud.bootloader.extended_fuses=0x05
atmega328_1mhz_4800baud.bootloader.path=optiboot_v50
atmega328_1mhz_4800baud.bootloader.file=atmega328_1b.hex
atmega328_1mhz_4800baud.bootloader.unlock_bits=0x3F
atmega328_1mhz_4800baud.bootloader.lock_bits=0x2F
atmega328_1mhz_4800baud.build.mcu=atmega328p
atmega328_1mhz_4800baud.build.f_cpu=1000000L
atmega328_1mhz_4800baud.build.core=arduino
atmega328_1mhz_4800baud.build.variant=standard

Ooooo! Lovely, thanks!

I'll give that a whirl in the morning when I can get at my ISP!

Rgds

Damon

PS. Down to ~20uA for my 1Hz control loop with 8MHz clock, so at 1MHz... B^>

Thank You tim7 for the nice job... I can use them myself for several low powered battery powered applications..
and Thank You @ DamonHD for asking the questions...

Doc

Hi Tim,

Should the extended fuse be 0x06 to allow for 1.8V BOD?

Should the low fuse be 0x42 at least to have the /8 clock prescaler selected for the 8MHz RC clock?

Rgds

Damon

Hi,

I have just successfully used your bootloader, thank you, with fuse modifications and other tweaks for my IDE:

atmega328_1mhz_4800baud.name=Optiboot 5 for bare 328P, 1MHz internal clock, fast start, 1.8V BOD, 4800baud upload, c/o tim7 20130416
atmega328_1mhz_4800baud.upload.protocol=arduino
atmega328_1mhz_4800baud.upload.maximum_size=32256
atmega328_1mhz_4800baud.upload.speed=4800
#atmega328_1mhz_4800baud.bootloader.low_fuses=0xff
atmega328_1mhz_4800baud.bootloader.low_fuses=0x42
atmega328_1mhz_4800baud.bootloader.high_fuses=0xde
#atmega328_1mhz_4800baud.bootloader.extended_fuses=0x05
atmega328_1mhz_4800baud.bootloader.extended_fuses=0x06
#atmega328_1mhz_4800baud.bootloader.path=optiboot_v50
atmega328_1mhz_4800baud.bootloader.path=atmega
atmega328_1mhz_4800baud.bootloader.file=atmega328_1b.hex
atmega328_1mhz_4800baud.bootloader.unlock_bits=0x3F
atmega328_1mhz_4800baud.bootloader.lock_bits=0x2F
atmega328_1mhz_4800baud.build.mcu=atmega328p
atmega328_1mhz_4800baud.build.f_cpu=1000000L
atmega328_1mhz_4800baud.build.core=arduino
atmega328_1mhz_4800baud.build.variant=standard

Rgds

Damon

And I have the system running from 2xAA NiMH as planned, drawing about 1uA for the AVR and about 2uA average for the LED being flashed. So, it definitely seems to work!

Many thanks again!

Rgds

Damon

Thanks for letting us know it worked. Quite right about the fuses, I forgot they'd need alteration. BTW Optiboot is maintained by WestfW at Google Code Archive - Long-term storage for Google Code Project Hosting., and he's made the code very easy to compile using the tools already included in the Arduino IDE.

Unfortunately I don't currently even have anything as basic as "make" on my ageing Mac, and my puny SheevaPlug doesn't really have space.

I could/should try and set up a build/dev environment in the corner of one of my chunky hosted servers, but it somehow feels evil using a big fat machine half around the world away to do my uC builds. Still, that's the "cloud" I suppose!

Rgds

Damon

If you have the Arduino IDE running then you already have everything you need (I'm less sure about Macs, but I think this is true). Just get the half-dozen-or-so files that make up the bootloader source code and put them in a directory in .../hardware/arduino/bootloaders/.

So, if I put the .c (etc) files in that directory, how does a hex file built against the correct preprocessor directives (such as F_CPU) happen?

Rgds

Damon