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

ccs c cannot change wdt prescaler at a run time

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



Joined: 03 Jun 2022
Posts: 18

View user's profile Send private message

ccs c cannot change wdt prescaler at a run time
PostPosted: Thu Dec 15, 2022 1:51 am     Reply with quote

Hi everyone,

I'm getting error "Can not change WDT prescale at run-time" when calling setup_wdt(WDT_2S).

The code:
Code:

#include <18F67K22.h>

#fuses WDT_SW
#FUSES NOWDT                      //Watch Dog Timer   
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOBROWNOUT               //No brownout reset
#use delay(internal=8000000)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=RS485, errors) 

unsigned int16 a=0;

void main()
{
   output_high(pin_c5);//RS485
   
   delay_ms(1000);
   fprintf(RS485,"Start\n");
   setup_wdt(WDT_ON | WDT_2S);
   
   while(TRUE)
   {
     a++;
     fprintf(RS485,"a:%lu\n",a);
   
     restart_wdt();
     
      delay_ms(500);
   }

}

It works with WDT_1S but this way it doesn't even compile. What is the problem? I use 5.015 version.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 15, 2022 2:42 am     Reply with quote

I installed CCS vs. 5.015 and it compiles your code with no errors or warnings.

Quote:
Executing: "C:\...\PICC\Ccsc.exe" +FH "PCH_Test.c" +DF +LY -T -A +M -Z +Y=9 +EA #__18F67K22=TRUE
Memory usage: ROM=0% RAM=0% - 0%
0 Errors, 0 Warnings.
Build Successful.
Loaded C:\Program Files\PICC\Projects\PCH_Test\PCH_Test.cof.
BUILD SUCCEEDED: Thu Dec 15 00:40:51 2022


Quote:
CCS PCH C Compiler, Version 5.015, xxxxx 15-Dec-22 00:40

Filename: C:\Program Files\PICC\Projects\PCH_Test\PCH_Test.lst

ROM used: 434 bytes (0%)
Largest free fragment is 65536
RAM used: 8 (0%) at main() level
16 (0%) worst case
Stack used: 1 locations
Stack size: 31
Ttelmah



Joined: 11 Mar 2010
Posts: 19217

View user's profile Send private message

PostPosted: Thu Dec 15, 2022 2:45 am     Reply with quote

Because you can't.

The watchdog prescaler is set in the fuses.

If you code with the line:

setup_wdt(WDT_ON | WDT_2S);

then look at the list file at the fuses, you will see they are set for 2 seconds.
recompile the same code but change it to say 1 sec, and the only thing that
will change in the resulting listing, is the fuses. So from WDT512 to
WDT256.

The C line here is rather misleading. Parts of it (the part that turns the
WDT on/off), code as a line in the assembler. However the watchdog 'time'
just determines the fuse settings, so can only be set _once_ in any
program. You cannot change the watchdog time (on these chips), except
in the fuses. So the time can only be set once.

In the manual:
"Some parts do not allow the time to be changed at run time". This chip
is one of those.

I suspect PCM, he has got two time lines in the code that actually fails.
What he posted works, but if he tries to _change_ the time somewhere
in the code, it won't. So his actual failing code probably has another
line setting the time to 1Sec.

So if he has:
Code:

   setup_wdt(WDT_1S);
   output_high(pin_c5);//RS485
   
   delay_ms(1000);
   fprintf(RS485,"Start\n");
   setup_wdt(WDT_ON | WDT_2S);


It'll fail has he describes.
Or if he has a prescaler fuse setting somewhere.
On newer compilers it'll give 'WDT Postscale can only be set once', rather
than the error he currently has.
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