WRITE prob during power cycle 18f6722
latest versions, 18f6722, pickit 2
ok, heres the deal. Everything is hunky doory until you switch the machine off and on again, It somtimes will write to the eeprom when it shouldn't.
So I looked at the datasheet and theres several things on this prob. It talks about "WREN" and here at this forum I found this
ASM
bsf EECON1, WR
nop
bcf EECON1, WREN
endasm
the datasheet also talked about several other things so i put them in my inc file
NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F6722, r = dec, w = -311, w = -230, f = inhx32
INCLUDE "P18F6722.INC" ; MPASM Header
__CONFIG _CONFIG1H, _OSC_HS_1H ; _OSC_XT_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_NOSLP_2L & _BORV_1_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
NOLIST
endif
LIST
EEPROM_START EQU 0F00000h
BLOCK_SIZE EQU 64
Strangly enough I had the same issue with another project and fixed it by getting rid of the power capacitor.
the WREN I dont really understand, I prefer basic ver asm. can someone help me out here to understand this a bit.
Brown-out or somthing like that
I have brown-out on and i have tried several settings, but it dosn't help. I believe I need to use WREN and write together. Heres a direct quote from the datasheet.
"There are conditions when the device may not want to
write to the data EEPROM memory. To protect against
spurious EEPROM writes, various mechanisms have
been implemented. On power-up, the WREN bit is
cleared. In addition, writes to the EEPROM are blocked
during the Power-up Timer period (TPWRT,
parameter 33).
The write initiate sequence and the WREN bit together
help prevent an accidental write during brown-out,
power glitch or software malfunction."
I believe this is exactly what I need. But its all in ASM.
CLRF EEADR ; Start at address 0
CLRF EEADRH ;
BCF EECON1, CFGS ; Set for memory
BCF EECON1, EEPGD ; Set for Data EEPROM
BCF INTCON, GIE ; Disable interrupts
BSF EECON1, WREN ; Enable writes
Loop ; Loop to refresh array
BSF EECON1, RD ; Read current address
MOVLW 55h ;
MOVWF EECON2 ; Write 55h
MOVLW 0AAh ;
MOVWF EECON2 ; Write 0AAh
BSF EECON1, WR ; Set WR bit to begin write
BTFSC EECON1, WR ; Wait for write to complete
BRA $-2
INCFSZ EEADR, F ; Increment address
BRA LOOP ; Not zero, do it again
INCFSZ EEADRH, F ; Increment the high address
BRA LOOP ; Not zero, do it again
BCF EECON1, WREN ; Disable writes
BSF INTCON, GIE ; Enable interrupts
The question is how do I only write my two Variables to eeprom if all is well (within voltage range). One of these variables is a byte and the other is a word.
As to your questions, This is a modification of a machine. I can't remove any capacitors from the power supply like i could in the other project that had the same issue. I would like to resolve this problem once and for all, not for just this project but also for all projects to come.
I do write to the eeprom. but i do not want to write if the system is powering down or up.
Thank you for your time....
I Believe my prob is.....
The machine I am modifying sends a signal at power down not when powering up(I have a "pause 2000" when powering up). This signal is a glitch. And I do not want to record this signal. It is not always there otherwise I would just subtract it from the total at power up.
So I'm trying to figure a way to not record this if the voltage is under, lets say 4.5v. The power supply is 5v, so anything under 4.5 would mean it is powering down. It may need to be a bit higher but I'm not sure.
I kind of thought that was what Brown-out was for, but it dosn't seem to be doing any good.
I put a loop with a variable to help this problem, and it has cut back alot of the false writes.
TOTALTEMP=TOTALTEMP+1
IF TOTALTEMP>200 THEN
READ 8,MONEY
IF MONEY <> CREDIT THEN
WRITE 8,CREDIT
GOSUB WRTOTAL
TOTALTEMP=0
ELSE
ENDIF
TOTALTEMP=0
ELSE
ENDIF
But it still dose a false write every once in awhile, before it was almost every shutdown.
Also, There is no battery backup. when this machine shuts down, the pic also is shutting down. however the pic can run as low as I think 2 volts. so any false readings from a pin could cause the pic to write and I dont want to.
And the price goes up.......
this is to be fabricated by the hundreds, price is an issue.
What about the onboard "HLVD"
But then again its all in ASM. It talks about these steps
1. Write the value to the HLVDL3:HLVDL0 bits that
selects the desired HLVD trip point.
2. Set the VDIRMAG bit to detect high voltage
(VDIRMAG = 1) or low voltage (VDIRMAG = 0).
3. Enable the HLVD module by setting the
HLVDEN bit.
4. Clear the HLVD interrupt flag (PIR2<2>), which
may have been set from a previous interrupt.
5. Enable the HLVD interrupt if interrupts are
desired by setting the HLVDIE and GIE bits
(PIE2<2> and INTCON<7>). An interrupt will not
be generated until the IRVST bit is set.
How do I write these values that it needs. Can I do it in PicBasic pro?
PBP to use the HLVD but one statement doesn't execute??
Quote:
Originally Posted by
jason
this is to be fabricated by the hundreds, price is an issue.
What about the onboard "HLVD"
But then again its all in ASM. It talks about these steps
1. Write the value to the HLVDL3:HLVDL0 bits that
selects the desired HLVD trip point.
2. Set the VDIRMAG bit to detect high voltage
(VDIRMAG = 1) or low voltage (VDIRMAG = 0).
3. Enable the HLVD module by setting the
HLVDEN bit.
4. Clear the HLVD interrupt flag (PIR2<2>), which
may have been set from a previous interrupt.
5. Enable the HLVD interrupt if interrupts are
desired by setting the HLVDIE and GIE bits
(PIE2<2> and INTCON<7>). An interrupt will not
be generated until the IRVST bit is set.
How do I write these values that it needs. Can I do it in PicBasic pro?
I have been working with the onboard HLVD module in a 18F4550 to use it as a low voltage monitor for my application. I am posting my current PBP code below that is suppose to do steps 1-5 you list above that are called out in the Data Sheet. I am prettry sure this is the right code, but it wasn't working, so I ran an ICD on it and discovered that when it gets to this procedure which is located in my main program loop, the first HLVDCON statement executes to clear HLVDCON.4, however the next statement (HLVDCON = %00011101) which is suppose to perform steps 1-3 in your above listing, doesn't execute....nor do any of the remaining statements in this process block execute...instead the program always jumps to an Interrupt Service Routine that is suppose to service a DT_INTS-18 interrupt triggered by a real-time clock. However the RTC interrupt isn't timed to happen when this happens. I can't figure out why this this HLVDCON statement is not executing and the rest of this block is not executing in the main loop before the interrupt happens.
Can anyone advise me what is happening here and how to fix it??
Code:
' Test for low battery conditon
' Set registers for using HLVD feature
HLVDCON.4 = 0 'Disable the module by clearing HLVDCON.4
' Set the trip point at Vdd=4.4 vdc by setting HLVD3:HLVDL0=1101
' Set VDIRMAG=0 (HLVDCON.7) to detect low voltage transition
' Enable the HLVD module (HLVDCON.4=1)
HLVDCON = %00011101
' Clear the HLVDIF interrupt flage (PIR2<2>)
PIR2.2 = 0
' Enable the HLVD interrupt
PIE2.2 = 1
INTCON.7 = 1
' Set IRVST bit (HLVDCON.5 =1) to allow interrupt generation
HLVDCON.5 =1
If PIR2.2 =1 THEN ' Test for HLVD interrupt (HLVDIF bit = 1)
For I = 0 TO 4 ' Blink the RED LED 5X as low battery warning
High LED_RED
Pause 500
LOW LED_RED
pause 500
next
ENDIF