control over WDT timeout

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
hackinblack
Posts: 26
Joined: Mon Apr 17, 2017 9:55 pm
Has thanked: 2 times
Been thanked: 14 times
Contact:

control over WDT timeout

Post 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)
Attachments
blinkWDT509.fcfx
(6.96 KiB) Downloaded 221 times

hackinblack
Posts: 26
Joined: Mon Apr 17, 2017 9:55 pm
Has thanked: 2 times
Been thanked: 14 times
Contact:

Re: control over WDT timeout

Post 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:-
Attachments
error code.PNG
(6.12 KiB) Downloaded 2301 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: control over WDT timeout

Post 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!
Martin

hackinblack
Posts: 26
Joined: Mon Apr 17, 2017 9:55 pm
Has thanked: 2 times
Been thanked: 14 times
Contact:

Re: control over WDT timeout

Post 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 249 times

hackinblack
Posts: 26
Joined: Mon Apr 17, 2017 9:55 pm
Has thanked: 2 times
Been thanked: 14 times
Contact:

Re: control over WDT timeout

Post by hackinblack »

WDT509sleep.fcfx
(7.29 KiB) Downloaded 242 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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: control over WDT timeout

Post 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.
Martin

Post Reply