Page 1 of 1

presetting eeprom

Posted: Thu May 22, 2008 1:05 pm
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

Re: presetting eeprom

Posted: Fri May 23, 2008 9:57 am
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.

Re: presetting eeprom

Posted: Fri May 23, 2008 2:39 pm
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.

Re: presetting eeprom

Posted: Fri May 23, 2008 5:32 pm
by jadiflow
Perfect! Thanks Steve, have a great weekend!

Jan Didden

clearing eeprom memory

Posted: Wed Sep 17, 2008 4:13 pm
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

Re: presetting eeprom

Posted: Sat Sep 20, 2008 4:39 pm
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

Re: presetting eeprom

Posted: Sun Sep 21, 2008 4:36 pm
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.

Re: presetting eeprom

Posted: Mon Sep 22, 2008 6:32 pm
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

Re: presetting eeprom

Posted: Tue Sep 23, 2008 10:37 am
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.

Re: presetting eeprom

Posted: Tue Sep 23, 2008 4:09 pm
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.

Re: presetting eeprom

Posted: Tue Sep 23, 2008 4:14 pm
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

Re: presetting eeprom

Posted: Tue Sep 23, 2008 4:56 pm
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?

Re: presetting eeprom

Posted: Tue Sep 23, 2008 6:31 pm
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

Flowcode Version

Posted: Wed Sep 24, 2008 7:45 am
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

Re: presetting eeprom

Posted: Wed Sep 24, 2008 8:00 am
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.

Re: presetting eeprom

Posted: Wed Sep 24, 2008 9:20 am
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