Watchdog Reset

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Niro
Posts: 75
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Watchdog Reset

Postby Niro » Fri Jun 22, 2018 5:41 pm

Hi guys,

for an old software I need to fix, I have a problem using

Code: Select all

// Disable Watchdog from Software-Reset
   MCUSR = 0;
   wdt_disable();
//

for supplementary code after reset, to disable the watchdog at system start.

The code works fine with AtmelStudio, but Flowcode shows some weired error messages, when this code is included.

Many Thanks!
Niro

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

Re: Watchdog Reset

Postby medelec35 » Fri Jun 22, 2018 6:44 pm

Hi Niro,
Have you tried commands within C code?

What is the target device?
These users thanked the author medelec35 for the post:
LeighM (Mon Jun 25, 2018 8:42 am)
Rating: 5.88%
 
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin

Niro
Posts: 75
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: Watchdog Reset

Postby Niro » Sat Jun 23, 2018 6:00 pm

Hi medelec,

cool! ...You are right!
Inside c-code within main it works quite fine!
But I thought the supplementary code also to be "c"??
BTW. ...target is ATmega328.

Many Thanks!
Niro
These users thanked the author Niro for the post:
medelec35 (Wed Jul 11, 2018 5:44 pm)
Rating: 5.88%
 

User avatar
LeighM
Matrix Staff
Posts: 1408
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 355 times
Been thanked: 512 times
Contact:

Re: Watchdog Reset

Postby LeighM » Mon Jun 25, 2018 8:45 am

I thought the supplementary code also to be "c"?

Additional C functions can be included into the project via the supplementary code, they won't execute unless called from a C icon.
These users thanked the author LeighM for the post:
medelec35 (Mon Jun 25, 2018 8:50 am)
Rating: 5.88%
 

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

Re: Watchdog Reset

Postby medelec35 » Mon Jun 25, 2018 8:50 am

Hi Niro,
You're welcome.
Glad flowchart now compiles.
Thanks for the update.

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

Martin

electron67
Posts: 278
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 95 times
Been thanked: 36 times
Contact:

Re: Watchdog Reset

Postby electron67 » Sat Jun 30, 2018 5:37 am

Hello everyone,

I'm having a similar problem, I want to reset the PIC with the flow diagram using C; I did a small program but when I'm going to simulate it with Flowcode 6 or Flowcode 7 the program is not reset, it continues normal, I also test it in hardware and it does not reset, I activate the watchdog function and the program does not start, I tried several options in C , asm ("reset"); but I can not reset the program; You could see the flow chart and get oriented; I do not know the C language (for this reason I use Flowcode, excellent for those who do not know C)

Thanks in advance; I hope you can help me. :(

Enrique
Attachments
RESET.fcfx
Flowchart Reset
(4.45 KiB) Downloaded 8 times

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

Re: Watchdog Reset

Postby medelec35 » Mon Jul 02, 2018 10:41 pm

Hi Enrique,
Have you tried it in lower case:

Code: Select all

reset();

Key words for boostC (Flowcode 6 and below) is lower case, whereas for XC8 (Flwocode V7 & above)
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin

electron67
Posts: 278
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 95 times
Been thanked: 36 times
Contact:

Re: Watchdog Reset

Postby electron67 » Mon Jul 02, 2018 11:33 pm

Hi Martin;

If I try it, I even try to simulate Flow8 and Flow7 and Flow6 with lowercase, but the LED stays on and does not reset. :?:

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

Re: Watchdog Reset

Postby medelec35 » Mon Jul 02, 2018 11:44 pm

Hi Enrique,
electron67 wrote:I even try to simulate

You won't be able to simulate with any version!
Although V8 is the first Flowcode version to simulate C Code,
V8 won't be able simulate all functions and RESET is one of those.
You can only test reset command with hardware.
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin

electron67
Posts: 278
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 95 times
Been thanked: 36 times
Contact:

Re: Watchdog Reset

Postby electron67 » Tue Jul 03, 2018 12:14 am

If I tried it in software and hardware. Also use the watchdog in Flow7 but the program does not start in hardware

electron67
Posts: 278
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 95 times
Been thanked: 36 times
Contact:

Re: Watchdog Reset

Postby electron67 » Tue Jul 03, 2018 12:36 am

Hi,

I'm left with doubt if I use lower case in hardware; right now, when I get home, I'm going to verify using hardware, to be sure; in a few minutes I confirm you; thanks for helping !!!

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

Re: Watchdog Reset

Postby medelec35 » Tue Jul 03, 2018 12:40 am

Your welcome.
I tried it with V6 and worked for 16F1937.
If it does not work for you then an alternative would be to enable watchdog timer.
Use Auto clear watchdog in project options.
Then add some C code boxes with

Code: Select all

MX_CLEAR_WATCHDOG;

What I do with my devices if allowed to to extend watchdog time out time.
Then for reset just use a while 1 loop.
The microcontroller will reset due to watchdog time out.
These users thanked the author medelec35 for the post:
electron67 (Tue Jul 03, 2018 4:50 pm)
Rating: 5.88%
 
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin

electron67
Posts: 278
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 95 times
Been thanked: 36 times
Contact:

Re: Watchdog Reset

Postby electron67 » Tue Jul 03, 2018 4:49 pm

Hi Martin :D

Thanks, Martin; I reset well the PIC use Flow6, lowercase and the 16F887, now I'm going to test it with 16F1509, I'm very grateful, I had tried several options, I was going to connect the reset to a pin of the PIC to reset manually with a PIC timer , but with the software reset it is simplified;
I will also try using the Watchdog (MX_CLEAR_WATCHDOG;).

Thank you very much for helping me with this !!!

Enrique
These users thanked the author electron67 for the post:
medelec35 (Tue Jul 03, 2018 6:55 pm)
Rating: 5.88%
 

SHORTCIRCUIT
Posts: 149
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 37 times
Been thanked: 18 times
Contact:

Re: Watchdog Reset

Postby SHORTCIRCUIT » Wed Jul 11, 2018 4:53 am

Hi Martin
I don't mean to hijack this thread. I have been reading your posts on watchdog timers as I been wanting to learn to use them.
I am experimenting with 16F88 and cannot seem to make it work. I wrote this program that blinks LED at half second increment using component
macro. I enable auto reset WDT in project options and that part works OK. So, now I blink LED 10 times after which WDT resets chip. up to now everything works as advertised. I tried putting a turn off LED macro in the dead part of the loop where nothing happens but the reset WDT does not happen. I tried (MX_CLEAR_WATCHDOG;) using a TMRO interrupt, but that didn't help.

Here is the program Im playing with:
Watchdog.fcfx
(10.16 KiB) Downloaded 3 times


looking forward to your reply
Larry Miranda

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

Re: Watchdog Reset

Postby medelec35 » Wed Jul 11, 2018 8:39 am

Hi Larry,
When you enable Auto Clear watchdog that automatically adds

Code: Select all

MX_CLEAR_WATCHDOG;
to the delays and any built in component that contains delays e.g LCD & UART.
If there is a part of flowchart that does not contain any delays or components that do not have delays e.g LED TurnOn/Off then watchdog timeout will occur, therefore

Code: Select all

MX_CLEAR_WATCHDOG;
must be used.
Don't place

Code: Select all

MX_CLEAR_WATCHDOG;
within interrupts as that will defeat the object of enabling watchdog timer.
For example hardware may be stuck in the wrong loop due to EMC interference but the timer interrupt will still be triggering thereby clearing WDT.
For 16F88 using C code, You set the watchdog timeout period from the standard 16ms to between 1ms & 268 secs.

To solve your issue, as there are no delays or any built in component that contains delays within no branch, then within C code,

Code: Select all

MX_CLEAR_WATCHDOG;
must be placed there.
These users thanked the author medelec35 for the post (total 2):
SHORTCIRCUIT (Wed Jul 11, 2018 12:50 pm) • electron67 (Wed Jul 11, 2018 3:12 pm)
Rating: 11.76%
 
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin

SHORTCIRCUIT
Posts: 149
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 37 times
Been thanked: 18 times
Contact:

Re: Watchdog Reset

Postby SHORTCIRCUIT » Wed Jul 11, 2018 1:02 pm

Hi Martin

Thanks for the reply, I think I understand now. I have two more questions. Where does the MX clear come from? Is it a standard C function so that all who know how to program C would then know to apply the MX_CLEAR_WATCHDOG;? Or does it come from somewhere else?

How do I set the watchdog period?

Thanks for your help
Larry Miranda

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

Re: Watchdog Reset

Postby medelec35 » Wed Jul 11, 2018 4:29 pm

Hi Larry,
SHORTCIRCUIT wrote:Where does the MX clear come from? Is it a standard C function so that all who know how to program C would then know to apply the MX_CLEAR_WATCHDOG;? Or does it come from somewhere else?

I could be wrong, so happy to be corrected.
I believe it's not standadard C function.
Since boostC and HiTec (now XC) use different commands to clear WDT, I believed Matrix created

Code: Select all

MX_CLEAR_WATCHDOG
function that will work with compilers used so far.

SHORTCIRCUIT wrote:How do I set the watchdog period?

You will need to look in the datasheet on page 142.
It shows the WDTCON which is WATCHDOG CONTROL REGISTER.
The setting of those bits determine Watchdog Timer Period from 1/32 to 1/65536
Basically there is a 16bit timer and a 7bit counter shared with Timer0
So you can use anyone or both.
As the watchdog uses a 32KHz internal oscillator = 1/32E03 = 32E-06 duration.
Looking at the datasheet the minimum time just with WATCHDOG CONTROL REGISTER = 32E-06 x 32 = 1ms. The latter 32 is just with WDTCON (bits 1 - 4 ) set to 0000.
With bits 1 - 4 set to 1111 for maximum time of 32E-06 x 65536 = 2.1 seconds.
If you also use the 7bit prescaler (OPTION_REG BITS 0 TO 2) as well, then maximum time before watchdog triggers: 32E-06 x 65536 x 128 = 268.4 seconds.
I believe I have calculated correctly.

So to set the watch dog timeout for maximum time duration and you're not using Timer0 prescaler.
With Flowcode6:
Use a C Code block with

Code: Select all

option_reg = option_reg|0b111;
wdtcon = wdtcon|10111;
These users thanked the author medelec35 for the post (total 2):
electron67 (Wed Jul 11, 2018 5:22 pm) • SHORTCIRCUIT (Wed Jul 11, 2018 7:52 pm)
Rating: 11.76%
 
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin

electron67
Posts: 278
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 95 times
Been thanked: 36 times
Contact:

Re: Watchdog Reset

Postby electron67 » Wed Jul 11, 2018 5:39 pm

I greatly appreciate Martin, Benj for his help and practical examples and the entire Matrix team for taking time to help those who do not study Microcontrollers and any way we work and live from Microcontrollers !!!

Thank you so much :D
Enrique

SHORTCIRCUIT
Posts: 149
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 37 times
Been thanked: 18 times
Contact:

Re: Watchdog Reset

Postby SHORTCIRCUIT » Wed Jul 11, 2018 7:52 pm

Hi Martin

Wow, that was a lot to digest. I did find what you explained in the data sheet and further found the info on the OPTION_REG from the index.
I am pretty sure I understand it now. You can only use the prescaler for WDT or TMRO, but not both, but 2 seconds is plenty of time anyway.
As always Martin, thank you very much, this was something I always wondered about and never took the time to find out.

Enrique, sorry to hijack your thread. I did learn a lot here.

Best regards
Larry
These users thanked the author SHORTCIRCUIT for the post:
electron67 (Wed Jul 11, 2018 9:02 pm)
Rating: 5.88%
 

SHORTCIRCUIT
Posts: 149
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 37 times
Been thanked: 18 times
Contact:

Re: Watchdog Reset

Postby SHORTCIRCUIT » Wed Jul 11, 2018 8:25 pm

Hi Martin

Is there a default for WDTCON or should you not assume a default.

Thank you in advance
Larry

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

Re: Watchdog Reset

Postby medelec35 » Wed Jul 11, 2018 9:40 pm

The default values for registers can be found on page 14 - 16.
The default for WDTCON is :
WDTCON Default values.png
WDTCON Default values.png (44.31 KiB) Viewed 93 times
=
WDTCON Default values 2.png
WDTCON Default values 2.png (35.72 KiB) Viewed 93 times

So for duration =

Code: Select all

32E-06 x 512 = 16ms

This backs up my earlier post:
medelec35 wrote:For 16F88 using C code, You set the watchdog timeout period from the standard 16ms to between 1ms & 268 secs.
These users thanked the author medelec35 for the post:
SHORTCIRCUIT (Thu Jul 12, 2018 12:21 am)
Rating: 5.88%
 
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin

SHORTCIRCUIT
Posts: 149
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 37 times
Been thanked: 18 times
Contact:

Re: Watchdog Reset

Postby SHORTCIRCUIT » Thu Jul 12, 2018 12:20 am

Hi Martin
Now I see it, thank you very much.
Larry

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

Re: Watchdog Reset

Postby medelec35 » Thu Jul 12, 2018 9:00 pm

You're welcome Larry,
Glad I have helped you to learn something.
These users thanked the author medelec35 for the post:
SHORTCIRCUIT (Fri Jul 13, 2018 1:46 am)
Rating: 5.88%
 
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin