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.