Internal eeprom - erase block


Closed Thread
Results 1 to 33 of 33
  1. #1

    Default Internal eeprom - erase block

    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
    .

  2. #2
    Join Date
    Dec 2007
    Location
    Denmark
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Dec 2007
    Location
    Denmark
    Posts
    28


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Check this one.
    Modify as needed.


    Code:
    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.
    Last edited by sayzer; - 27th December 2007 at 17:08. Reason: edited code with minor modification....
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5


    Did you find this post helpful? Yes | No

    Default

    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.

    .

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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".
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7


    Did you find this post helpful? Yes | No

    Default

    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
    .

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ruijc View Post
    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.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    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

  11. #11
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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?


    ----------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  12. #12


    Did you find this post helpful? Yes | No

    Default No contradictions - High & Standard endurance blocks

    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

  13. #13
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BrianT View Post
    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!



    ---------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  14. #14
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Default read eeprom problem

    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

  15. #15
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Try this for grins, same thing but different...

    Code:
    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.

  16. #16
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Unhappy i'll try

    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...

  17. #17
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Use a STOP or an endless loop before the END statement.
    Code:
            pause 2000
            lcdout $fe,1,"Successful!"
    Here:   GOTO Here 
    end
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  18. #18
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Default thanks

    Thanks steve.
    I'll try this.

  19. #19
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Unhappy Still won't work

    Hi Steve!

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

  20. #20
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Default error in my code

    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.

  21. #21
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ria_river View Post
    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.
    Last edited by skimask; - 19th January 2008 at 08:15.

  22. #22
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Smile I see

    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.

  23. #23
    Join Date
    Nov 2007
    Location
    Cebu, Philippines
    Posts
    14


    Did you find this post helpful? Yes | No

    Post me again

    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.

  24. #24
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ria_river View Post
    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?

  25. #25


    Did you find this post helpful? Yes | No

    Default

    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

  26. #26
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ruijc View Post
    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.

  27. #27
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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.

    -------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  28. #28


    Did you find this post helpful? Yes | No

    Default

    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.

  29. #29
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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

  30. #30


    Did you find this post helpful? Yes | No

    Default

    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 ?



    .

  31. #31
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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

  32. #32
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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.

    --------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  33. #33


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 15:46
  2. config bits
    By brianD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th February 2010, 14:45
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 01:55
  4. PortE problems (PIC18F4455)
    By RubenR in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 12th July 2006, 16:26
  5. Internal EEPROM Read/write Addressing Errors with 18F PIC's
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 18
    Last Post: - 12th July 2005, 20:42

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts