write to EEPROM and interrupt


Closed Thread
Results 1 to 8 of 8
  1. #1
    micro's Avatar
    micro Guest

    Default write to EEPROM and interrupt

    i use external interrupt in my programm, and i want to use WRITE command
    but i must turn interrupt off or mask it before use WRITE command.
    so, how can i do that?? should i put WRITE command at the beginning of the software? i mean before Main loop, or is there any simple methode to do it ??

    pic16f84


    WRITE_PRO:
    ---
    ----
    WRITE 3,4
    ---
    --
    goto WRITE_PRO

    OPTION_REG =%11000000
    INTCON =%10010000
    ON INTERRUPT GOTO INT

    MAIN:
    ---
    ----
    GOTO MAIN

    Did i do the right or the wrong ??? because i want to put WRITE_PRO at any posion not at the beginning as i did

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The position in the program will not have any bearing on how WRITE operates. Put it wherever you want it.

    If an interrupt occurs in the middle of a WRITE sequence, it can cause the WRITE to fail. But, the interrupt has to happen at just the right time to cause a problem. So turning OFF interrupts everytime isn't always necessary.

    I like to try writing to EEPROM with interrupts turned on, to reduce the possibily of losing other interrupts(10ms is a long time).

    Do the WRITE, then READ it back to see if the WRITE was successful, if not, try again. If interrupts are happening so fast that it fails 3 times in a row. Then turn off the interrupts (INTCON.7 = 0) and write it one last time.

    Unless your interrupts are happening at a very high speed, the write will succeed the first time, 99% of the time or better.
    <br>
    DT

  3. #3
    Join Date
    Mar 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: write to EEPROM and interrupt

    I'm going to try this. Thanks!

    Also, does the same apply to EEPROM reads? I assume a READ instruction can get messed up if the interrupt occurs at just the right time during the READ?

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


    Did you find this post helpful? Yes | No

    Default Re: write to EEPROM and interrupt

    swr999, I have used the "DEFINE WRITE_INT 1" directive with my 18F parts and have had no problems. The READ instructions are not to my knowlege prone to disruption with interrupts enabled.
    Dave Purola,
    N8NTA
    EN82fn

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: write to EEPROM and interrupt

    Quote Originally Posted by Dave View Post
    swr999, I have used the "DEFINE WRITE_INT 1" directive with my 18F parts and have had no problems. The READ instructions are not to my knowlege prone to disruption with interrupts enabled.
    Hi. Is this a PBP3 DEFINE? I don't see this in my PBP 2.60 manual. What does it do?
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  6. #6
    Join Date
    Mar 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: write to EEPROM and interrupt

    Quote Originally Posted by Dave View Post
    swr999, I have used the "DEFINE WRITE_INT 1" directive with my 18F parts and have had no problems. The READ instructions are not to my knowlege prone to disruption with interrupts enabled.
    Thanks Dave. My "issue" is that I have a 10-mS interrupt running to keep track of elapsed time. I have several EEPROM writes and since EEPROM writes take a while I don't want to lose time by stopping the interrupt for every write.

    I did a test program where I repeatedly wrote to EEPROM with a 'random' WORD. For each write I then read back the value that got stored in EEPROM. It turns out that the error rate due to interference from the interrupt was quite low, about 0.04% (~400 errors in a million writes). So what I ended up doing was to do each write with a call to a subroutine:

    EEwriteWord:
    WRITE addr,xW.byte0:WRITE addr+1,xW.byte1
    READ addr,xR.byte0: READ addr+1,xR.byte1
    IF xR != xW then
    INTCON.7=0
    WRITE addr,xW.byte0:WRITE addr+1,xW.byte1
    INTCON.7=1
    ENDIF
    RETURN

    This seems to be working well. While the EEPROM write takes several mS the READ is pretty fast, so this doesn't add too much overhead.

  7. #7
    Join Date
    Mar 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: write to EEPROM and interrupt

    Quote Originally Posted by rsocor01 View Post
    Hi. Is this a PBP3 DEFINE? I don't see this in my PBP 2.60 manual. What does it do?
    DEFINE WRITE_INT 1 is used to avoid write errors during a WRITE to EEPROM which might otherwise possibly be caused by an interrupt occurring during the write. The functionality is that it disables interrupts just prior to executing a WRITE instruction, and re-enabls interrupts after the WRITE completes. Appears to be strictly a PBP3 feature.

  8. #8
    Join Date
    Mar 2008
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: write to EEPROM and interrupt

    With regard to the "DEFINE WRITE_INT 1" directive, it appears to be available at least from PBP 2.50 onwards. I misspoke above^^^. Apologies.

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 03:35
  2. Replies: 5
    Last Post: - 29th May 2008, 19:03
  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, 15:19
  4. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 19:14
  5. WRITE TO Eeprom
    By crhomberg in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 12th February 2008, 05:33

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