Bad EEPROM written in ATmega48PA

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,

 

I have found a problem on some devices I have with ATmega48PA. I have to copy a flash variable to EEPROM memory everytime I reset the device, but sometimes the lower bits are written to 0xFF. The only solution I have found is to disconnect AVcc pin from V+. In this case it works properly but it is not the best solution I think.

I have also tried different solutions without good results:

- To add L-C filter to AVcc.

- To add 100nF cap to V+ and GND.

- To add 100nF cap to Aref and GND.

- To add a regulator to V+.

 

This problem happens only in some devices and not always. And the devices are powered by a 6V battery.

Could you help me solving this issue, please?

Thanks in advance.

 

BRs,

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is brownout enabled and at the right level?

 

As the datasheet tells you:

 

 

(and yes that's actually the mega32 datasheet - I happened to have it open - But it's the same info in all AVR datasheets).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

exnorkel wrote:
I have to copy a flash variable to EEPROM memory

Why?

 

Surely, if it's in flash it is already non-volatile - so what's the point in copying it to EEPROM?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As Cliff said,  BOD is important.  

 

But so is any emergency power-fail detection.  

You must detect when the power is failing and have sufficient voltage on a reservoir capacitor to perform the EEPROM write before the BOD kicks in.

 

No problem with a planned shutdown.   You do the EEPROM write before you remove power.

 

Judging by your comments in #0,  you appear to think capacitors are optional.   You should always follow datasheet recommendations.  i.e. 100nF on VCC, AVCC, AREF.

The AVR has a maximum VCC of 5.5V.   6V is too much.   You should have a resistor or LDO.    If there is a reservoir capacitor on VCC,  you can monitor the Battery for power-fail.

 

Mains power can fail instantly.   If a punter removes the battery,  you have instant power failure.   Normal batteries will die slowly.   So you have plenty of time to start an orderly shutdown.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot for your help.

 

@clawson, Brown out was disabled, so I have tried to program BOD at 1,8V and now all devices work properly. Vcc never reaches this value but it works properly now. It is a little bit strange, isn´t it?

 

@awneil, the variable in EEPROM could be changed by the user during a normal use, but I have prepared a special reset to restart this variable from flash. For this purpose is necessary to take out the battery during the device initialization.

 

@david, I will apply 100nF capacitors in Vcc, AVcc and Aref for more stability. Vcc is always lower than 5,5V.

 

I have checked that the system works good, but do you think is enough with this changes?

Thanks.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

On the way down from 5V to 0V as the power dies away the AVR will likely pass through all voltages on the way down. At some point there comes a time when there may still be enough energy to operate the fetch/execute logic but things like PC and SP and R0 to R31 may begin to corrupt so rogue code executes. It might hit something that writes to EE registers (EEAR defaults to 0x00 so often a rogue write is to EEPROM location 0)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

exnorkel wrote:
@clawson, Brown out was disabled, so I have tried to program BOD at 1,8V and now all devices work properly. Vcc never reaches this value but it works properly now. It is a little bit strange, isn´t it?

Not really strange.  You haven't said much more than "reset".  Do you really get the same symptoms with an enternal reset as with a power-on reset?  I'd guess not.

 

How can you say it "never reaches that value"?  What does the datasheet say about how long it takes for BOD or POR to happen?  have you used a fast 'scope and watched Vcc right on the power pins?  And the Gnd pins?

 

You haven't said what else is attached to the AVR.  Without BOD at a proper level, the AVR is going to start running at about 1V -- which is below spec for proper operation, and in particular EEPROM writes.  It could perhaps just be this race.  But other devices in your circuit could also "wake up" and cause the rising Vcc to dip momentarily.

 

1)  Use an appropriate BOD in all your AVR apps.

2)  Heed advice about decoupling caps.

3)  Ensure enough power supply capacitance to handle the desired rising-power curve for your app.

4)  After you characterize your rising-power curve, use appropriate fuse settings.

5)  In all my apps, after startup and setting of port pin directions, I delay for as many milliseconds as the app can handle.  A typical time is about 100ms when I don't care about starting up fast.  You'll probably find that this alone will mask problems addressed in the list above.  Note the "mask problems".

 

And/or just use proper capacitors, use BOD, use slow startup time fuses, and add a startup delay in all your apps.  Then you don't run into "strange".

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will add to theusch 5:

often there are other things that start up about the same voltage as the the chip release reset, so the voltage can make a small drop on the way up! 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have tried to program BOD at 1,8V and now all devices work properly.

I would set it as high as possible ie ~4V for a 5V system.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
The AVR has a maximum VCC of 5.5V. 6V is too much.
exnorkel wrote:
the devices are powered by a 6V battery.
exnorkel wrote:
with ATmega48PA.

This model line should be OK...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

exnorkel wrote:
@awneil, the variable in EEPROM could be changed by the user during a normal use, but I have prepared a special reset to restart this variable from flash. For this purpose is necessary to take out the battery during the device initialization.

I'm confused -- if you take out the battery, how does the AVR run?

 

I have more to say about disconnecting AVcc "helping" the symptoms.  But I'd need a more thorough example of this reset sequence for "restore factory defaults" and the battery removal and re-insertion and overall connections.  The short answer is that a lightly-loaded AVcc may take much longer to drop into POR range than Vcc.  So you get strange combinations of the AVR trying to run essentially without supplyV.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your help.

 

I have received the new PCB with the last changes and prepared a new FW avoiding the EEPROM write failure. These are the main changes / features of the new system:

  • Vcc never surpasses 5,5V. There is a diode and a 10µF capacitor before the µC.
  • Now the µC is ATmega168PA.
  • I have added 100nF capacitors in Vcc, AVcc and Aref for more stability.
  • BOD is activated to 1,8V but I desactivate it in sleep mode to avoid high battery consumption. In my case, BOD activation increases the current consumption 150 times.

 

For your info, the "special reset" works like that: During the initialization, after battery connection, I write a default value to a EEPROM variable during some seconds. If the battery is disconnected during this time the variable is reseted. If not, the variable is written again to the previous value.

 

My doubt now is about the up and down voltage slopes in Vcc during ON/OFF situations. How is possible to calculate the minimum slope time in each case?

 

For the moment the first 200 devices are tested and work perfectly, so I will continue working in the same way.

 

Thanks!!