News:

;) This forum is the property of Proton software developers

Main Menu

how to use WDT with 12F675?

Started by hitronics, Apr 09, 2022, 01:27 AM

Previous topic - Next topic

hitronics

Hi, Guys
I am very new to use WDT with pic microcontrollers
is there any example to use it with proton?
all your efforts are appreciated

GDeSantis

I don't have a PIC12F675; but comments regarding a program for the PIC12F1572 are as follows:

The Watchdog Timer (WDT) is a system timer that generates a reset if your program does not reset the WDT within an allocated time-out period. The WDT is generally used to force a reset if your system "hangs" due to an unexpected event. 

The PIC12F1572 WDT derives its time base from its 31 KHz LFINTOSC internal oscillator.  The oscillator is independent of the main MCU clock oscillator and WDT time intervals are approximately multiples of one millisecond.

In the attached program, the WDT is enabled and configured for a timing interval of 4096 LFINTOSC clock cycles or approximately 132 mSec.   Since the program does not reset the WDT, the MCU periodically resets due to a WDT time-out.

Using an oscilloscope, the reset can be observed by noting the voltage across the LED  momentarily drops to zero every 136mSec.   

hitronics

Quote from: GDeSantis on Apr 09, 2022, 06:18 PMI don't have a PIC12F675; but comments regarding a program for the PIC12F1572 are as follows:

The Watchdog Timer (WDT) is a system timer that generates a reset if your program does not reset the WDT within an allocated time-out period. The WDT is generally used to force a reset if your system "hangs" due to an unexpected event. 

The PIC12F1572 WDT derives its time base from its 31 KHz LFINTOSC internal oscillator.  The oscillator is independent of the main MCU clock oscillator and WDT time intervals are approximately multiples of one millisecond.

In the attached program, the WDT is enabled and configured for a timing interval of 4096 LFINTOSC clock cycles or approximately 132 mSec.  Since the program does not reset the WDT, the MCU periodically resets due to a WDT time-out.

Using an oscilloscope, the reset can be observed by noting the voltage across the LED  momentarily drops to zero every 136mSec.   


as I see on Proton Compiler Manual that need to:
Declare Watchdog = On

then my question is how not let WDT in your code triggered?

Yves

If you don't really requires WDT just turn it off. Myself I always have it off as I never really understood what WDT is useful for. If your code tend to hang it means there is something not quite right with your coding. If you need some timing use timer0 or other in interrupt.

Yves 
Yves

hitronics

Quote from: Yves on Apr 09, 2022, 09:28 PMIf you don't really requires WDT just turn it off. Myself I always have it off as I never really understood what WDT is useful for. If your code tend to hang it means there is something not quite right with your coding. If you need some timing use timer0 or other in interrupt.

Yves 

sometimes microcontroller hang because it is near to some noise from motors or ac appliances so it is very important to use WDT

John Drew

WDT is very important in many situations. I use PICs in repeater controllers, devices that sit on hilltops connected to high antennas. It's a noisy environment on occasions with the build up of high potentials from rain etc. Not to mention possible lightning strikes nearby on other towers. The antennas are earthed but EM or electrical pulses still find their way to the equipment and can cause temporary disruption that can be overcome with a reset.
In answer to your question. You reset the WDT by scattering CLRWDT instructions in your code. e.g put a CLRWDT inside any loops of significant length or at least in your main loop.
I always make the WDT timer as long as possible because it's non commercial but it saves me long drives to the site.
Has it actually fired on any site? I have no idea. That's the whole point, it's an on site finger on the power switch :)
John

hitronics

@John Drew

dear, john do you have an example for 12F675 to let WDT trig after few millisecond to do some testing?

Stephen Moss

Quote from: hitronics on Apr 09, 2022, 08:33 PMas I see on Proton Compiler Manual that need to:
Declare Watchdog = On
Alternatively just set the WDT enable configuration fuse.

Quote from: hitronics on Apr 10, 2022, 03:56 PMdo you have an example for 12F675 to let WDT trig after few millisecond to do some testing?
If you look at section 9.6 of the data sheet you will see how long the WDT runs for, you can increase that using the Prescaller to extend up to 128 time longer a little over 2 seconds depending on what value you assign to the prescaller (see Options Regsiter on page 12).

For testing you could simply connect an LED and a 330 ohm resistor between an output pin and ground, set the output high to turn the LED on. If you do not clear the WDT it will eventaully trigger with should briefly turn the LED off as a result fo the WDT reset, if you create a main loop and clear the WDT within it then provided it does not take longer for your mail loop to execute that the WDT reset time then LED will remain on as ther is not WDT reset to turn it off.