CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F47K42 and WDT

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PIC18F47K42 and WDT
PostPosted: Sat Mar 21, 2020 11:28 am     Reply with quote

Using the PIC18F47K42 I would like to use the WDT selectively.

So I figured I need to set the FUSE
and the first thing in main() switch off the WDT as example below.
Code:

#include <18F47K42.h>
#FUSES WDT

void main()
{
  setup_wdt( WDT_OFF );  // does not stop the WDT it resets the cpu

  rest of code here....
}


However the code just does a reset about once per second.

How to selectively enable / disable the WDT ?

Here is code I would like to use:

Code:

#include <18F47K42.h>

#fuse WDT

#use delay(clock = 12000000, crystal = 12000000)

void main()
{
     int32 g_n32WDTCounter=0;
     
     setup_wdt( WDT_OFF );   

         

     enable_interrupts(GLOBAL);

     /////////////////////////////////////////////////////////////////////
     // eventually using DS32KHz as SOSC as a more accurate clk for the WDT
     setup_wdt( WDT_ON | WDT_1S | WDT_WINDOW_100_PERCENT | WDT_CLK_31000);
     
    // at some point in future code call this....
     do{

        restart_wdt();
                   
        sleep( SLEEP_FULL );
        delay_cycles(1);// nop after sleep
       
        output_toggle( PIN_B3 ); // for scope monitoring       
       
        g_n32WDTCounter++;
     
     }while( g_n32WDTCounter < 30 ); // about 30 seconds   
       
     setup_wdt( WDT_OFF );   
     reset_cpu();         
}


What is it I'm not understanding about the WDT !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 21, 2020 12:52 pm     Reply with quote

You have to turn off the hardware enable, to let the software
enable/disable work. Example:
Quote:

#FUSES NOWDT
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sat Mar 21, 2020 1:02 pm     Reply with quote

Key thing is the line in the data sheet (registers 5-5), where the options
that enable the watchdog in the fuses all have the note: 'SWDTEN is
ignored'.
So as PCM_Programmer says if you want software control of the WDT,
you can't turn it on in tghe fuses....
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Thanks for the help
PostPosted: Sat Mar 21, 2020 4:54 pm     Reply with quote

Thanks for the help.
I've tried several combinations of FUSES but still can make it work.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 21, 2020 5:35 pm     Reply with quote

I assume you mean "still can not" make it work ?

Post your current test program.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 21, 2020 6:30 pm     Reply with quote

just a comment...

you should not enable interrupts without 'handlers' ( ISRs)...

your program enables the 'global', so if the 'wizard' has enabled specific interrupts, unknown to you... they WILL cause you random problems....I don't know if you use the 'wizard' or other 'helper' butone programmer's idea of defaults won't ever be what you KNOW the 'defaults' need to be....
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Sat Mar 21, 2020 7:50 pm     Reply with quote

PCM programmer wrote:
I assume you mean "still can not" make it work ?

Post your current test program.


Thanks PCM P I meant cannot make it work... But I did and it's going ok now...
Thanks for the help.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 22, 2020 2:38 pm     Reply with quote

I have to wonder why an 'accurate' WDT is needed ?
WDTis only enabled after final program is made and then 'timeout' is usual computed as 1.2 - 2 x a 'failsafe' value.
Say main() does everything and updates a 'flag' about 5 second interval. WDT could be set to 7-10 seconds.
There's probably no need for subsecond accuracy.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon Mar 23, 2020 2:26 am     Reply with quote

What he is trying to do, is reasonable. The way to use the WDT, with
SOSC, is:
Code:


#define WDT_SOSC 0x2000


   setup_wdt( WDT_ON | WDT_1S | WDT_WINDOW_100_PERCENT | WDT_SOSC);

By default the standard settings only support operation off the 31K, or
31K25 internal clock.

This correctly puts 0x27 into the 0x395C register, to select SOSC.

There are always individual settings that get 'missed' like this, and
you just have to create the extra settings when this happens.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group