element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Atmega328p, eeprom burnout and interupts
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 10 replies
  • Answers 4 answers
  • Subscribers 394 subscribers
  • Views 860 views
  • Users 0 members are here
  • EEPROM
  • atmega328
  • burnout
Related

Atmega328p, eeprom burnout and interupts

Former Member
Former Member over 10 years ago

Dear Community

 

I build myself an atmega328 based temperature controller to actuate relays in order to control beer fermentation temperature in a fridge.  I am fairy happy with what I have so far.  The control works well, 2 buttons are used to change the desired temperature and two buttons are used to change the allowable range in witch to keep the fermentation temperature.  The temperature probe is a LM35 which is sealed with epoxy and heat shrink and is housed in a stainless steel probe submerged in the fermenting wort (you beer).  It takes 10 temperature reading in 40 ms as as average (this is to avoid resonance with 50 Hz AC power, I might be a fool, comment welcome), it then adds these averaged readings into a array creating a rolling average.  I have tested the temperature readings at our local electronics department (lucky to be in a university environment) and it is pretty close to truth.

 

In void loop I don't use delay, I rather use this kind of settup:

 

void loop() {
  //use millis for timing 
  unsigned long curMillis = millis();

  if (curMillis - prevMillis >= sleep){
    prevMillis = curMillis;

bla bal bla

 

sleep is set to 250 ms.  I have found that this works well with the buttons.

 

The problem:

Due to my lack of knowledge I am writing 4 times a second to eeprom addresses in order to save setting in case of a power interruption.  Just today I read about eeprom burnout.  So if I understand it correnctly:

100 000 / 4 = 25 000 ms, thus if the eeprom address gets burned out after 100 000 write events, then that address will only last for about 25 seconds.  So what happens now is that whenever there is  power interruption the set range seems to be anything random, like 124.3 deg C, which is not ideal for making beer.  I think a solution to this problem would be to only write to the eeprom if anything changes just by comparing the eeprom value to the current value in the loop, maybe also add timing - not sure.

 

I found some code here:

EEPROM advanced usage on Arduino Uno / ATMega328 | Michael Bouvy

"

  • Read / write operations on EEPROM should never be interrupted : you should always disable/clear interrupts (cli()) before any operation and re-enable/set interrupts after (sei()).

"

So in the link above it is suggested that one disables interrupts while writing.

 

From this link:

http://playground.arduino.cc/Main/AVR

"

Note that the millis timer, and serial communication will be affected by disabling interrupts. The delayMicroseconds() function disables interrupts while it is running.

"

 

What do you guys think?  I am not sure how millis timer and serial will be affected and also do you think it is that important to disable interrupts during during read write?  I know nothing about interrupts.  What would be best practice?

 

Thanks for reading.

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 10 years ago +1
    Hello I think I have figured out a solution for my eeprom burnout problem and it is working fine so far, if it fails i will post it here. I now have an if statement that checks the current eeprom value…
Parents
  • bobcroft
    0 bobcroft over 10 years ago

    Armand,

                   I suggest you look at EEPROMex library which has the ability, I believe, to only write to the EEPROM if the data being written is different to that already stored in the EEPROM.

     

    The other way you could minimize EEPROM writes is to first read the value stored in your EEPROM and compare it to the current value it they are the same or within acceptable bounds, then you do not need to write the new value to the EEPROM.

     

    Otherwise I think you are sampling the temperature far too frequently as there is no way your process can respond in anything like a 40mSec period.  Averaging the readings is an excellent idea but I would think that if you sample the temperature at a frequency of once a minute that would more than adequate and probably still too fast.  A lot depends on the volume of liquid you are heating / cooling and the amount of energy available for heating  / cooling.  If for example you consider heating then too large a heater will cause the process to overshoot the target temperature whereas too little heat will make the process slow to respond.

    There is a cheap software package called Meguno Pro which is very cheap and available as a free trial.  This package can log data and continuously graph the data.  It would be very informative for you to log your process and see what sort of response in terms of temperature change over time you got.

     

    I hope that helps but if you need more help please come back.

     

    Bob

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to bobcroft

    Hi Bob, Peter and mcb1

     

    I have actually never used any kind of forum.  It is amazing that there are so many passionate people out there that is willing to take the time to answer questions from someone around the world.  Thank you! 

     

    Thank you very much for the advise, I will look into EEPROMex, the update function looks perfect.  I think I explained my situation badly.  I am not writing sensor data to the eeprom, only the set temperature and the range that is required.  The sensor data is only used in a couple of if statements to control the relays for switching between, OK state, Heating or Cooling (wait to cool, if cooling was triggered less than 5 min ago).  I will revisit the 40 ms temperature averaging and doe mare tests.  At this stage, the eeprom problem is my main headache.

     

    I am thinking of using EEPROMex and using the update function.  The other thing that I am wondering about, I used eeprom addresses 0, 1 and 2.  Will the other addresses still be OK - as I understand that is the case.

     

    I also have to disclaim that I am a mere mortal and on top of that a biologist, I suppose that is why I like the arduino, I can poke it and see what it does.

     

    Thanks again.  I ll get cracking as soon as I get time again.

    Armand

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 10 years ago in reply to Former Member

    Armand

    There is always a first time for everything.

    The arduino forums allow searching, which seems to work better than here IMO.

     

    If you are only writing the set and range to eeprom, I think you'll never wear it out.

    You can read as many times as you like, its just the write cycles that have a limit.

     

    Unless you add a real time clock (entirely possible and cheap), you cannot tell how much time has passed if it is depowered/reset as the Millis() starts at 1 at startup.

    You could write to eeprom the state you are in (0,1,2,3) and even how many minutes within that if you wanted to.

    ie Location 10 = 1 if you are in heat cycle, and Location 11 is the number of minutes you've been heating for (0-255), 20 =1 if you are cooling, 21 is the number of minutes you've been cooling for (0-255), etc.

     

    As far as I know each location has a finite number of write cycles, so yes the others should be fine.

    If you really wanted to get picky, you could write and then read it to ensure it works, and use the first locations as some pointer to where the data is.

     

    On the other hand just buy a new chip, and start fresh ...

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to mcb1

    Thanks mcb1

     

    Good ideas.  I agree, it is just better to get a fresh chip.  I have ordered, takes a little while here in South Africa.  What are your thoughts on brown out detection.  I am not clear on the actual importance of it especially when writing to eeprom.  I found a calculator here: Engbedded AVR Fuse Calculator

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 10 years ago in reply to Former Member

    Personally I've never had an application that requires brown-out detection (yet but one is coming up), and hence never considered it.

     

    I prefer to use external watchdogs, regardless of the internal capabilities of the uP.

    Many of them include brown-out detection, and cost a few dollars.

    If it's that critical, then I'd suggest looking at using one.


    If you are really concerned, you could detect the incoming voltage, have a large capacitor across the uP supply, and act accordingly.

    You could also add a LiPo battery just to to hold the uP while you shut down.

    Some of the Arduino boards include the option for a LiPo and include the charging cct.


    Nick gammon has a good guide to power saving here.

    http://www.gammon.com.au/forum/?id=11497

    and at 100nA you'd probably never have to worry about it EVER.



     

    I'm not sure what the process is when writing to the eeprom, and how its affected by a brown-out.

     

    As you can see there are several ways to overcome the problem, it's what suits you best.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to mcb1

    Thank you Mark

     

    Maybe one thing at a time.  This has been very educational.

     

    Cheers

    Armand

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 10 years ago in reply to mcb1

    Thank you Mark

     

    Maybe one thing at a time.  This has been very educational.

     

    Cheers

    Armand

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube