Auto clear watchdog problem
Moderator: Benj
-
- Posts: 29
- Joined: Thu Jan 14, 2010 10:43 pm
- Has thanked: 3 times
- Contact:
Auto clear watchdog problem
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.
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 423 times
- Steve
- Matrix Staff
- Posts: 3421
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Auto clear watchdog problem
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.
Also note that relatively large delays in the code for Flowcode components include clrwdt statements.
-
- 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: Auto clear watchdog problem
Or clear_wdt();steve wrote:you will need to issue occasional C-icon "clrwdt();" commands.
since with 16F737 clrwdt(); does not complie due to error.
Thought it also affects the delays within component macros?steve wrote: The "auto-clear watchdog timer" actually only affects the delay icon in Flowcode .
Martin
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Auto clear watchdog problem
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Auto clear watchdog problem
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();
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();
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Steve
- Matrix Staff
- Posts: 3421
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Auto clear watchdog problem
Or just use the following, which should be compiler-independent:
Code: Select all
MX_CLEAR_WATCHDOG;
-
- 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: Auto clear watchdog problem
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.
Is there a known issue/fix with Auto clear watchdog, or would you like me to send software in question for testing?
Thanks.
Martin
- Steve
- Matrix Staff
- Posts: 3421
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Auto clear watchdog problem
I've not heard of this issue. Please create a simple program and post on this forum so we can investigate. Thanks.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Auto clear watchdog problem
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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: Auto clear watchdog problem
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.
When I can I will try that theory.
Thanks once again.
Martin
-
- 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: Auto clear watchdog problem
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?
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
-
- 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: Auto clear watchdog problem
I have got round the auto clear watchdog issue by using delays like the one below:Benj wrote: Anyway have a bit of a play and let me know who you get on.
Thanks again. Two second delay
Martin
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Auto clear watchdog problem
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel