  | 
	  | 
		 
	 
	
		| View previous topic :: View next topic   | 
	 
	
	
		| Author | 
		Message | 
	 
	
		
			ilker07
 
 
  Joined: 03 Jun 2022 Posts: 74
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| ccs c cannot change wdt prescaler at a run time | 
			 
			
				 Posted: Thu Dec 15, 2022 1:51 am     | 
				     | 
			 
			
				
  | 
			 
			
				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
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 15, 2022 2:42 am     | 
				     | 
			 
			
				
  | 
			 
			
				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: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 15, 2022 2:45 am     | 
				     | 
			 
			
				
  | 
			 
			
				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. | 
			 
		  | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
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
  
		 |