EEPROM Write command with interrupts??


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2009
    Posts
    19

    Default EEPROM Write command with interrupts??

    Hi all, I am using Darrel Taylor's PBP interrupts in my project and i also need to be able to write to the internal EEPROM of my PIC.

    Now, according to the microcode studio help file "If interrupts are used in a program, they must be turned off (masked, not DISABLEd) before executing a WRITE command"

    How do i do this? I am not sure how to 'mask' an interrupt, can i not use '@INT_DISABLE'?

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


    Did you find this post helpful? Yes | No

    Default

    If you are using PBP 2.50 or later there is a define that handles that for you ...
    Code:
    DEFINE WRITE_INT 1
    For PBP versions prior to 2.50 you can disable global interrupts, but this will cause a delay of up to 4 mS during the self-timed write process.
    Code:
    INTCON.7 = 0
    WRITE  ADD, VAL
    INTCON.7 = 1
    Sometimes it's better to just try the WRITE, then READ it back and see if it wrote the correct value, if not ... try again.

    To interfere with the write sequence, an interrupt must occur within a 4-instruction window (4 uS with 4Mhz OSC) while it's setting up the write to EEPROM. That doesn't happen very often, and waiting 4000 uS (4 mS) just to make sure nothing happens in that 4uS can cause you to miss interrupts.
    DT

  3. #3
    Join Date
    Sep 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply Darrel

    I am running PBP 2.50

    The WRITE command will come straight after an interrupt is triggered since it will be from a 'save' button that happens to create an interrupt but the WRITE will not happen within the interrupt itself (unless there is some way to only enable state change interrupts on just specific pins rather than the whole port? I'm new to interrupts)

    i.e
    Code:
          repeat
             LCDOUT $FE, $c0, dec val_calib, "  "
             If btn_up = 0 then
               if val_calib <> 254 then val_calib = val_calib + 1
             endif 
             If btn_dn = 0 then
               if val_calib <> 0 then val_calib = val_calib - 1
             endif
             pause 1
           until btn_menu = 0 'exits menu and saves value to eeprom
           'Write value to eeprom here
    btn_menu is on portb of a 16f628A with port change interrupts enabled.

    If my brain is correctly in gear it should mean that although the interrupt will be processed, it should then process the write command AFTER the interrupt and therefore work ok provided no other interrupts are triggered.

    So, i can try the WRITE then read back/confirm and see what happens but can you be a little more specific on how the DEFINE WRITE_INT works? Does that just effectively cause an interrupt while writing so that no other interrupts can fire at the same time?

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Elnino View Post
    ... can you be a little more specific on how the DEFINE WRITE_INT works?
    With DEFINE WRITE_INT 1, PBP will automatically disable global interrupts during those 4 critical instructions of a WRITE command, then turns them back on during the actual hardware Write to EEPROM.

    That way the WRITE is protected from failure due to interrupts, and interrupts can still happen during a WRITE.

    Since you have PBP 2.50, that's your best way to go.
    <br>
    DT

  5. #5
    Join Date
    Sep 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Excellent, thanks Darrel, keep up the good work!

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