Watchdog slowing program down

Moderator: Benj

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Watchdog slowing program down

Postby daveb0360 » Tue Aug 28, 2012 10:23 am

Hi,
I have almost finished my code with great thanks to members debugging my efforts. I learned a lot in the process.

However, a final part of the project was to have watchdog enabled to avoid lockups since my project is fairly critical.
As soon as I run the code with watchdog icon and auto clear watchdog enabled, my program still functions but very much slower. This is causing an over temperature condition because the program is not reacting quickly enough......I read somewhere in the forums that a bug exists that slows down delays but that this bug was to be fixed in V4.5
I am running v4.5 but can't find a way round this problem.
Any clues anybody.
Code attached

Dave
Attachments
HeaterControl_eval15.fcf
(17.05 KiB) Downloaded 175 times

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

Re: Watchdog slowing program down

Postby medelec35 » Tue Aug 28, 2012 10:48 am

Hi Dave,
I thought it was indeed fixed with V4.5

Here is what I would suggest:
Only in configuration menu, disable Watchdog timer. (leave Auto Clear Watchdog in view, project options enabled)
If problem is resolved then microcontroller is resetting so more clear watchdog commands are required.

If problem not resolved then I can post a solution.

Edit:
I will carry out some testing tonight and post results with a solution anyway

Martin
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: 8536
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3525 times
Contact:

Re: Watchdog slowing program down

Postby medelec35 » Tue Aug 28, 2012 6:23 pm

Before I can come up with a solution, we need to know cause of issue first.

I have tested a 16F883 1 sec delay with and without watchdog enabled and here are results of measuring 1sec delay:
Water Heater Dealy Issue1.png
(436.81 KiB) Downloaded 2705 times


As you can see there is a 4% overhead increase.
I would not have thought that would cause issue your describing.

Can you also try with both auto clear watchdog and watchdog timer disabled please then post all results.

Thanks

Martin
Martin

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

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Watchdog slowing program down

Postby daveb0360 » Wed Aug 29, 2012 10:28 am

Hi Martin,
I have tried what you suggested and there is approx 30% increase in timing of main program loop.
I will try and set up scope and publish the traces shortly but in the interim, could it be because the watchdog icon is in the read macros that are looping 64 times within the main loop? wouldn't this mean that the watchdog was being set and reset 64 times per loop?

Just a theory.

Dave

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

Re: Watchdog slowing program down

Postby Benj » Wed Aug 29, 2012 10:49 am

Hi Dave,

The watchdog command simply resets the watchdog count register back to 0 so there is no problem with calling it repeatedly.

From the top of my head the auto clear watchdog command adds the function to delays and hardware macro calls so if you have multiple of these calls in a loop then it might explain why you are getting such a longer delay.
These users thanked the author Benj for the post:
daveb0360 (Wed Aug 29, 2012 1:04 pm)
Rating: 5.26%
 

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

Re: Watchdog slowing program down

Postby medelec35 » Wed Aug 29, 2012 3:11 pm

Hi Dave,
I have posted a way round for you to have a look at.
Not tested on hardware, but idea is delay for 5ms (use watchdog clear command)then loop 5ms delay.
Eg. for 3secs = 3000ms
= 5ms*100*6
= 3000ms
I'm at work so rushed it a bit, hope it helps?

Martin
Attachments
HeaterControl_eval16.fcf
(20.49 KiB) Downloaded 163 times
These users thanked the author medelec35 for the post:
daveb0360 (Thu Aug 30, 2012 2:28 am)
Rating: 5.26%
 
Martin

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

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Watchdog slowing program down

Postby daveb0360 » Thu Aug 30, 2012 2:33 am

Hi Martin,
This is brilliant..........I can see what you are doing and although it hasn't cured the problem, this is only because the overall loop time needs to be included in the timings which I hadn't accurately done......I can take this from here so BIG thanks to you.
I am going to add a diag output to the unused port pin for test and debug purposes......something that can be scoped if ever returns come in.

Just to confirm though....I need watchdog enable bit set in chip config & auto clear watchdog disabled in project options.........correct?

Dave

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

Re: Watchdog slowing program down

Postby medelec35 » Thu Aug 30, 2012 7:35 am

Hi Dave,
No problem.

What I do for diagnostics is set up rs232 on one pin.
Then I send to rs232 time elapsed in seconds and the value of variables.
That way I can not only tell if chip is resetting, I can tell why software may not be working since I can observe value of variables.
What I do to save space is have one temp string, then convert variable to string, and send string to rs232 every second.
Then the rs232 can be captured to a text file e.g by using capture text within hyperterminal (standard on PC's up to XP I believe?)
I can add it and post diagnostics if you would like to see?

Martin
These users thanked the author medelec35 for the post:
daveb0360 (Thu Aug 30, 2012 12:45 pm)
Rating: 5.26%
 
Martin

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

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Watchdog slowing program down

Postby daveb0360 » Thu Aug 30, 2012 12:52 pm

Hi,
Thanks Martin, I understand what you're doing. i don't have the luxury of hyperterminal in Win7 64Bit pro. Don't know why they would drop such basic functionality......it hardly bloats the OS !
There are alternative comm apps on the net I can explore but for now, I'll run with this.
Certainly worth building into the next version release , along with the frost protection routine........gives me opportunity to bill the customer for updates... :wink:

Cheers

Dave

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Watchdog slowing program down

Postby Enamul » Thu Aug 30, 2012 12:59 pm

Hi,
But you can still use hyper-terminal which is available in windows XP. or you can use terminal software for the link..
http://www.ddrservice.net/download/Soft ... l.exe.html
If you want to use hyper-terminal it self..I can post you for that which you can use in windows 7 64-bit machine. But the issue might be there is no serial port in new machines..solution for that is to use serial to usb converter. I bought one from Maple Electronics working fine for me..Just replaced the necessity of serial physical port.
These users thanked the author Enamul for the post:
daveb0360 (Thu Aug 30, 2012 1:10 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Watchdog slowing program down

Postby daveb0360 » Thu Aug 30, 2012 1:08 pm

Benj wrote:Hi Dave,

The watchdog command simply resets the watchdog count register back to 0 so there is no problem with calling it repeatedly.

From the top of my head the auto clear watchdog command adds the function to delays and hardware macro calls so if you have multiple of these calls in a loop then it might explain why you are getting such a longer delay.

Hi Ben,
How does the auto clear watchdog command deal with delays longer than 18ms? Perhaps this should be explained more in depth on the forum or in the help files....it seems many people are getting 'confused / caught out by this important function. To have confidence in the function, FC users need some in depth detailing of such functions.
On a connected note, could I put forward a few suggestions for FC; based on my own experience as a novice or occasional coder..

1. A programmatic way of enabling and setting watchdog prescaler /postscaler options in order to extend watchdog timeout periods without C code knowledge. (watchdog setup module)
2. Enhancement to the GUI to enable visual grouping of sub- routines and loops. Flowcodes can get very visually complex and hard to follow at times even a simple 'draw a box around...' type of functionality would be helpful to some. Or, enable change colour of individual icons/text.
3. Ability to store textual notes within project files would enhance integration.
4. Version control.

Kindest Regards

Dave
These users thanked the author daveb0360 for the post:
Benj (Thu Aug 30, 2012 3:07 pm)
Rating: 5.26%
 

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

Re: Watchdog slowing program down

Postby medelec35 » Thu Aug 30, 2012 3:04 pm

Hi Dave, attacted is an example of diagnostics:
heater control diag.png
heater control diag.png (92.22 KiB) Viewed 6763 times

1st column is Elapsed seconds.
2nd is Voltage variable.
3rd is Temperature variable.
4th is Pattern
You can get diagnostics to display text as well e.g
Secs: 45 Vol: 345 Temp: 532 Pat: 2
I prefer non text for importing directly to a spread sheet
Using timer2 which only simulates in Flowcode 5 and above.
Therefore if you want to see it working you will need to use hardware or Real Pic simulator.
You will not be able to Flowcode to compile until attached 12F617.fcd is placed in C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD
(windows 64 bit)
Or
C:\Program Files\Matrix Multimedia\Flowcode V4\FCD
(windows 64 bit)

I use a TTL to usb converter
E.g from Farnell:

Code: Select all

FTDI - TTL-232R-WE - CABLE,USB-TTL,SER CONV,5V,WIRE-END
Manufacturer: FTDI
Order Code: 1740364
Manufacturer Part No: TTL-232R-WE RoHS :  Yes

Description CABLE,USB-TTL,SER CONV,5V,WIRE-END
Connector Type A:USB
Connector Type B:TTL-232R 


Although I have found CP211x type to be very reliable.
Attachments
12F617.fcd
(10.78 KiB) Downloaded 119 times
HeaterControlVgdb2tst617.zip
(6.54 KiB) Downloaded 102 times
Martin

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

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

Re: Watchdog slowing program down

Postby Benj » Thu Aug 30, 2012 3:19 pm

How does the auto clear watchdog command deal with delays longer than 18ms?


The auto clear watchdog command when enabled basically replaces the ms and s delay functions with a loop containing a much smaller delay and the watchdog reset command. This loop will run until the original delay value has been reached.

1. A programmatic way of enabling and setting watchdog prescaler /postscaler options in order to extend watchdog timeout periods without C code knowledge. (watchdog setup module)
2. Enhancement to the GUI to enable visual grouping of sub- routines and loops. Flowcodes can get very visually complex and hard to follow at times even a simple 'draw a box around...' type of functionality would be helpful to some. Or, enable change colour of individual icons/text.
3. Ability to store textual notes within project files would enhance integration.
4. Version control.


These are all great suggestions and hopefully we can work some if not all of them into the next version.

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

Re: Watchdog slowing program down

Postby medelec35 » Thu Aug 30, 2012 7:03 pm

You can even add text conditions:
Water heater2.png
Water heater2.png (119.84 KiB) Viewed 6752 times
Attachments
HeaterControl_eval14 with Diag2.fcf
(23.27 KiB) Downloaded 143 times
Martin

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