|
|
View previous topic :: View next topic |
Author |
Message |
Milentije89
Joined: 07 Apr 2017 Posts: 31
|
PIC 18F45K22 watchdog timer does't work |
Posted: Wed Apr 25, 2018 8:42 am |
|
|
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
|
|
Posted: Wed Apr 25, 2018 8:54 am |
|
|
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: 19537
|
|
Posted: Wed Apr 25, 2018 9:01 am |
|
|
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
|
|
Posted: Wed Apr 25, 2018 9:12 am |
|
|
Thank you both.
Now, that is a big problem... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed Apr 25, 2018 12:39 pm |
|
|
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. |
|
|
|
|
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
|