Page 1 of 1

EEPROM question

Posted: Fri Feb 15, 2013 1:59 pm
by Michaelt
Hello again.

I am trying to finish må rebuilt refrigiuator to a climate box that can keep my Beer brews at the perfect fermentation temperature. the program is working and my hardware is complete but i just have 1 final detail to make, In case there is a power loss where my Climate box is it will not go back to the previus temperature setting when power is restored. and this is baad for my beer :cry:

I have tryed testing the eeprom function but with no luck and i am pretty sure what the problem is, i just don't know how to fix it.

Here is the details.

In the program i have a Floating point variable called setpoint this i can adjust up and down between +3 and +25 degrees C. It gets converted to string[4] to display on LCD also,
i just havent been able to convert it to Uint witch seems to be the dataformat that the eeprom uses.??

I also have to make a function in the Initialiaze function that retreaves the data from the eeprom and puts it in the setpoint again.

so to ad up my problem i need to convert my (floating point variable ---> (Uint variable) and the back again

Hope this is solvable

regards from Michael

Re: EEPROM question

Posted: Fri Feb 15, 2013 2:05 pm
by medelec35
Hi Michael,
Are you able to post your flowchart so it can be looked at?
That way I can get an idea on the typical values of floats and implement conversion to EEPROM.

Re: EEPROM question

Posted: Fri Feb 15, 2013 2:48 pm
by medelec35
Hi Michael,
I have attached something for you to look at.
It's the way I would save and retrieve float (to 2 decimal places) to and from EEPROM
Assuming numbers are not too High (0.00 to 655.35)

Martin

Re: EEPROM question

Posted: Sat Feb 16, 2013 7:29 pm
by Michaelt
Hello Medelec
and thanks for your response, I have a few questions to your uploated program that i hope u can clarify for me. :D

I se thant my problem was that i stored the data as a floating point in the eeprom at only one address,
If i understand it correctly u divide the floatVar in to bytes and then store it in 2 seperate adresses.

I was using a variabe as the adress location in the eprom, i see that u just use 0 and 1.

Also u multiply the float with 100 in the beginning and divide again in the end.. Why is this?

I am do not completely understand whay u writ the 20 in location 2, but i will try using the dividing in to bytes and se if it works..
thanks a lot so far :)

Re: EEPROM question

Posted: Sat Feb 16, 2013 7:56 pm
by medelec35
Michaelt wrote: If i understand it correctly u divide the floatVar in to bytes and then store it in 2 seperate adresses.
Correct since each EEPROM address can only store whole numbers from 0 to 255
Michaelt wrote: Also u multiply the float with 100 in the beginning and divide again in the end.. Why is this?
Since EEPROM can only store whole numbers if you have got a temperature of 23.65
Then the whole part is only 23
So I multiplied by 100
= 2365
Stored 2365 as two bytes.

When 2365 is retrieved, then it has to be divided by 100, so it's back to original number.
2365/100 = 23.65

There maybe better ways, but it's the first thing I though of.
Michaelt wrote: I am do not completely understand whay u writ the 20 in location 2,
Only reason for this 20 is so it can be detected of EEPROM was updated or not.
If address 2 was not set at at 20 then contents of EEPROM sould not be retrieved as EEPROM has not been updated with any new values since power was 1st applied.
You can then use this fact to load default values on to EEPROM.

Martin

Re: EEPROM question

Posted: Sat Feb 16, 2013 9:14 pm
by Michaelt
Awsome. it is working perfect now, Thanks a lot for your help Martin :D

Have a good weekend
Regards from Michael

Re: EEPROM question

Posted: Sun Feb 17, 2013 12:28 am
by medelec35
No probs, just happy your up and running.
Michaelt wrote: Have a good weekend
Thanks you too have a good weekend :)

Martin