Auto clear watchdog problem

Moderator: Benj

Brian Walsh
Posts: 29
Joined: Thu Jan 14, 2010 10:43 pm
Has thanked: 3 times
Contact:

Auto clear watchdog problem

Postby Brian Walsh » Tue Feb 09, 2010 9:45 pm

My next evaluation project with FC4 is interrupt on change to portb. This is used with an encoder on bits 4 & 5.

There is a brief preamble followed by the main loop which outputs an integer value representing the encoder position via RS232.

When a change in the relevant bits of portb occurs, the interrupt handler modifies the position integer value and returns control to the main loop.

While watching program performance, I noticed that, after a couple of minutes, the position variable zeroed itself.

The auto clear watchdog check box in project options is ticked but changing the watchdog postscaler value changes the time out period so I'm pretty sure this is the culprit.

Adding the line 'asm clrwdt' to the main loop solves the problem - so something's not right.

Brian Walsh.
Attachments
encoder_test.fcf
(10.5 KiB) Downloaded 225 times

User avatar
Steve
Matrix Staff
Posts: 3102
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 391 times
Contact:

Re: Auto clear watchdog problem

Postby Steve » Wed Feb 10, 2010 8:12 am

Thanks for the note - I'll get someone here to investigate.

User avatar
Steve
Matrix Staff
Posts: 3102
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 391 times
Contact:

Re: Auto clear watchdog problem

Postby Steve » Wed Feb 10, 2010 9:28 am

We know why you are having this issue. The "auto-clear watchdog timer" actually only affects the delay icon in Flowcode. If you are not using it, then you will need to issue occasional C-icon "clrwdt();" commands.

Also note that relatively large delays in the code for Flowcode components include clrwdt statements.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8542
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Auto clear watchdog problem

Postby medelec35 » Fri Feb 12, 2010 5:02 pm

steve wrote:you will need to issue occasional C-icon "clrwdt();" commands.

Or clear_wdt();
since with 16F737 clrwdt(); does not complie due to error.
steve wrote:The "auto-clear watchdog timer" actually only affects the delay icon in Flowcode .

Thought it also affects the delays within component macros?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Benj
Matrix Staff
Posts: 14581
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4605 times
Been thanked: 4241 times
Contact:

Re: Auto clear watchdog problem

Postby Benj » Mon Feb 15, 2010 2:03 pm

Hello Medelec

Ok this is a problem that I think I should be able to resolve in the next release.

If anyone is using a device from the 16F737 product family and want to use the watchdog delays then they will need to make the following modification to their internals.h file found in the FCD directory.

#define MX_CLEAR_WATCHDOG CLRWDT()

becomes

#define MX_CLEAR_WATCHDOG clear_wdt()

You can comment out the first line and that way it is easy to change back if you are using a different device.

User avatar
Benj
Matrix Staff
Posts: 14581
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4605 times
Been thanked: 4241 times
Contact:

Re: Auto clear watchdog problem

Postby Benj » Fri Feb 19, 2010 9:46 am

Hello

Sorry I think I may have made a mistake here. Please ignore my last posting.

There are two defines inside the internals file.

This is the BoostC clear watchdog command.

#define MX_CLEAR_WATCHDOG clear_wdt()

and here is the HITECH clear watchdog command.

#define MX_CLEAR_WATCHDOG CLRWDT()

The file should be ok as is and does not require editing.

To use extra watchdog clear commands in your program choose the appriopriate statement for your compiler.

BoostC - clear_wdt();
HITECH - CLRWDT();

User avatar
Steve
Matrix Staff
Posts: 3102
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 391 times
Contact:

Re: Auto clear watchdog problem

Postby Steve » Fri Feb 19, 2010 10:16 am

Or just use the following, which should be compiler-independent:

Code: Select all

MX_CLEAR_WATCHDOG;
These users thanked the author Steve for the post:
medelec35 (Fri Jan 07, 2011 2:08 pm)
Rating: 5.26%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8542
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Auto clear watchdog problem

Postby medelec35 » Tue Jul 06, 2010 4:20 pm

There is an issue with 16F883 and auto clear watchdog. When auto clear watchdog is selected, even if watchdog timer config. is set to off. the duty of both PWM channels are lower than normal and are no longer adjustable. If auto clear watchdog is un-ticked then PWM Duty increases to normal, and regain variable control again.
Is there a known issue/fix with Auto clear watchdog, or would you like me to send software in question for testing?
Thanks.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Steve
Matrix Staff
Posts: 3102
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 391 times
Contact:

Re: Auto clear watchdog problem

Postby Steve » Wed Jul 07, 2010 6:51 am

I've not heard of this issue. Please create a simple program and post on this forum so we can investigate. Thanks.

User avatar
Benj
Matrix Staff
Posts: 14581
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4605 times
Been thanked: 4241 times
Contact:

Re: Auto clear watchdog problem

Postby Benj » Wed Jul 07, 2010 1:44 pm

Hello Medelec,

Right as far as I can see there is a bit of a problem as both PWM timer1 and Watchdog timer use the same input prescaler peripheral.

If you are leaving the watchdog configuration setting disabled then the watchdog itself will be disabled.

Enabling the autoclear watchdog simply uses the BoostC or HiTech C clear watchdog commands so it seems that this command is automatically switching the prescaler from the timer1 peripheral to the watchdog timer.

Therefore if you are using PWM then you will have to either not use the watchdog at all or you may be able to clear the watchdog timer using direct register access rather then using the clear function. There may also be a way to switch the prescaler back to the control of the timer 1 but im not sure about this.

Anyway have a bit of a play and let me know who you get on.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8542
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Auto clear watchdog problem

Postby medelec35 » Wed Jul 07, 2010 3:44 pm

Thank you for that valuable information, I appreciate it. There is however one thing I have noticed, when I did a cut down version to post online, with Auto watchdog clear enabled, the PWM was working 100% OK. One difference was I deleted a 2 second delay, so I wonder if working for short time delay periods, but not longer delays? Unfortunately I cannot test that with 16F883, as they keep failing to program via ICSP. (well some can program up to about 5 times, others would not program at all. Un like 16F737 which would program 100%)
When I can I will try that theory.
Thanks once again.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8542
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Auto clear watchdog problem

Postby medelec35 » Wed Jul 07, 2010 9:39 pm

Hmm I am a bit confused. I thought timer1 prescaler used T1CON.

WDT shares prescaler with Timer0 which is OPTION_REG which has nothing to do with PWM, as you said, PWM uses timer1
Unless I have got something wrong?

Which Registor are you referring to that gets changed please?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8542
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Auto clear watchdog problem

Postby medelec35 » Tue Jul 13, 2010 7:28 am

Benj wrote: Anyway have a bit of a play and let me know who you get on.

I have got round the auto clear watchdog issue by using delays like the one below:
Thanks again.
Auto Clear Watchdog Issue.JPG
Auto Clear Watchdog Issue.JPG (11.78 KiB) Viewed 7119 times

Two second delay
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Benj
Matrix Staff
Posts: 14581
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4605 times
Been thanked: 4241 times
Contact:

Re: Auto clear watchdog problem

Postby Benj » Tue Jul 13, 2010 10:02 am

Hi Medelec,

Your right the watchdog shares the prescaler resource with timer 0 and not timer 1. The powerup timer uses timer 1 but this should not be active during operation.

Im a bit stumped by this. Thanks for posting up the workaround.

If I get some time I would like to have a look at the assembler code to see exactly what is going wrong with this.