Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC Watchdog Timer - EEPROM problem

Status
Not open for further replies.

mfacen

Member level 1
Joined
Feb 24, 2005
Messages
35
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,765
watchdog pic eprom

I'm designing a entry lock system based on a PIC16F84. The system is working fine but once every few months or so it blocks, I think is due to interference in the mains. I tryied to start using the Watch Dog Timer to reset the microcontroller if it stalls but it resets the chip everytime it tryies to write a new code into the EEPROM even if I use the prescaler to the maximum. I use the EEPROM to store the codes.
Any idea what is causing the Watchdog to reset the chip ? I even used CLRWDT right at the begin of the eeprom write rutine .
 

pic24 watchdog

Hi,

if you have assigned the prescaler to timer0 you can not assign the prescaler also to the watchdog maybe this is your problem??

I have attached the EEPROM_write function (programmed in C) I am using on the 16F877 maybe you see something that is missing in your routine??

void EEPROM_write(byte adresse, byte daten)
{
EEPGD=0;

do
{
asm("clrwdt");
}
while(WR);

EEADR=adresse;
EEDATA=daten;
WREN=1;
GIE=0;
EECON2=0x55;
EECON2=0xAA;
WR=1;
GIE=1;
WREN=0;
}

best regards
 

pic watchdog 16f877 timer prescaler

Thanks C-Man for the FAST response !!!

I'm not using TMR0 on the program. I program directly in assembler with MPLAB. I'm assigning the presacaler to the wdt:

__config _xt_osc & _wdt_on & _pwrte_on & _cp_off
bcf option_reg,psa


And this is the eeprom write rutine:

eewrite
clrwdt
bsf status,rp0
bcf eecon1,eeif
bsf eecon1,wren
bcf intcon,gie

movlw h'55'
movwf eecon2
movlw h'aa'
movwf eecon2
bsf eecon1,wr

notyet
btfss eecon1,eeif
clrwdt
goto notyet
bcf eecon1,eeif
bcf eecon1,wren
bsf intcon,gie
bcf status,rp0
return



The program works fine in all the rest of the rutines, is just when I enter a new code on the keypad that it resets. If I don't use the wdt it writes to the eeprom without problems.

Thanks for the help.
 

pic16f 128 lock

What about this??

notyet
clrwdt
btfss eecon1,eeif
goto notyet


Otherwise you are trapped inside the waitloop without resetting the watchdog as soon as eeif is set ...

best regards
 

problem option_reg

I forgot to post this:

bcf option_reg,ps2 ;ps2 of psa
bcf option_reg,ps1 ;ps1 of psa
bcf option_reg,ps0 ;ps0 of psa

I'm using the maximun prescaler (1:128) for the WDT, that should give plenty of time for the write operation, in the 16F84 datasheet there is a graphic that states for 5 volts VDD the write time of the EEPROM is just over 5ms, the wdt should reset every 18ms x 128 = 2304 ms. Thats a lot of time for the write operation !!!

Added after 3 minutes:

sorry, I posted a cut & paste from my program as is running now ( prescaler=1 )

I've already tried this:

bsf option_reg,ps2 ;ps2 of psa
bsf option_reg,ps1 ;ps1 of psa
bsf option_reg,ps0 ;ps0 of psa

(prescaler = 128)

Added after 2 minutes:

Ah ok, I don't remember if I already tried that, I think I did but not for shure.

Now is 2 in the morning here and my wife is going to killme if I start taking apart the lock, I'll try that tomorrow and let you know.

Thanks...
 

mfacen said:
I forgot to post this:

bcf option_reg,ps2 ;ps2 of psa
bcf option_reg,ps1 ;ps1 of psa
bcf option_reg,ps0 ;ps0 of psa

I'm using the maximun prescaler (1:128) for the WDT, that should give plenty of time for the write operation, in the 16F84 datasheet there is a graphic that states for 5 volts VDD the write time of the EEPROM is just over 5ms, the wdt should reset every 18ms x 128 = 2304 ms. Thats a lot of time for the write operation !!!

Added after 3 minutes:

sorry, I posted a cut & paste from my program as is running now ( prescaler=1 )

I've already tried this:

bsf option_reg,ps2 ;ps2 of psa
bsf option_reg,ps1 ;ps1 of psa
bsf option_reg,ps0 ;ps0 of psa

(prescaler = 128)

You misunderstood my answer please look at it again.

Your routine resets the watchdog as long as eeif is not set but as soon as it is set it does not reset the watchdog any more but still loops (until the no more triggered watchdog resets your PIC)!!!

Also look again at the datasheet if you want to have maximum prescaler you will have to set psa to assign the prescaler to the watchdog.

best regards
 

Yes you are right, I've cut and pasted from the program as it is working now, my mistake. As I couldn't make it work I tried lots of different things and messed it up. I'm not calling anymore the write eeprom rutine and I'm just using the lock with the codes I programmed when I burned the program in the PIC.
I'll get out the PIC from the lock tomorrow and go trough the program again.

Regards...
 

Ok C-man, the &%&&%$$% thing is working now.

The problem was the one you pointed out.
I can belive I spent weeks writing the program and then fail in such a stupid thing !!!! Well, you learn from your mistakes right ?

Thanks for the help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top