Pages: [1] 2   Go Down
Author Topic: Getting ATMEGA328P to work below 2.7V  (Read 2096 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I am attempting to get my ATMEGA328P to work at low voltage (around 2.6V for 2x AA batteries). It works fine at 3.3V using the blink sketch, but at 2.6V it does not work.

I am using it together with a crystal and two capacitors for the clock, and programming the chip on my Duemilanove and extracting it when programmed and putting it on my breadboard.

I've read about fuses, and tried various settings using the fuse calculator http://www.engbedded.com/fusecalc. I did this by editing boards.txt and adding a new board definition, and changing the fuses settings. I attempted to set the brownout fuse to 1.8V, and the clock to a lower setting as I understand at 1.8V the maximum possible is 4Mhz(?).

I used these settings:

Quote
atmega328lowpower.name=Arduino Duemilanove Low Power

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

atmega328lowpower.bootloader.low_fuses=0x7F
atmega328lowpower.bootloader.high_fuses=0xD9
atmega328lowpower.bootloader.extended_fuses=0xFE
atmega328lowpower.bootloader.path=atmega
atmega328lowpower.bootloader.file=ATmegaBOOT_168_atmega328.hex
atmega328lowpower.bootloader.unlock_bits=0x3F
atmega328lowpower.bootloader.lock_bits=0x0F

atmega328lowpower.build.mcu=atmega328p
atmega328lowpower.build.f_cpu=1000000L
atmega328lowpower.build.core=arduino

However, I get this error when burning the bootloader via w/ Arduino as ISP;

Quote
****failed;
avrdude: verification error, first mismatch at byte 0x000
   0xff != 0x07
avrdude: verification error; content mismatch

Any help is very much appreciated, I am desperate now smiley

P.S. Burning the normal settings as bootloader worked fine, so my programmer appears to be fine.

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8646
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like the data sheet says 2.7 Volts is the minimum to get 10 MHz operation.  At 1.8 Volts you have to drop down to 4 MHz so I would recommend trying something more like 8 MHz at 2.6 Volts.   

I have also read somewhere that the Arduino bootloader can only deal with clock frequencies in powers of 2 (2 MHz, 4 MHz, 8 MHz, 16 MHz) to keep the calculation of buad rates reasonable.  Not sure how true that is and what the implications are.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you think I can use the 16MHz crystal to run the chip at 4MHz, should I be using the 128KHz internal clock source?
Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3214
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try looking into the prescaler fuse bits. I'm not sure about the 328, but other chips have a prescaler on the fuses... that may allow you to keep the crystal.
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Prescaler... like the 'divide clock by 8' flag?
Logged

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

Atmega328 as the single option to divide or not the input frequency by 8, it has no PLL or anything else to play with the clock source, you can either enable that fuse, replace the crystal, or use the internal RC oscilator but that one is a bit risky if you want to use serial coms.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Burning the bootloader with the default settings works fine, and the chip is programmable afterward.

However, changing just one setting, e.g. setting Extended to FF to disable brownout detection, causes that error message and the chip is unprogrammable.

Ideally I'd want the clock to be divided by 8 to get 2MHz, and brownout detection disabled, and use the external crystal.

If anyone knows how to do this, I would appreciate it very much as I am close to 'laming out' and doing something much less elegant to get a job done.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 596
Posts: 33266
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do you think I can use the 16MHz crystal to run the chip at 4MHz

No.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8646
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

However, changing just one setting, e.g. setting Extended to FF to disable brownout detection, causes that error message and the chip is unprogrammable.

Trying to set the Extended byte to 0xFF won't work because when avrdude reads back the value (to verify it) the "don't care" bits read as 0.  You have to say 0x07 to set the bottom three bits to disable BOD.  

Note: the CKDIV8 bit just pre-sets the Clock Pre-scale Register (CLKPR).  You set that register at run time to set the system clock divider to any power of two between 1 (2^0) and 256 (2^8).  Use the 16 MHz crystal and set the CKDIV8 fuse to start the CPU at 2MHz, then change the CLKPR register to run the processor up to 8MHz at run time.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much. I see the problem, perhaps a bug in the Calculator web page. With that setting I was able to power the chip from 2.6V and it worked fine.

The next step is lowering the clock speed, ideally to about 4MHz to suit the rating graph:



I ticked the CKDIV8, resulting in:

7F DA 07

And changed CPU speed to 8MHz:

atmega328.build.f_cpu=8000000L

The bootloader burnt OK, but when I replaced the chip back into my Duemilanove, I get stk500 sync errors.

Any ideas?

If there are any insights on how to use the internal clock too, that would be useful. I already have the crystal so I don't need it this time, but it might be useful for other people to see.
Thanks.
« Last Edit: April 28, 2011, 08:02:40 pm by jonny5alive » Logged

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

But your duemilanove board as an 16Mhz crystal in it...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But your duemilanove board as an 16Mhz crystal in it...

Should I use 2000000 instead? (16000000 / smiley-cool
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you should look at using a charge pump setup to get the voltage up.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

Quote
atmega328lowpower.upload.speed=57600
   :
atmega328lowpower.build.f_cpu=1000000L
I don't think you can run 57600bps at 1MHz clock rate.  In fact, 1MHz seems to be a particularly LOUSY speed for serial comm purposes.   See http://www.wormfood.net/avrbaudcalc.php

Assuming you want a crystal, you probably need an actual slower crystal rather than using the internal divider to generate the lower clock rate from a high-speed crystal.  I don't recall seeing anything in the datasheet that says that the crystal oscillator is capable of operating at high frequencies even when the voltage is low; you shouldn't assume anything other than the oscillator following the same section 23.8 graph...
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8646
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you use a 16 MHz crystal and turn on CKDIV8 to get an initial 2 MHz clock, that is what the bootloader will run at.  If you later change the CLKPR register in your sketch to bring the speed up to 4 or 8 MHz then your sketch will be running at a different rate.

I think you should put the final clock rate in the boards.txt entry so millis() and such will work in your sketch.  That will mean the baud rate used by the bootloader will be much lower.  For example if you start at 2 MHz, boost up to 8 MHz later, and the bootloader normally runs at 9600, put:

atmega328lowpower.upload.speed=2400
   :
atmega328lowpower.build.f_cpu=8000000L
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1] 2   Go Up
Jump to: