16F628 Data EEPROM Write Problem

Started by Scott Kellish January 14, 2004
 
Hi Everyone,
I'm having some intermittent problems writing to the data eeprom on 16F628 parts. Below is the code I'm using. Once in a while, probably on the order of one in 2-3000 writes I'll get a write failure which is when the data read back after a write does not match what was written. There is decoupling caps at the chip and the supply looks solid. I'd appreciate it if anyone could point out any problems with the following code.
 
Thanks
Scott

 
 
; IN:   NVMADDR = ADDRESS TO WRITE
;       W       = DATA TO WRITE
;
WRITENVM    BSF     STATUS, RP0                     ; BANK 1
            MOVWF   _NVMDATA                        ; SAVE NEW BYTE
 
; GET CURRENT VALUE
            MOVF    _NVMADDR, W                     ; GET CURRENT VALUE
            MOVWF   EEADR
            BSF     EECON1, RD
            MOVF    EEDATA, W
            XORWF   _NVMDATA, W                     ; SAME AS CURRENT VALUE?
            BZ      WRITENVMDONE                    ; YES, NO NEED TO CONTINUE
            MOVF    EEDATA, W
            MOVWF   _OLDNVMDATA                     ; SAVE CURRENT VALUE
 
; NEW VALUE DIFFERENT THEN CURRENT, REPLACE
            MOVF    _NVMDATA, W                     ; NEW DATA
            CALL    WRITENVMBYTE                    ; WRITE TO NVM
            SKPZ 
            RETURN                                  ; WRITE FAILED
            BSF     STATUS, RP0
        
; GET CURRENT CHECKSUM VALUE
            MOVLW   LOW NVM_CHECKSUM                ; CHECKSUM LOCATION
            MOVWF   EEADR
            BSF     EECON1, RD
            MOVF    EEDATA, W                       ; READ CURRENT CHECKSUM
            SUBWF   _OLDNVMDATA, F                  ; SUBTRACT OUT ORIGINAL VALUE
            NEGF    _OLDNVMDATA, W
            ADDWF   _NVMDATA, W                     ; ADD IN NEW VALUE AND WRITE UPDATE CHECKSUM BACK
            MOVWF   EEDATA
            B       WRITENVMBYTE1
 
; WRITE & VERIFY BYTE TO NVM LOCATION
WRITENVMBYTE 
            BSF     STATUS, RP0                     ; BANK 1
            MOVWF   EEDATA                          ; DATA TO WRITE
            MOVF    _NVMADDR, W                     ; GET CURRENT VALUE
            MOVWF   EEADR
            BCF     INTCON, GIE                     ; DISABLE INTERRUPTS
WRITENVMBYTE1  
            BSF     EECON1, WREN                    ; ENABLE WRITE MOD
            MOVLW   55H
            MOVWF   EECON2
            MOVLW   0AAH
            MOVWF   EECON2                          ; UNLOCK
            BSF     EECON1, WR                      ; START WRITE CYCLE
            BSF     INTCON, GIE                     ; RE_ENABLER INT'S
            MOVF    EEDATA, W
WRITENVMBYTE2  
            CLRWDT                                  ; FEED DOG WHILE WE WAIT
            BTFSC   EECON1, WR                      ; WRITE DONE?
            B       WRITENVMBYTE2                   ; NO.
        
; WRITE COMPLETE, READ BACK TO VERIFY
            BCF     EECON1, WREN                    ; DISABLE WRITE MODE
            BSF     EECON1, RD                      ; LATCH DATA FOR READ
            SUBWF   EEDATA, W                       ; READ = WRITTEN?
WRITENVMDONE 
            BCF     STATUS, RP0
            RETURN
 
READNVM     BSF     STATUS, RP0                     ; BANK 1
            MOVWF   EEADR                           ; ADDRESS TO READ
            BSF     EECON1, RD                      ; LATCH READ DATA
            MOVF    EEDATA, W                       ; READ DATA
            BCF     STATUS, RP0                     ; BANK 0
            RETURN
 
 
 
__________________________________________
MavenWare SoftSystem Solutions
18 Ridge Road
Clark, New Jersey 07066 USA
Scott Kellish, Owner
Tel.      +01 732 382 1873
Fax:     +01 732 382 1873
Mobile: +01 732 261-5856
e-mail:  s...@comcast.net
__________________________________________




----- Original Message -----
From: "Scott Kellish" <>
To: "PICLIST" <>
Sent: Wednesday, January 14, 2004 2:15 AM
Subject: [piclist] 16F628 Data EEPROM Write Problem
Hi Everyone,
I'm having some intermittent problems writing to the data eeprom on 16F628
parts. Below is the code I'm using. Once in a while, probably on the order
of one in 2-3000 writes I'll get a write failure which is when the data read
back after a write does not match what was written. There is decoupling caps
at the chip and the supply looks solid. I'd appreciate it if anyone could
point out any problems with the following code.

Have you tried a battery supply? It might be something getting in via the
mains.

Leon
--
Leon Heller, G1HSM
Email:
My low-cost Philips LPC210x ARM development system:
http://webspace.webring.com/people/jl/leon_heller//lpc2104.html



Thanks,
This is a finished design already in the field. I posed the question about
the supply stability to my EE counterpart and he feels its ok with ample
decoupling caps, but he's going to take a look at it again. I just want to
make sure that I'm not violating some timing constraint or sequencing with
my code.

Scott

>
> ----- Original Message -----
> From: "Scott Kellish" <>
> To: "PICLIST" <>
> Sent: Wednesday, January 14, 2004 2:15 AM
> Subject: [piclist] 16F628 Data EEPROM Write Problem >
> Hi Everyone,
> I'm having some intermittent problems writing to the data eeprom on 16F628
> parts. Below is the code I'm using. Once in a while, probably on the order
> of one in 2-3000 writes I'll get a write failure which is when the data
read
> back after a write does not match what was written. There is decoupling
caps
> at the chip and the supply looks solid. I'd appreciate it if anyone could
> point out any problems with the following code.
>
> Have you tried a battery supply? It might be something getting in via the
> mains.
>
> Leon
> --
> Leon Heller, G1HSM
> Email:
> My low-cost Philips LPC210x ARM development system:
> http://webspace.webring.com/people/jl/leon_heller//lpc2104.html
>
> to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
>
>




--- In , "Scott Kellish" <skellish@c...> wrote:
>
> Hi Everyone,
> I'm having some intermittent problems writing to the data eeprom on
16F628 parts. Below is the code I'm using.

If you are using the 16F628A there is a silicon errata on data EEPROM
writes. It looks like uChip wants you to change to interrupt driven
writing and to execute a SLEEP immediately after the "BSF EECON1,
WR". I know you say you are using the non-A part and it doesn't look
like the non-A part has the issue but I mention it because maybe you
failed to properly specify the part you are using.

As for the code, you do not have global interrupts disabled when you
are writing your checksum -- that's dangerous as interrupt code may
disturb the required instruction sequence during this operation.
Move the "WRITENVMBYTE1" label up one line so it is before the "BCF
INTCON, GIE" line. From your description, I doubt this is the
problem you are experiencing but it is a potential source of problems.

--Scott