PDA

View Full Version : EEPROM Write command with interrupts??



Elnino
- 23rd November 2009, 04:15
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'?

Darrel Taylor
- 23rd November 2009, 05:26
If you are using PBP 2.50 or later there is a define that handles that for you ...
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.
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.

Elnino
- 23rd November 2009, 05:47
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


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?

Darrel Taylor
- 23rd November 2009, 06:11
... 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>

Elnino
- 23rd November 2009, 06:44
Excellent, thanks Darrel, keep up the good work!