Watchdog Reset

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

Moderator: Benj

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

Watchdog Reset

Post by Niro »

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

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 Reset

Post by medelec35 »

Hi Niro,
Have you tried commands within C code?

What is the target device?
Martin

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

Re: Watchdog Reset

Post by Niro »

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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Watchdog Reset

Post by LeighM »

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.

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 Reset

Post by medelec35 »

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

Martin
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Watchdog Reset

Post by electron67 »

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 342 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 Reset

Post by medelec35 »

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)
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Watchdog Reset

Post by electron67 »

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. :?:

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 Reset

Post by medelec35 »

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.
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Watchdog Reset

Post by electron67 »

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

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Watchdog Reset

Post by electron67 »

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 !!!

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 Reset

Post by medelec35 »

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.
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Watchdog Reset

Post by electron67 »

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

SHORTCIRCUIT
Posts: 155
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 40 times
Been thanked: 19 times
Contact:

Re: Watchdog Reset

Post by SHORTCIRCUIT »

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 223 times
looking forward to your reply
Larry Miranda

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 Reset

Post by medelec35 »

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.
Martin

SHORTCIRCUIT
Posts: 155
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 40 times
Been thanked: 19 times
Contact:

Re: Watchdog Reset

Post by SHORTCIRCUIT »

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

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 Reset

Post by medelec35 »

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;
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Watchdog Reset

Post by electron67 »

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: 155
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 40 times
Been thanked: 19 times
Contact:

Re: Watchdog Reset

Post by SHORTCIRCUIT »

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

SHORTCIRCUIT
Posts: 155
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 40 times
Been thanked: 19 times
Contact:

Re: Watchdog Reset

Post by SHORTCIRCUIT »

Hi Martin

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

Thank you in advance
Larry

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 Reset

Post by medelec35 »

The default values for registers can be found on page 14 - 16.
The default for WDTCON is :
WDTCON Default values.png
(44.31 KiB) Downloaded 4135 times
=
WDTCON Default values 2.png
(35.72 KiB) Downloaded 4135 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.
Martin

SHORTCIRCUIT
Posts: 155
Joined: Thu Feb 10, 2011 4:39 am
Location: Las Vegas, Nevada USA
Has thanked: 40 times
Been thanked: 19 times
Contact:

Re: Watchdog Reset

Post by SHORTCIRCUIT »

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

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 Reset

Post by medelec35 »

You're welcome Larry,
Glad I have helped you to learn something.
Martin

Post Reply