presetting eeprom

Any general or miscellaneous queries that do not fit into the other forum catagories

Moderators: Benj, Mods

Post Reply
jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

presetting eeprom

Post by jadiflow »

Hi,

I need to set some eeprom locations just one time, to read initial data when the unit is switched on first. From then on, the eeprom data will be changed as part of the operation. So I can't set it as part of the flowchart, but need to somehow set it when I program the chip. Can I do that?

Edit: I found that I can 'manually preset' the eeprom contents in the eeprom component icon. Will this value be in that location at download or is it just for simulation purposes?

Jan Didden

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

Re: presetting eeprom

Post by Benj »

Hello Jan

The EEPROM component is simulation only im afraid.

You can do the following however.

1) Create a flowcode program to load the contents of the EEPROM.
2) Download this program to the chip and allow it to run.
3) Create your flowcode program that reads the EEPROM values
4) Download this program to the chip.

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: presetting eeprom

Post by Steve »

The following C code will put some data into the EEPROM of a PICmicro:

Code: Select all

#pragma DATA 0x2100, 0x12, 0x34, 0x56, 0x78, "ABCD"
The "0x2100" is the address of the EEPROM memory, and 8 locations of EEPROM memory will be set.

This data is stored into the EEPROM memory when the chip is programmed.

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: presetting eeprom

Post by jadiflow »

Perfect! Thanks Steve, have a great weekend!

Jan Didden

carlstein
Posts: 12
Joined: Tue Nov 28, 2006 3:11 pm
Location: University of leicester
Contact:

clearing eeprom memory

Post by carlstein »

A useful tip to clear the EEprom cells first time they are used is to create a variable (eg: "count") with an incremental value for example: "count=count+1". Starting from address "0", Loop the counter to run up to 255, each time send a write command to the EEprom. Specify in the EEprom settings "count" as the address and "0" as the data. The EEprom will then clear to all zero's.

This can also be viewed in the simulation as Flowcode also simulates the random eeprom cell values which appear if you don't clear the memory, you will see zero's scrolling down the list!

I use routine this on one of my products to perform a "factory reset" and it initiates only when a certain switch input is held for a specified time during power-up.
Less elaborate is to use a PCB shorting link (jumper).



Carl

User avatar
goldwingers
Posts: 118
Joined: Wed Sep 06, 2006 1:22 pm
Location: London
Been thanked: 1 time
Contact:

Re: presetting eeprom

Post by goldwingers »

Try this, the program will check to see if loc 0 is 255, if not it will reload some preset points, if it is 255 it will bypass the eeprom write routine.

Regards

Ian
Attachments
Flowcode1.fcf
(4 KiB) Downloaded 522 times

jmccorison
Posts: 26
Joined: Mon Aug 18, 2008 11:47 pm
Location: Orcas Island, WA
Contact:

Re: presetting eeprom

Post by jmccorison »

Yes, but unfortunately you have a 1 in 255 chance that this will fail. Since the EEPROM memory locations are initially random, the first location could well have 255 in it. If this is a project for yourself, no big deal. But if you are developing a commercial product you can expect a lot of failures if your product is successful.

The basic idea is a good one, but make the "pass/fail" test more difficult. For example, put what you call the device as the first bytes in EEPROM. It is highly unlikely that "Acme Widget" would be the result of a random byte pattern. Some mathematician could tell you how to calculate the odds, but they are going to verge in impossible.

User avatar
goldwingers
Posts: 118
Joined: Wed Sep 06, 2006 1:22 pm
Location: London
Been thanked: 1 time
Contact:

Re: presetting eeprom

Post by goldwingers »

I agree about the odds, but the last write eeprom command actually sets eeprom loc 0 to 255, that is after all others have been initialised this should work like a basic lock. I would assume that you could write to other locations and use them as normal read write but the locations which were preset at start up would remain in place unless you change them, these could also be used for a software reset to factory settings.

Ian

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

Re: presetting eeprom

Post by Benj »

Hello

This is a great topic ! very useful. 8)

Using two or three bytes at the start of the EEPROM would pretty much guarentee that you have the correct values set. (two is probably plenty in most cases)

Eg

1 byte at the start gives a 1 in 256 chance of failure.
2 bytes at the start gives a 1 in 65536 chance of failure.
3 bytes at the start gives a 1 in 16777216 chance of failure.
etc.

Calculating the probability is fairly easy, for example with 5 bytes the probability would be equal to 256 x 256 x 256 x 256 x 256 or 256 to the power 5.

carlstein
Posts: 12
Joined: Tue Nov 28, 2006 3:11 pm
Location: University of leicester
Contact:

Re: presetting eeprom

Post by carlstein »

Here's a copy of the manual EEprom reset routine I described earlier. This programs all cells as 00h data.
Ok you may not want all Zeros but in some cases it's better to have a predicatable value, for instance, one of my programs uses the EEprom to store stepper motor data for animated figres, in this case a row of zero's would do no harm but a bunch of random values could well damage the motors.

Press the Switch on A0 to initiate the reset.
Attachments
eeprom reset.fcf
(5 KiB) Downloaded 440 times

carlstein
Posts: 12
Joined: Tue Nov 28, 2006 3:11 pm
Location: University of leicester
Contact:

Re: presetting eeprom

Post by carlstein »

Hang on, that doesn't work.
For some reason the Switch needs to be changed to a toggle switch, yes now it works!

Ben: Is this a "glitch"?

Carl

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

Re: presetting eeprom

Post by Benj »

Hello Carl

Thanks for the program.

If it is a glitch then im not able to reproduce it here. Both switch types act to clear the EEPROM via the simulation. Which version of Flowcode 3 are you using?

User avatar
goldwingers
Posts: 118
Joined: Wed Sep 06, 2006 1:22 pm
Location: London
Been thanked: 1 time
Contact:

Re: presetting eeprom

Post by goldwingers »

Hi guys,
Slight issue with your program, it does not reset location 255 since the eeprom starts at 0 - 255 that is in fact 256 locatons... another method without using connection points and resets all locations is attached.

Regards

Ian.
Dont ya just love flowcode
Attachments
eeprom reset.fcf
(5.5 KiB) Downloaded 343 times

carlstein
Posts: 12
Joined: Tue Nov 28, 2006 3:11 pm
Location: University of leicester
Contact:

Flowcode Version

Post by carlstein »

Hang on Ben, I'll just have a look.

It's 3.2.1.38

I think there's a later update, is it 3.22?

Carl

carlstein
Posts: 12
Joined: Tue Nov 28, 2006 3:11 pm
Location: University of leicester
Contact:

Re: presetting eeprom

Post by carlstein »

Just looked at goldwingers mod.

Yeh your'e right. I forgot about the options of the "loop until" icon.
But I do use the loop for de-bouncing a switch input, so that the program does not continue until the switch is released (otherwise the switch operation is carried out X number of cycles). Output B0 flashes to provide feedback to the operator.
Attachments
button press+flash.fcf
(5 KiB) Downloaded 345 times

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

Re: presetting eeprom

Post by Benj »

Hello Carl

The latest version is 3.4.7. You can download the update from here if you wish.

http://www.matrixmultimedia.com/Flowcode3a-X.php

Post Reply