Pages: [1] 2   Go Down
Author Topic: ATmega328P targeted at low-power battery use: help needed with baby steps!  (Read 2525 times)
0 Members and 1 Guest are viewing this topic.
London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm working on the OpenTRV project (I expect I can't post links initially and so I won't even try, but you can find it with your favourite search engine if you wish) for saving energy in heating systems with a smart retrofit Thermostatic Radiator Valve and some stuff to call for heat from a boiler centrally.

I already have a PICAXE prototype up and running at my house across multiple nodes each controlling wireless valves via RFM22/RFM23, etc.

I want to build a parallel ATmega/Arduino stack which I expect to be able to do more sophisticated things, and more power-efficiently.

In some configurations our hardware will be powered by a couple of AA rechargeables so operation down to around 2V is needed, but operation at 3.3V (or 5V) may also happen, eg at mains-powered nodes.

I have so far succeeded in using my UNO as ISP to get a (8MHzRC/8, see below) bootloader into a couple of blank ATmega328P chips (so far as I can tell), but moving on to program them a TTL-232R-3V3 has me foxed so far.

I am running IDE 1.0.3 on a Mac.

I have added this to the end of the boards.txt file:

Code:
atmega328bb2AA.name=ATmega328 on a breadboard (8 MHz internal clock / 8), 2xAA supply 1.8V BOD

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

atmega328bb2AA.bootloader.low_fuses=0x62
atmega328bb2AA.bootloader.high_fuses=0xDA
atmega328bb2AA.bootloader.extended_fuses=0x06
atmega328bb2AA.bootloader.path=arduino:atmega
atmega328bb2AA.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb2AA.bootloader.unlock_bits=0x3F
atmega328bb2AA.bootloader.lock_bits=0x0F

atmega328bb2AA.build.mcu=atmega328p
atmega328bb2AA.build.f_cpu=1000000L
atmega328bb2AA.build.core=arduino
atmega328bb2AA.build.variant=standard

Note in particular the fuses (so the CPU clock is 1MHz, and BOD is set at 1.8V) and the f_cpu (set to 1MHz correctly) I hope.

Attempting to load the blink sketch spits out, after a pause:

avrdude: stk500_recv(): programmer is not responding

My best guess was that I probably also had to reduce "upload.speed" to 7200, but no luck so far.

I have automatic reset *apparently* working (reset tied high with 10K, via 100nF to RTS, so a LED on digital pin 13 (PB5) blinks when the IDE opens the connection and slowly thereafter).

I'm pretty familiar with electronics and computing, but have no AVR-specific test gear.  I have a couple of these 328Ps, an UNO and a Leonardo.

Any other clues?

Rgds

Damon
« Last Edit: April 15, 2013, 12:29:18 pm by DamonHD » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27114
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Would need to review your fuse settings with a fuse calculator, make sure they make sense.
http://www.engbedded.com/fusecalc

I have not tried to download a sketch via serial into a slow running part; serial speed lkely needs to be reduced as you noted (to 57600/8, or 115200/8).
Might also just have to download via ICSP (no bootloader) using File:Upload Using Programmer option.

Should change your descriptions to say 1 MHz also, not 8.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 208
Posts: 12932
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

...but moving on to program them a TTL-232R-3V3 has me foxed so far.

Why bother?  You have a method to program the target.  Why do you also need a bootloader?
Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Because if possible I want for me, and others playing with OpenTRV, to be able to be able to reprogram in situ (frequently during development) without levering chips in and out, as I do with the PICAXE for example, and without buying expensive or non-main-line hardware.  IE I want the development cycle to be cheap and fast and easy.

And I didn't find out how to get anything other than the bootloader into my ATmega32Ps via my UNO, but if someone could point me at the generic way to do that I'd be interested.

But note that it may simply be impractical given that 5V from the UNO would be toxic to some of the main components on my target system, and other in-situ users of the SPI bus in particular.

Fuse settings: I have run them back and forth through a calculator, and the brain of someone fairly experienced in AVR stuff, so I may have got them wrong still, but not for want of cross-checking!

Yes, probably I should change the name!

Rgds

Damon

PS. But I likely need to be educated about what the best way to do things is in this AVR/Arduino environment: every dev ecosystem is different.
« Last Edit: April 15, 2013, 04:38:02 pm by DamonHD » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 134
Posts: 6762
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The new optiboot build says:
make atmega328 AVR_FREQ=1000000 BAUD_RATE=57600
BAUD RATE CHECK: Desired: 57600, Real: 62500, UBRRL = 1, Error=-8.5%
avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=1000000  -DBAUD_RATE=57600 -DLED_START_FLASHES=3       -c -o optiboot.o optiboot.c
optiboot.c:252:2: error: #error BAUD_RATE error greater than -5%
optiboot.c:277:2: error: #error Unachievable baud rate (too fast) BAUD_RATE
make: *** [optiboot.o] Error 1

A bit of research suggests that 9600 should work OK.
Also 31250 (MIDI bitrate; it might be widely implemented.)
Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does the bootloader on the AVR auto-detect the baud of the incoming data, eg can I just set 9600 in the stuff in boards.txt now?

Or does that value get baked into the boatloader itself from the boards.txt file so I'll have to change it and reload the ATmegas?

Rgds

Damon
Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't understand your point, sorry!

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

http://gallery.hd.org/_c/energy-matters/_more2013/_more04/OpenTRV-prototype-20130410-V0p09-PCB-populated-and-prepared-for-simple-deployment-5-DHD.jpg.html

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
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just put this circuit on your board with a mini-jack - though that is optional - and you can program in circuit:
http://www.picaxe.com/Site_Resources/Media/Site_1/pinout/serial.jpg

And use the serial monitor for debugging.
« Last Edit: April 16, 2013, 11:44:19 am by KeithRB » Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm really not following.

That *is* how I use the PICAXE already.

Rgds

Damon
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: