PDA

View Full Version : Internal eeprom - erase block



ruijc
- 27th December 2007, 09:12
Hi guys,

will start making some experiments with saving data to eeprom and dumping the data to lcd or PC via rs232.

First i will try with the internal eeprom to see how that works and after with an external eeprom.

I've been reading the pbp manual and will use the write and read commands.

My first question is :

My code will need to sart with clearing the eeprom before saving new data ( 1st erase old data then save new data ).

Is there a simple way to erase ( by code ) all internal eeprom memory at the beggining of the program ?

Thanks
.

atwoz
- 27th December 2007, 10:22
So you want to erase the eeprom every time the pic is started?

I'm rather new to pics and PB, but I'll give you my opinion :).

Maybe you can add something like:

w0 var word
for w0 = 0 to 255 'It depends on how many slots you want to erase, I'm erasing 256
write w0, 0 'We write a zero to the eeprom at the desired location, like erasing it
next w0 ' we continue with the next w0

hope this helps.

By the way, there's the Data command, with it you can preset the eeprom to whatever you want at the time of the programing. You add Data @0,2,6, 3, 50, etc at the beginning of your program and when your program your pic (not every time you power it up) the eeprom recieves the values you specified, in this case:

eeprom 0 = 0
eeprom 1 = 2
eeprom 2 = 6
eeprom 3 = 3
eeprom 4 = 50

bye

Art

atwoz
- 27th December 2007, 10:42
Look at what I found. Darrel creates some really awesome extensions all the time, maybe this one will help you with what you are doing.

http://www.picbasic.co.uk/forum/showthread.php?t=2444

sayzer
- 27th December 2007, 11:07
Check this one.
Modify as needed.





ReadMem VAR BYTE
Value VAR BYTE

Begin:

FOR ReadMem = 0 TO 128 'Scan eeprom
READ ReadMem, Value
IF Value <> $FF THEN Start
NEXT ReadMem

Start:

' your "value" variable gets a value here.
'..
'....

' when you want to save something into eeprom, goto "save".

GOTO Start


Save:
IF ReadMem = 128 THEN ' last eeprom location.
WRITE 0, Value ' thus, start from the beginning
WRITE 128, $FF ' assign $FF to last written eeprom location.
ELSE
WRITE ReadMem + 1, value 'save your value into eeprom after the current eeprom address.
WRITE ReadMem, $FF 'assign $FF to the current eeprom location.
ENDIF 'new eeprom location will be incremented,
GOTO Begin '...with the next eeprom scan.

ruijc
- 27th December 2007, 16:00
atwoz,

thanks for the help...also...very interesting link ;)

sayzer,

also thanks for the help.

Nice code ;)

If i understand it will search the eeprom for a good value, send it to "start" to process it.
Then when saving, saves the new value to the eeprom and deletes the previous address value.

This can be very handy ;)

Although what i will be using is more like this:

1st : erase all eeprom if button #1 pressed
2nd : send all data stored in eeprom via rs232 if button #2 pressed
3rd : start collecting data and saving it to eeprom if button #3 pressed
4th : stop collecting data and go back to starting loop if button #4 pressed


Since the data being colected and saved into the eeprom will be unique ( meaning that everytime the pic restarts and will if it will colect data it cannot be mixed with old data ) the entire eeprom will have to be deleted and ready to receive o toon of fresh continuous data.

.

sayzer
- 27th December 2007, 16:04
I see.

But, if you are erasing eeprom very frequently in your application, I do not now what "very frequently means ??", then your eeprom will be dead "very soon".

Then, very soon, your customers will be calling you "very frequently".

ruijc
- 27th December 2007, 17:24
hehehe :)

all true ;)

but like i said i'm just experimenting with reading and writing.

When i manage to get it right i will move to external eeproms


Microchip states that it's "1,000,000 write EEPROM endurance".

I hope it's true :)
.

skimask
- 27th December 2007, 17:35
Microchip states that it's "1,000,000 write EEPROM endurance".

Search the microchip website. Somewhere there's an App-Note that talks about Microchip's EEPROM endurance and how to get the most out of it.

mister_e
- 27th December 2007, 17:41
yeah i remind this one... but i'm not sure if it wasn't only for EXTERNAL eeprom.. playing with page write, voltage and temperature seems to be external dedicated tricks to me... but yeah i may have missed the one about PIC!

http://www.picbasic.co.uk/forum/showthread.php?t=1670

skimask
- 27th December 2007, 18:08
yeah i remind this one... but i'm not sure if it wasn't only for EXTERNAL eeprom.. playing with page write, voltage and temperature seems to be external dedicated tricks to me... but yeah i may have missed the one about PIC!
http://www.picbasic.co.uk/forum/showthread.php?t=1670

Yep, got me again, that's the one I was talking about. For some reason, I thought it was for internal eeprom/flash. I have yet to totally wipe out a flash PIC or on chip EEPROM on a PIC yet. I've worn out a small chunk of one, like the first 64 bytes of an older 18F4620, but not completely...yet...today...or even this year... I can sure try :D

sayzer
- 28th December 2007, 07:29
Some statements from 24LC32 datasheet.

"
• Endurance:
- 10,000,000 Erase/Write cycles
guaranteed for High Endurance Block

- 1,000,000 E/W cycles guaranteed for
Standard Endurance Block
"


In the same datasheet, there is also this;

"...the first 4K, starting at address 000,
is rated at 10,000,000 E/W cycles guaranteed. The
remainder of the array, 28K bits, is rated at 100,000 E/W cycles guaranteed."


Do I get it wrong, or the datasheet contradicts itself?


----------------

BrianT
- 28th December 2007, 08:51
What this is saying is that the first 4k locations are 'high endurance' (and probably physically larger). The remaining 28k bytes are 'standard endurance'.

Just make sure your code always starts to store data from address 0 so the low adfdresses get most writes and the highest see less writes.

HTH
Brian

sayzer
- 28th December 2007, 09:13
What this is saying is that the first 4k locations are 'high endurance' (and probably physically larger). The remaining 28k bytes are 'standard endurance'.

Just make sure your code always starts to store data from address 0 so the low adfdresses get most writes and the highest see less writes.

HTH
Brian

Hi Brian,


What it says is clear.

The thing is, for standard block, it says 1M cycle at the beginning, but 100K cycle at the end of the statement. Read it again!



---------------------

ria_river
- 13th January 2008, 04:25
Hi everyone!

I'm using PIC16f877a and I program it this way:

'PIC DEFINES
'--------------------
@ DEVICE pic16f877a, XT_OSC
@ DEVICE pic16f877a, WDT_ON
@ DEVICE pic16f877a, PWRT_ON
@ DEVICE pic16f877a, BOD_ON
@ DEVICE pic16f877a, LVP_OFF
@ DEVICE pic16f877a, CPD_OFF
@ DEVICE pic16f877a, PROTECT_OFF
@ DEVICE pic16f877a, WRT_OFF

'LCD DISPLAY
'--------------------
DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
'DEFINE LCD_COMMANDUS 2000
'DEFINE LCD_DATAUS 50

ADCON1=7

prnt var byte[2]

TRISB=%00000000
TRISC=%00000000
TRISD=%00000001
CMCON=%00000111
'CVRCON=%0000000
OPTION_REG.7=0

EEPROM 0,[1]
EEPROM 1,[8]

lcdout $fe,1,"Reading eeprom"
read 0,prnt[0]
read 1,prnt[1]
lcdout $fe,1,"Reading=",#prnt[0],#prnt[1]

end

When I load the hex file I can see the values 1 and 8 stored in eeprom address 0 and 1 respectively.My problem is that it can't read those values. the lcd will just display "Reading=00".Please help me

skimask
- 13th January 2008, 06:18
Try this for grins, same thing but different...



loc0 var byte
loc1 var byte
.................
write 0,1
write 1,8
lcdout $fe,1,"Reading eeprom"
read 0,loc0
read 1,loc1
lcdout $fe,1,"Reading=",DEC loc0,DEC loc1
end

Should say "Reading=18" when it's run.

ria_river
- 14th January 2008, 10:08
I also got problem writing the eeprom. I program it this way:

lcdout $fe,1,"writing the eeprom"

write 0,2
write 1,3
pause 2000

lcdout $fe,1,"Successful!"

end

The output is terrible.It will just make the lcd display "writing the eeprom" and it will keep on refreshing...
Please help me...

mister_e
- 14th January 2008, 17:07
Use a STOP or an endless loop before the END statement.

pause 2000
lcdout $fe,1,"Successful!"
Here: GOTO Here
end

ria_river
- 17th January 2008, 10:37
Thanks steve.
I'll try this.

ria_river
- 19th January 2008, 06:55
Hi Steve!

I placed an endless loop before the END, but still i got the same output.
What should I do?
Please help...

ria_river
- 19th January 2008, 07:04
Hi skimask!
The DEC code will cause a compilation error.
What shall I do?
If you know other means please tell me...
Thank you in advance.

skimask
- 19th January 2008, 07:12
Hi skimask!
The DEC code will cause a compilation error.
What shall I do?
If you know other means please tell me...
Thank you in advance.

What shall you do?
Read the manual, figure out how to use it for yourself.
Jeez...try to do some of the legwork yourself for a change...
I know of plenty of other 'means' to do what you want, but you want to be spoonfed like a little baby...

Unless of course you don't have a manual because you've got a pirated copy of PicBasicPro.
Which is entirely possible.
You know that online PDF at MeLabs website isn't exactly up to date.

ria_river
- 19th January 2008, 07:21
Thank you for all the help.

I been reading the manual a lot of times. I even follow the codes and procedures provided by the manual.
It's just simply won't work.

Again, thank you very much for your time and ideas.

ria_river
- 8th February 2008, 12:47
Hi everyone!

I can read and write now using the pic16f84a but I can't do that using pic16f877a.
Is there any lines I have to add inorder to allow reading and writing the eeprom?
I've read the 16f877a datasheet. It is stated there that I have to disable all interrupts before writing. I've tried that but still won't work.

A working simple code for reading and writing the internal eeprom of pic16f877a is all I need.

Please help me...
Thank you in advance.

skimask
- 8th February 2008, 13:37
Hi everyone!
I can read and write now using the pic16f84a but I can't do that using pic16f877a.
Is there any lines I have to add inorder to allow reading and writing the eeprom?
I've read the 16f877a datasheet. It is stated there that I have to disable all interrupts before writing. I've tried that but still won't work.
A working simple code for reading and writing the internal eeprom of pic16f877a is all I need.
Please help me...
Thank you in advance.

Well, since you stated that you have beening trying to get it to work, why do YOU post YOUR code, and I'm sure WE can HELP YOU figure out what YOU are doing WRONG.

And how many times do you have to post the same question, and/or hijack other threads?

ruijc
- 11th February 2008, 15:32
Hi all,

returning to the original thread...

I have sucessfully created the circuit and code to work with data and save them it to the external eeprom with a determinated timming.

I have managed to save/read data in 2 blocks ( 2 sessions ).

I have one part of the code that is responsable to erase both blocks of data.

My erasing code is simple and i use a set of ( For x to y...next ) instructions where x and y are the block's starting address and ending address.

I could use more memory blocks and increase the project's performance but i limited it to 2 blocks because the erasing process takes too long ( 2/3 minutes for both blocks ).

I know that i could use a faster clock to increase the instruction's speed and erasing process, but i'm working with the internal clock of a 16F88.

Is there a way i can speed a bit more via software ? Maybe a diferent code/set of instructions that work a bit better ?

Thanks

skimask
- 12th February 2008, 04:43
I could use more memory blocks and increase the project's performance but i limited it to 2 blocks because the erasing process takes too long ( 2/3 minutes for both blocks ).
I know that i could use a faster clock to increase the instruction's speed and erasing process, but i'm working with the internal clock of a 16F88.
Is there a way i can speed a bit more via software ? Maybe a diferent code/set of instructions that work a bit better ?
Thanks

Post your code. 2-3 minutes is entirely TOO LONG! :) There has to be something silly going on that's causing it to take sooooo long.

sayzer
- 12th February 2008, 09:58
By "block" do you mean the "page" feature of external eeproms?

If so, page write takes about the same time as writing a single byte. Should be somewhere between 2ms to 10ms depending on the eeprom you are using.

It seems that your block writing routine is not really accuate.

-------------------

ruijc
- 12th February 2008, 10:54
Hello sayzer,

i dont mean page.

When i say block it means that i'm using an area of memory for one record session and other area for a diferent record session.

For example...

Using memory address from 0 to 3000 will be used as "block" 1 or record session #1 and memory address 3500 to 6500 will be used as "block" 2 or session #2.

The user will choose ( using a button ) where it will record ( either block 1 or 2 ) and the same concept is used when reading back data.

I'm using a 16F88 pic with internal osc and a 24LC512 external eeprom.
The program works very well except the erasing rotine ( note that i'm erasing all blocks at the same time ).

With 2 blocks it erases in an acceptable time frame...but i would like to use more blocks without loosing too much time erasing them all.

Dave
- 12th February 2008, 13:14
ruijc, But why are you required to erase all of the data? Why not just keep a couple of pointers? 1 for number of data bytes recorded and 1 for the next data location. The reason for 2 is to verify if either is corrupted. Just update the 2 pointers when writing the data or clear them when you require a memory clear function.

Dave Purola,
N8NTA

ruijc
- 12th February 2008, 14:56
Hello Dave,

Very interesting idea.

It makes perfect sense. It's a completly diferent logic this way.

Thanks ;)

What i thought was:

I can reserve 4 bytes ( using 2 blocks of data...reserve more with more blocks ) of memory such as:

1 will record the starting address for first block
1 will record the ending point for the first block
1 will record the starting point of second block
1 will record the ending address of second block

This way i can have variable size of block with data:)

These can be stored either in the external or internal eeprom ( i guess it will be safer to store them in the external one )

For reading it will lookup these bytes for it to know where to start colecting data and where to stop.

To erase just simply put these to 0 ( reminding to check for 0 before start recording ).


I think it can work this way, dont you think ?



.

Dave
- 12th February 2008, 16:11
ruijc, Bygolly youv'e got it....... I have used this same method for about 3 years or so using 4 24LC1025's for data storage of depth, temperature, diveplane angle, and status at 1 second intervals for about 18 hours on my TempTracker.

Dave Purola,
N8NTA

sayzer
- 12th February 2008, 17:02
So what Dave is suggesting is like a partition table.

Instead of erasing all data, just erase or clear partition table.

If the partition table is empty, the data is not accessible or is useless.

--------------

ruijc
- 13th February 2008, 11:11
This way i can "erase" alot of blocks of data in a ms and also safely read only what i recorded in the previous session and not mix up data from previous recordings.