Page 1 of 1

control over WDT timeout

Posted: Fri Jun 14, 2019 5:57 pm
by hackinblack
i have a simple project which mis-uses the watchdog timer in a 12F509 to produce eye-catching warning flashes;my question is how do i get more control other than just enabling the WDT in the config's and ducking for cover :wink: ?
the only forum example was,i think,for a 18F part.adding the 'c code' block threw up errors because the registers are not the same in baseline parts... :oops:
before my flaky internet drops out again ; does anybody have any examples of using a single tact. switch to turn on and off a PIC either off completely or just into power saving sleep (12F509 target powered from button cell)

Re: control over WDT timeout

Posted: Fri Jun 14, 2019 7:48 pm
by hackinblack
specifically adding the following C block

option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler
wdtcon = 0b00000111; //Configure watchdog 1:256 Prescaler, Software Watchdog enabled

produces a C file but wont produce a hex file; throwing the following errors:-

Re: control over WDT timeout

Posted: Sun Jun 16, 2019 11:28 am
by medelec35
Hi hackinblack,
hackinblack wrote:option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler
With Flowcode V7 and above, registers are all in upper case.
Within 12F509 The register you are referring to as option_reg is just called OPTION.
However within 12F509 this register is Write only!
So instead of

Code: Select all

OPTION = OPTION | 0b00001111;
you must use

Code: Select all

OPTION = 0b00001111;
instead
hackinblack wrote:wdtcon = 0b00000111;
The way the values of watchdog timer gets altered is by setting the 3 lower bits of OPTION register as WDTCON does not exist within 12F509.
All this information can be found within the 12F509 datasheet.
You should also add C code block with a command to reset the watchdog timer:

Code: Select all

MX_CLEAR_WATCHDOG;

Use Auto clear watchdog in project options.

I would not recommend using the 12F509, you will be facing several stack and memory issues as this chip is now outdated.
I would recommend using 12F1840 instead as its much superior with heaps more stack and memory and it runs of it's internal oscillator at a maximum speed of 32MHz!

Re: control over WDT timeout

Posted: Thu Jun 20, 2019 4:00 pm
by hackinblack
i quite agree; the newer little PICmicro's are incredible,but these are a tube i already have here...postage here is eye-watering like 15 euros for 1 chip :shock:
the use of upper case is partly what threw me and the differences between 12F and 18F registers;i foolishly tried to change as little as possible to get something going :oops: i actually wanted the WDTtimer to jump in,as it makes a more eye-catching blink.it now functions as intended!
thanks sooo much for the help. next time i may be forced to read the datasheet... :roll:
blinkWDT509.fcfx
(7.13 KiB) Downloaded 268 times

Re: control over WDT timeout

Posted: Thu Jun 20, 2019 4:50 pm
by hackinblack
WDT509sleep.fcfx
(7.29 KiB) Downloaded 257 times
here's the new version; with faster blink rate and sleep woken up by the watchdog timer (i seem to have lost the 'double tap' on the blink though...)
other then removing a 'NOP' at the end of the sleep command;which doesn't seem to do anything...?it seems to work OK.
pity i can't test its current draw; as its running direct from a PICkit2.

Re: control over WDT timeout

Posted: Fri Jun 21, 2019 2:08 pm
by medelec35
At least you are sorted for now?
hackinblack wrote:postage here is eye-watering like 15 euros for 1 chip
Ouch, that does seem very steep!
hackinblack wrote:thanks sooo much for the help.
Not a problem, I try and help when I can.
All the best.