watchdog and 16F88

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Rotac
Posts: 54
Joined: Fri Oct 02, 2009 1:41 pm
Been thanked: 1 time
Contact:

watchdog and 16F88

Post by Rotac »

Hello,

I want to use the watchdog function, because the micro hangs up when I used in a car, I have used as powe supply a 5 V regulator with the 2 capacitors (100N) and 2 capacitors (100uF, 470uF) and a diode in de power line.
One output I have used as "Run " led (RB2), all other I/O are in use even RA5, the micro runs at 8 Mhz with internal RC. it workks very well without disabled Watchdog.
When I set the Watchdog to "On" in Configuration menu and download the program to the micro, only one Led (RB5) is on and it's doesn't work (no respond on input to any output).

What do I wrong?

It it posible to use the watchdog function in combination with the run led, so when the watchtdog will be activated it's been seen by the led?

Question: How can I solved this problem?

Regards

Rob

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: watchdog and 16F88

Post by medelec35 »

Hi Rob.
If your your going to enable watchdog timer, then you will need to Enable "Auto Clear watchdog" from build, Project options menu (Flowcode V5)
Or View, Project options menu (Flowcode V4).


Note the Auto Clear watchdog is only effective when delays or components that use delays are involved.
If not many delays are used then to reset watchdog timer you could place a few C code blocks with

Code: Select all

MX_CLEAR_WATCHDOG;
Rotac wrote: It it posible to use the watchdog function in combination with the run led, so when the watchtdog will be activated it's been seen by the led?
What I would do is get the led to rapidly flash for a fixed number of times during the initial power up prior to the main loop.
Then each time microcontroller resets you will see LED flasing a few times.
Perhaps keeps flashing at 1/2 Hz for 30 seconds?

If your stuck then if your able to post a flowchart, I can help you further.

Martin
Martin

Rotac
Posts: 54
Joined: Fri Oct 02, 2009 1:41 pm
Been thanked: 1 time
Contact:

Re: watchdog and 16F88

Post by Rotac »

Hi Martin,

I have set (project options menu (V4) the automatic watchdog, question why not the setting by chip settings (2x)?

Your command "MX_CLEAR_WATCHDOG" is that the same I used in the C code?

Your Idee to make a Run led in the beginning op the program, before the main loop is OK, but maybe you can it combine with the flashing Led (B0) so when the watchdog is active the led flashes different than in the main loop

Regards

Rob
Attachments
16f88.fcf
Test wd
(7.5 KiB) Downloaded 333 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: watchdog and 16F88

Post by medelec35 »

Hi Rob,
I have set watchdog timer to enabled and changed osc frequency from 4MHz to 8MHz since you have got osccon=0x70; = 8MHz

Another thing I have done is changed LED 0 pattern from the normal 13Hz to practically on all the time (a bit of flicker) for 5 seconds if chip restarted.
Or 16f88V2a is solid for about 5 seconds

Within this 1st 5 seconds, switches can still be used as normal.

If you want a specific normal operation pattern then if you post the details I will alter Flowchart accordingly.
Rotac wrote: question why not the setting by chip settings (2x)?
Not sure what your asking, but your frequency was set to 4MHz instead of 8MHz
Rotac wrote: Your command "MX_CLEAR_WATCHDOG" is that the same I used in the C code?
Yes it's the same.
It's used to clear the watchdog timer so watchdog time out does not occur during normal operation.

Martin
Attachments
16f88V2.fcf
(8.5 KiB) Downloaded 294 times
16f88V2a.fcf
(8.5 KiB) Downloaded 299 times
Martin

Rotac
Posts: 54
Joined: Fri Oct 02, 2009 1:41 pm
Been thanked: 1 time
Contact:

Re: watchdog and 16F88

Post by Rotac »

Hi Martin,

Many thanks, for your quick response. even on Sunday.

I had forgotten to set the right osc. frequency, but I see less difference when you change this value, in Simulation mode or when you shoot it to the 006 Board!Is this setting for both Simulation and real?

So, if I understand it right and you want to use a watchdog function, you must insert the C code with " clear_wdt();" and this part must in the Main loop and not above this loop?

then you have to set by "Project options" "Automatic watchdog! question why both?

When you look bij the Chip Configuration and look to the first Window, you can set the Watchdog to "on", when you open this window it's always "off"
then when you open the second window, "Switch to Exper Config System" then there is the watchdog setting again, (this 2 settings, I ment with 2x) what is here the function, all these settings for the same item is a little confusing!

the program:
I have compared what I sent and what you have changed and have simplified it with this program, the led goes on for e.g. 2 seconds above the loop? (see attachement)
Question: program runs and everytime the watchdog will be cleared just on time, when this not happen, what's happen then? same like a master clear? or when the power is going off and on?
How many time must the watchdog be cleared (reset) before it's too late?
Is there a possibility so simulate this mailfunction?

Regards and Marry Xmas

Rob
Attachments
16f88V1a.fcf
watchdog examble
(8 KiB) Downloaded 277 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: watchdog and 16F88

Post by medelec35 »

Hi Rob no problem.

I don't work for matrix so I just answer from home, in the hope of helping someone.
Rotac wrote:Is this setting for both Simulation and real?
Just for the real hardware and not simulation.
You probably don't notice a lot of difference between Clock speed (View, Project options) set at 4MHz & 8MHz because the clock speed is use setting the correct time delays. So this would have an effect on LCDs, delays ect.
Your just using 50ms for your main program, so insted of 50ms, in relaity would be 25ms.

It's the 'osccon' command that is actually setting hardware oscillator speed.

Or if you had an external crystal or resonator it will be those that set osc speed.
Rotac wrote: So, if I understand it right and you want to use a watchdog function, you must insert the C code with " clear_wdt();" and this part must in the Main loop and not above this loop?
That's correct. If watchdog is enabled, then if a watchdog clear command e.g clear_wdt(); is not accessed within 18ms then your microcontroller will reset.

Once the watchdog timer is cleared using clear_wdt(); then again clear_wdt(); has to be seen within 18ms (before timer rolls over) . This cycle is permanently repeating.
That's why clear_wdt() is used inside the loop, so it keeps clearing the watchdog timer (otherwise known as 'patting the dog')

As it happens, your loop will last about 24ms before the delay is accessed, so it's recommended you having the watchdog clear command within your loop.
At least after 24 ms delay will reset watchdog timer, so long as Auto clear watchdog timer is enabled!
Rotac wrote: then you have to set by "Project options" "Automatic watchdog! question why both?
The Auto clear watchdog does not enable the watchdog timer. All it does place a clear_wdt(); command within delays that's used for components and actual delays them self.
For the watchdog timer to be enabled, it must be set to enabled within advanced configuration menu.
Rotac wrote: When you look bij the Chip Configuration and look to the first Window, you can set the Watchdog to "on", when you open this window it's always "off"
then when you open the second window, "Switch to Exper Config System" then there is the watchdog setting again, (this 2 settings, I ment with 2x) what is here the function, all these settings for the same item is a little confusing!
Yes this can be confusing at first.
It is not recommended to use the basic configuration at all.
That was intended for older microcontrollers that had much less functions than modern day microcontrollers.
If you set enable watchdog on the simple configuration screen, then go into advance screen, all the default values will be restored. Hence your see watchdog timer as off again.
I have the expert screen permanently enabled.
To do this:

On simple configuration screen ('Chip','c=Configure')
select options, then un-tick 'Use simple config screen'

When using Advance Config screen, just make sure low voltage programming and background debug & extended CPU (only if you see that option as that only applies to some microcontrollers)
Rotac wrote: the program:
I have compared what I sent and what you have changed and have simplified it with this program, the led goes on for e.g. 2 seconds above the loop?
That's totally up to you how you do your flowchart, the only difference between the way I altered it and yours is with mine you can press the switches to perform an action while LED is solid.
With yours you can't.
I don't mind at all if you use our ideas or not, so long as your happy, and learn something new, that's all that matters.
Rotac wrote: Question: program runs and everytime the watchdog will be cleared just on time, when this not happen, what's happen then? same like a master clear? or when the power is going off and on?
If watchdog timer is not cleared in time, then i'm fairly sure it will restart as though power has been interrupted.
Rotac wrote: How many time must the watchdog be cleared (reset) before it's too late?
Is there a possibility so simulate this mailfunction?
There are not too many times. if unsure then just add a few extra commands.
All that has to be done is use a clear command before 18ms has elapsed (timer rolls over) as stated above.

You may have seen two different commands to clear the watchdog timer.
clear_wdt();
and
MX_CLEAR_WATCHDOG;
Difference is:
clear_wdt(); only works with Boostc default compiler.
MX_CLEAR_WATCHDOG; works with both Boostc and Hitec compilers.

Hope this helps.

Martin
Martin

Rotac
Posts: 54
Joined: Fri Oct 02, 2009 1:41 pm
Been thanked: 1 time
Contact:

Re: watchdog and 16F88

Post by Rotac »

Hi Martin,

Thanks again, for the detailed explanation.

Osc:
So if you write in C-Block for e.g. "osccon = 0x70 then the setting in project options does't have any affect ? or will be overruled?

Watchdog:
you wrote "It is not recommended to use the basic configuration at all."

so only the command in C-Block and the setting in project options is OK for using the watchdog? I mean is the setting in the Expert config screen necessarily for this chip?


Simulation and Real
When you simulate a project with flashing it's flashing different in Real mode Can you explain this to me?

Thanks for your time

Regards

Rob

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: watchdog and 16F88

Post by medelec35 »

Hi Bob,
Your welcome.

A very good thing about products sold by Matrix Multimedia is the support by it's staff and forum users in my opinion can't be beat.
Plus products are great!
Of course :lol:
Rotac wrote: Osc:
So if you write in C-Block for e.g. "osccon = 0x70 then the setting in project options does't have any affect ? or will be overruled?
the setting of clock speed in project options will not alter the internal or external osc speed at all, so no its not overruled.
That's why for internal oscillator running at 4MHz for example you need to set osccon at 0x60 (this changes the internal osc of your hardware) then you will also need to change Clock speed from project options so your delays will be correct. Some components like LCD must have correct clock speed for it to work.
Rotac wrote: Watchdog:
you wrote "It is not recommended to use the basic configuration at all."

so only the command in C-Block and the setting in project options is OK for using the watchdog? I mean is the setting in the Expert config screen necessarily for this chip?
I don't recommend using simple screen because of lack of options. Ie osc and watchdog. What about MCLR?
Do you want it enalbled or use MCLR as an input?
You have not got that option with simple config, it's only avaible within advance config screen.
Rotac wrote: Simulation and Real
When you simulate a project with flashing it's flashing different in Real mode Can you explain this to me?
The simulation is much slower than the real world.
When you see an LED flashing using simulator, it could look solid on your hardware.
Also C code blocks are not simulated either.
Flowcode simulator has got some great advantages.
E.g press F8 once to single step, then add variables to the variable watch window.
Singe step to watch the variables change value.
You can use this method for debugging.

Flowcode V5 has got loads of simulation improvements as well as load other improvements over V4.
To try Flowcode V5 for free:
http://www.matrixmultimedia.com/lc_index.php?p=25

If you want to simulate in real time before sending to your target device, then have a look at this:
http://www.matrixmultimedia.com/mmforum ... =25#p24998
&
http://www.matrixmultimedia.com/mmforum ... =7&t=11092

I would highly recommend that simulaor ,and you will find after trial time has elapse, it is very reasonably priced for the full version.

You can ask questions any time, but you may find these links will also help you:

Free course, training videos,examples etc:
http://www.matrixmultimedia.com/lc_index.php

project not running as expected?:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936
Martin

Rotac
Posts: 54
Joined: Fri Oct 02, 2009 1:41 pm
Been thanked: 1 time
Contact:

Re: watchdog and 16F88

Post by Rotac »

Hi Martin,

thanks for your links, my doubt to upgrade to V5 is now gone,, even the Pic simulator would be a nice add.

I have here an image of the Expert settings (see tachment).

So you must at 3 places activate the watchdog? was't it be simplify at one place?

Regards

Rob
Attachments
overvieuw Expert configuration
overvieuw Expert configuration
16F88 expert configuration.JPG (66.6 KiB) Viewed 7256 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: watchdog and 16F88

Post by medelec35 »

Rotac wrote: So you must at 3 places activate the watchdog? was't it be simplify at one place?
Hi Rob,
It was never really at one place.

Which ever way you enable watchdog timer it's two only places & not three.

1) You need to enable auto clear watchdog (that does not enable watchdog timer, but is used to clear watchdog timer when a delay is encountered, so time out is prevented).

2) Either enable watchdog timer using simple configuration settings (I don't recommend this).

OR

2) Enable watchdog timer using advance configuration settings.
Not both!

Its a waste of time enabling watchdog on both configuration screens since if enabled on basic, then as soon as you go to advance configuration settings, the simple settings will be overridden anyway (which is what happens when you go into advance configuration settings).

The reason I don't recommend using the basic configuration screen is:
16F88 configuration settings have been pre-configured by Matrix Multimeda so you won't under normal circumstances need to alter config settings for the chip to run correctly on hardware with EB006 programmer and 19.6608MHz crystal (since 16F88 is shiped with EB006).

With other devices, the default configuration settings are Watchdog and Low voltage programming & MCLR enabled.

So if disable watchdog timer on simple configuration settings, an important function like disabling low voltage programming (not available on all target devices) will get missed.
Martin

Rotac
Posts: 54
Joined: Fri Oct 02, 2009 1:41 pm
Been thanked: 1 time
Contact:

Re: watchdog and 16F88

Post by Rotac »

Hi Martin,

with the 3 Places I ment:

1) in the program it self => clear_wdt();
2) Project options => Automatic watchdog
3) expert configuration => see the last jpg file

Regards

Rob

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: watchdog and 16F88

Post by medelec35 »

I get what your saying.

In that case yes you will need to use all three if:

Delay, RS232, LCD (or components that contains their own delay)
is not accessed within 18ms (you can manually change this on some of the newer microcontollers).

It does not matter what language is used e.g from assembly, C, JAL ect, its sill the same you will need to place clear_wdt(); commands if watchdog is enabled.
However you will need more of clear_wdt(); commands with those than you do with Flowcode as they will probably not have 'Auto clear watchdog' option to select.
Martin

Post Reply