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 support@ccsinfo.com

Watchdog question

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

Watchdog question
PostPosted: Mon May 16, 2011 3:55 pm     Reply with quote

Hi,

I wanna use a wdt in my application. I'm using a 18F87K22 and have configured it like:
#fuses WDT1024
Now the problem is, the WDT is active before I execute setup_wdt(WDT_ON); thus I have put an explicit setup_wdt(WDT_OFF); into my code which doesn't seem to help at all.... :( Why is that? Shocked

Thanks for help!
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Mon May 16, 2011 4:25 pm     Reply with quote

My reason asking is because I wanna disable the WDT while i'm waiting for a user input. I put following in my app:
Code:
            setup_wdt(WDT_OFF);    //disable WDT while waiting for input
            fgets (in_str, PC);
            setup_wdt(WDT_ON);      //re-enable watchdog
but it doesn't work correctly, while i'm waiting for user input, the watchdog still kicks in and resets my mcu... Question
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 16, 2011 4:28 pm     Reply with quote

Quote:
I'm using a 18F87K22 and have configured it like:
#fuses WDT1024

The P18F87K22 data sheet tells you what you have to do, to enable
software control of the Watchdog:
Quote:

28.2.1 CONTROL REGISTER

Register 28-16 shows the WDTCON register. This is a
readable and writable register which contains a control
bit that allows software to override the WDT Enable
Configuration bit, but only if the Configuration bit has
disabled the WDT
.
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Mon May 16, 2011 4:37 pm     Reply with quote

Uhm, okay
I tried this:
Code:
#byte WDTCON = getenv("sfr:WDTCON")
#bit SWDTEN = WDTCON.0

and then do this to disable:
Code:
  setup_wdt(WDT_OFF);
  SWDTEN = 0;

But that doesn't seem to do it either... any clues?
Thank you!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 16, 2011 4:56 pm     Reply with quote

This program shows how to do it with vs. 4.121. The PIC will start-up
and the LED will be off for 1 second. Then it will go on for 4 seconds,
then the PIC will do a WDT reset, and the process begins again. The
LED will keep blinking: 1 second off, 4 seconds on.

I don't have an 18F87K22, but I have a PIC in same family. I tested this
on a PicDem2-Plus board (non-Rohs version).
Code:

#include <18F45K22.h>
#fuses INTRC_IO, WDT_SW, WDT1024, NOPLLEN, NOPBADEN 
#use delay(clock=4M)

//===================================
void main()
{
output_low(PIN_B0);  // LED off
delay_ms(1000);  // Wait one second
output_high(PIN_B0);   // LED on

setup_wdt(WDT_ON);  // Enable WDT. It will reset in 4 seconds.

while(1);
}
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Mon May 16, 2011 5:13 pm     Reply with quote

Weird... I haven't tried your code yet but just figured something weird out myself:
I have
Code:
#byte WDTCON = getenv("sfr:WDTCON")
#bit SWDTEN = WDTCON.0
#byte CONFIG2H = getenv("sfr:CONFIG2H")
#bit WDTEN0 = CONFIG2H.0
#bit WDTEN1 = CONFIG2H.1

and they are all 0 but the WDT still kicks in and resets the mcu... why is that? What am i missing? Shocked
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 16, 2011 5:42 pm     Reply with quote

You can't write directly to Config registers in code. The PIC data sheet
explains this in section 28.1 Configuration Bits.

CCS has a function for it:
Quote:

write_configuration_memory( )

Syntax:
write_configuration_memory (dataptr, count)

But it's totally, utterly unnecessary, since I showed you how to do it
with the #fuses statement.
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue May 17, 2011 9:53 am     Reply with quote

Having set the fuses like
Code:
#fuses WDT1024,WDT_SW
did it. I assume I had to turn on the Software switch SWDTEN in with the WDT_SW fuses switch in order to be able to switch the WDT on off with setup_wdt()
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