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

PIC 18F45K22 watchdog timer does't work

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



Joined: 07 Apr 2017
Posts: 31

View user's profile Send private message

PIC 18F45K22 watchdog timer does't work
PostPosted: Wed Apr 25, 2018 8:42 am     Reply with quote

PIC 1: 18F45K22 (on my product PCB)
PIC 2: 18F87K22 (on EasyPIC PRO 7 dev board)
CCS C: 5.075

Hi to you all!

I have some strange problem with WDT on 18F45K22 chip.

Here is a code that works perfectly on 18F87K22
Code:

#include <18F87k22.h>

#fuses INTRC, WDT_SW, WDT256, PUT, NOPROTECT, NOPLLEN, MCLR

#use delay(clock = 16M)
#use rs232(baud = 9600, XMIT = PIN_C6, RCV = PIN_C7)

void main()
{
   set_tris_b(0x00);
   output_b(0x00);
   
   switch ( restart_cause() )
   {
      case WDT_TIMEOUT:
      {
         printf("\r\nRestarted processor because of watchdog timeout!\r\n");
         break;
      }
      case NORMAL_POWER_UP:
      {
         printf("\r\nNormal power up!\r\n");
         break;
      }
   }
   
   setup_wdt(WDT_ON);
   while(1)
   {
      //restart_wdt();
      output_toggle(PIN_B0);
      delay_ms(500);
   }
}


WDT restarts MCU every 1024 ms. Perfect!

Here is a code for 18F45K22 that doesn't work
Code:

#include <18F45k22.h>

#fuses INTRC, WDT_SW, WDT256, PUT, NOPROTECT, NOPLLEN, MCLR

#use delay(clock = 16M)
#use rs232(baud = 9600, XMIT = PIN_C6, RCV = PIN_C7)

#include <bootloader.h>

void main()
{
   set_tris_e(0x00);
   output_e(0x00);
   
   switch ( restart_cause() )
   {
      case WDT_TIMEOUT:
      {
         printf("\r\nRestarted processor because of watchdog timeout!\r\n");
         break;
      }
      case NORMAL_POWER_UP:
      {
         printf("\r\nNormal power up!\r\n");
         break;
      }
   }

   setup_wdt(WDT_ON);
   while(1)
   {
      output_toggle(PIN_E0);
      delay_ms(500);
   }
}


As you can see I am using bootloader, and that is the only "big" difference between those two chunks of code.
WDT doesn't reset 18F45K22. It looks like it is not working at all. I can not force WDT to reset the MCU.

I have tried a lot of things:

1. Changing fuse WDT_WS to all other options - NOT WORKING
2. Deleting WDT_WS fuse - NOT WORKING
3. Changing WDTxxx fuse - NOT WORKING
4. Changing MCU with another 45K22 - NOT WORKING
5. Checked .lst file and WDT related bits are set correctly
6. I am not using ICD and DEBUG options, so it can not be a problem
7. I can't remember what else I have tried without success...

Can somebody help me with this problem?

TIA!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 25, 2018 8:54 am     Reply with quote

The key point is that you are using the bootloader for the 18F45K22.
The bootloader has its own fuses. What are the fuse settings in the
bootloader code that you initially programmed into the 18F45K22 ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Wed Apr 25, 2018 9:01 am     Reply with quote

Just to expand on this a little, the application cannot set the fuses. Your code runs with whatever fuses the bootloader has. This is why it is quite nice (to remind you of this), to use the syntax:
Code:

#include <18F87k22.h>
#fuses NONE //No fuses in the code
// bootloader: #fuses INTRC, WDT_SW, WDT256, PUT, NOPROTECT, NOPLLEN, MCLR


Now if your bootloader has go the WDT disabled, then you have your answer.
Milentije89



Joined: 07 Apr 2017
Posts: 31

View user's profile Send private message

PostPosted: Wed Apr 25, 2018 9:12 am     Reply with quote

Thank you both.

Now, that is a big problem... Mad
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Wed Apr 25, 2018 12:39 pm     Reply with quote

Problem is that if the loaded code could change the fuses, it could stop the bootloader being able to work.....
The bootloader fuses have to be what the processor uses.
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