How an EEPROM works?

A forum where Flowcode v7 user created components can be shared, discussed and reviewed.

Moderator: Benj

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

How an EEPROM works?

Postby Jacob1 » Mon Feb 12, 2018 7:43 pm

Hello,

I am trying to understand how to use a EEPROM. The flow code wiki doesn't really clearly explain how to use the read and write macros and I have tried to look at other forums but I,m still confused, so I wondered if someone could explain what these are used for? I am trying to create a program which stores light measurements, which are read as a byte value or int. I can easily display the light measurements on the LCD, say every 1 second. However, I'm not sure how to store each measurement every second and then how to show each of these values on the LCD by pressing a switch. I have attached my program which I understand may be wrong!

The program will not work on simulation, as there is no light to be read by the light sensor but I just want to know how to set up the basics in terms of the EEPROM

Thanks
Jacob
Attachments
EEPROM.fcfx
(11.24 KiB) Downloaded 33 times

User avatar
Benj
Matrix Staff
Posts: 14157
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4080 times
Contact:

Re: How an EEPROM works?

Postby Benj » Thu Feb 15, 2018 1:07 pm

Hi Jacob,

EEPROM is a means of storing data in a way so that it will be present after a power cycle or reset. It is often used for things like configuration settings or other values that may need to change but won't change to often.

The reason for not changing too often is that the EEPROM normally has a limit on how many times you can write a location. Usually 100,000 or 1,000,000 times. Even at 1,000,000 times if you wrote to a location every second you would burn out the location in 11 days. Then keep in mind that you could potentially write to the same location thousands or even millions of times a second and you can see just how quickly you can burn out a location.

You may be better of using an array variable if you don't need the data to persist after a power cycle or the unit will remain powered during normal operation.

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: How an EEPROM works?

Postby Jacob1 » Thu Feb 15, 2018 9:37 pm

Hi,

Thanks for your reply, that does help. I am still a bit confused though regarding when to use the write and read macros? For the example I attached which I am working on, I'm not sure if I correctly used the EEPROM. Would you write a variable to a certain address being 0-255? And then use the read macro the read the variable afterwards? It asks for the light measurements to be stored on the EEPROM, say every second over a period of 3 minutes (although it originally asks for 24hrs) and then two switches are to be used to scroll through all the measurements recorded. So I'm just a bit unsure as how to go about this,

Thanks,
Jacob

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: How an EEPROM works?

Postby Jacob1 » Wed Feb 28, 2018 9:51 am

Hello,

Still working on the EEPROM program, just wondered if anyone would be free to check my program for any errors. The program produces 0s on simulation, as there is no light but I just want to ensure I have set up the EEPROM correctly. I have added 1 to the address each time, hoping that this means the light variables taken every second go to a new address. On the project board itself, the program does show values when A0 is pressed, which
I believe were 100 and some other zeros so I don't think this is correct. Its very hard to now if I have initialized the program correctly by simulation, as
i cannot simulate the light sensor!

I appreciate your help and any advice about any changes to the program if there are errors would be most appreciated,
Jacob

User avatar
Benj
Matrix Staff
Posts: 14157
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4080 times
Contact:

Re: How an EEPROM works?

Postby Benj » Wed Feb 28, 2018 10:48 am

Hi Jacob,

You should be able to use an adc slider to allow you to simulate the analogue light level. Also you haven't attached your program for us to have a look for you.

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: How an EEPROM works?

Postby Jacob1 » Wed Feb 28, 2018 11:13 am

Ok I will try that also,

Apologies, I did attach my program on my first post but I think I have made some changes. Here it is,

Thanks for your help,
Jacob
Attachments
EEPROM.fcfx
(14.67 KiB) Downloaded 38 times

User avatar
Benj
Matrix Staff
Posts: 14157
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4080 times
Contact:

Re: How an EEPROM works?

Postby Benj » Wed Feb 28, 2018 12:14 pm

Hi Jacob,

You seem to take light level readings and store into EEPROM locations 0-49. When the adress variable reaches 50 you exit the write loop and continue.

You then wait for pin A0 to become high and then perform the readback. However your adress variable still has the value 50, maybe this needs resetting back to 0 using a calculation icon. You might also need to increment it like you did when writing data or you will read back the same value again and again.

You also seem to only read a single value if A1 is pressed before looping back and writing again. As the address variable still has the value 50 the write routine will simply be skipped.

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: How an EEPROM works?

Postby Jacob1 » Wed Feb 28, 2018 2:49 pm

Thanks for your reply, that does make sense!

I have changed my program now, so after writing, the adress = 0 and then I perform the read function, with a incremented count before. However, during simulation we can see that during write it counts up perfectly until 50 then resets to 0, but then during the read macro it will not count up again. So I was wondering if there is a reason for this?

Also when A0 is high, I am simply printing the variable, is there a way as you said that i can print 1 number after the other instead of just one value?
I've attached my updated program
I really appreciate your help,
Jacob
Attachments
EEPROM.fcfx
(15.29 KiB) Downloaded 34 times

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: How an EEPROM works?

Postby Jacob1 » Thu Mar 01, 2018 11:33 am

Hi Ben,

I have had slow progress with the EEPROM program, but have now managed to successfully increment the adress variable by 1. I have changed the program now, so that it it will write untill 50, then it goes back to 0 and increment the adress by 1 and read from this untill 50 again. I don't know if this is correct, in terms of successfully storing the light variables. I then have another loop which just displays a message so I know it has finished storing the light measurements. When A0 is high, it will jump out of this and into another which simply displays the variable. The program task itself asks for the variables to be scrolled forwards and backwards by pressing A0 and A1. I still haven't worked out how to display the light variable, in terms of separate variables from adress 0-49.

If you have any idea of how to do this I would be grateful if you could explain. Would I need to change my variable to a string, say of index 50 and then allocate 50 strings with different light variables? This seems a long method and I don't think this is the correct way of doing it

I've attached my new changed program, I will get there eventually! :)

Thanks
Jacob
Attachments
EEPROM.fcfx
(16.42 KiB) Downloaded 37 times