Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

WDT with PIC16F877A

Status
Not open for further replies.
You read the 16F877A datasheet.

Seriously. What language are you using ?

Regardless of that you need to do two things.

You need to enable it in your processor config.
Optionaly you can change the prescaler which determines how long it takes to time out.
You need to reset it in you main code loop to keep it from reseting the processor.
 
Gaud, its a hard life, the <2 posters have sooo little patience (from one with sooo much experience ;-).
 
Use of WDT in PIC16F877A

Hi,
I want to know that when watch dog timer is used in PIC16F877A on reset the control goes to 0000th location and starts executing from that location reseting all the variables. If the code gets hang up then I want the control to get back to previous location executed without damaging the variables stroed in RAM location. I dont want the control to start from 0000th location.

I want to know if this is possible, kindly reply.
 
The idea behind the watchdog timer is that it does a clean system restart. You can not change this.

Maybe you should look into using a different timer that you check in your main loop. If the timer has expired restart you application with the vars left in place.

Or you could store your information in EEPROM on FLASH memory and restore it on restart.

Hi,
I want to know that when watch dog timer is used in PIC16F877A on reset the control goes to 0000th location and starts executing from that location reseting all the variables. If the code gets hang up then I want the control to get back to previous location executed without damaging the variables stroed in RAM location. I dont want the control to start from 0000th location.

I want to know if this is possible, kindly reply.
 
Yes, the whole point of a WD is a total restart. You then code critical process paramaters into eeprom on a regular basis in advance, and point to a different start address on reset if required, reloading these pre-stored parameters. A WD restart by definition is 0000, a readdress can be applied directly after. A WD restart must be this way, or you could just get stuck in the same code loop that triggered the WD timer in the 1st place.
 
You need to read the datasheet - on modern PIC's a WDT timeout, while the PIC is in sleep, restarts immediately following the sleep instruction. I found this out after struggling for ages trying to detect what had caused a hardware reset, an actual reset, or a WDT timeout - as you did on the older devices - when in fact the PIC wasn't doing a reset, just carrying on from where it was.
 
In the way Nigel suggests, the WDT can be used as a crude timer, and not resort back to ORG 0. Like put Pic to sleep wait for X period of time, then do something, and go back to sleep. You could keep track of much longer periods of time by inserting a counter where the NOP is, and keeping track of that. In GCBasic:

Code:
#chip 16f690,8
#config Osc=INTRC_OSC_NOCLKOUT  

#define LED1 PortC.0
dir LED1 out
;Set max prescaler 1:65536 WDTCON = b'10110' 
;Set shared TMR0 Prescaler to 128 and assign
;to the wdt here OPTION_REG = b'xxxx1111'
;This gives a wdt of 268 sec
OPTION_REG = OPTION_REG OR b'00001111'
WDTCON = b'10010'  ;try for 67 sec 

Main:
Set LED1 ON
wait 1 s
Set LED1 Off
SWDTEN = 1  ;turn on WDTCON,0 bit on
asm sleep
nop  ;sleep executes the next instruction
SWDTEN = 0
goto main
 
In the way Nigel suggests, the WDT can be used as a crude timer, and not resort back to ORG 0. Like put Pic to sleep wait for X period of time, then do something, and go back to sleep. You could keep track of much longer periods of time by inserting a counter where the NOP is, and keeping track of that.

My particular application was intended to wake up and transmit an IR code at specific intervals - with no great accuracy required. I used a DIL switch on one of the ports, and that was used to set the number of WDT wakeups required before the code was transmitted. I think maximum time is about 2.5 seconds, so I could set it from 2.5 seconds to 40 seconds with a 4 pin switch.
 
My particular application was intended to wake up and transmit an IR code at specific intervals - with no great accuracy required. I used a DIL switch on one of the ports, and that was used to set the number of WDT wakeups required before the code was transmitted. I think maximum time is about 2.5 seconds, so I could set it from 2.5 seconds to 40 seconds with a 4 pin switch.
Well now, there is something practical:), very nice.

The max WDT of 268 sec (or thereabouts), was a surprise of the newer midrange PIC's.
 
This would make an interesting topic for JPUG. Hopefully I'll have time over the holidays to do a couple of articles. WDT & Interrupts are always interesting topics.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top