Bad Eeprom write on '628???


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2006
    Posts
    22

    Default Bad Eeprom write on '628???

    Hi:
    I am trying to save PORTB pin status on Power On Reset, then when power is restored the data will be the same there is my code:

    start:
    trisb=0
    gosub update ' restore last portb value

    mainlop:
    portb = portb +1
    gosub store_val 'update the value on rb to eeprom
    pause 1000
    goto mainlop


    update:
    read 0,last_val
    PORTB= last_val
    return

    store_val:
    last_val=portb
    write 0,last_val
    pause 10
    return

    is too simple, it means a loop where the portb is incremented once each second and then save the status on eeprom, but it doesn't work !
    when I remove the power then I restore, th leds atached to the port b is a number different to the I can remember when the pic is shut off!

    Ovbiously I init the eeprom data with a number before taht the pic can run on first time!
    What I doing Wrong?
    Thanks!

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    You should not write to the EEPROM every second. The number of writes is limited if you know. Ideally, if you need to save, you should save only if there is a change in status of the port. This will reduce the number of writes.

    This looks like a test program to me. So, please think of your real application. You may not need to update the EEPROM so frequently..

    Jerson

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    1)You haven't declared last_val

    2)If you lose power while writing to the EEPROM your saved value might be corrupt

    3)You most likely will shut off power during the pause 1000 – in this case you would not expect to see the same number when you repower up. Say you had PORTB = 28 when the power went down (during the Pause 1000). 28 should be in the EEPROM. When you reapply power, the number 28 is read back and put on PORTB. a few microseconds later you add 1 to that and display the new value, which you see. Therefore 28 !=29.

    4)Jerson is right – your eeprom is limited in the number of writes – how about detecting the power loss and writing the value to EEPROM before the power drops out?

    5)
    Ovbiously I init the eeprom data with a number before taht the pic can run on first time!
    Not to me, I don't see it in your code.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    Join Date
    Jul 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default but . . .

    Thanks by your comments friends, my real app is simple y try to make a ir (infrared) control box that control 4 relays the only that i need is save the last relays status when a possible reset ocurr!, it ensure that there is no change when the power suply is shut down!

    last_val is a byte sized var, and I do not write a statemment as

    " WRITE 0,1" ;INIT EEPROM

    instead I mod the eeprom data memory in MPlab when i burn the Chips, so
    How I can detect a power loss?, what is then the best way to do this type of things?
    my idea is save the PORTB status ONLY when a new value is reloaded from a an Ir controller, instead each second as the above code is!.

    Thanks Again!

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    >> How I can detect a power loss?

    Lot of ways to do this ... without a schematic or more detail it is hard to say what is best. For moderately low power projects, I place a fast diode between the power supply and VDD. I also place a cap between VDD and GND. I then monitor the voltage from the anode of the diode (also connected to the PIC through a diode) and sense when it goes low (with ADC or Comparators). When it goes low, I shut off everything and write to EEPROM. I size the cap to give me enough time to do this.

    Others might do this differently (like using BOD).
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6
    Join Date
    Jul 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default This is my circuit

    As you can see the schematic is very simple.
    I try to make the changes what you say, view the ADDED.jpg file I think that this may work, today I also make code changes and i try again, let know if the the squematics looks like you say,

    Thanks
    Attached Images Attached Images   

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, 14:46
  2. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  3. PIC16F684 + LCD to use the 256bytes of EEPROM - HELP
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th March 2008, 14:19
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

Members who have read this thread : 0

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