|
|
View previous topic :: View next topic |
Author |
Message |
oliv
Joined: 04 Nov 2009 Posts: 3
|
WDT on 18f4550 |
Posted: Wed Nov 04, 2009 5:23 am |
|
|
I can't change the WDT time.
Fuses are set to WDT1024 but I haven't reset before 2mn.
Someone had already got this problem ?
Thanks
Last edited by oliv on Fri Nov 06, 2009 5:15 am; edited 5 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
oliv
Joined: 04 Nov 2009 Posts: 3
|
|
Posted: Fri Nov 06, 2009 5:15 am |
|
|
my compiler :
CCS V_4.99.2.12
and here is a code looking my principal code.
Code: | #include <18F4550.h>
#fuses HSPLL,WDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#fuses WDT1024
|
Code: |
void main (void)
{
char commande;
LED_OFF(LED1);
LED_OFF(LED2);
usb_init_cs();
lcd_init();
switch ( restart_cause() )
{
case WDT_TIMEOUT:
lcd_gotoxy(1,1);
printf(lcd_putc,"WDT restart ...");
break;
default :
lcd_gotoxy(1,1);
printf(lcd_putc,"normal start ...");
break;
}
setup_wdt(WDT_ON);
while (TRUE)
{
usb_task();
usb_debug_task();
restart_wdt();
lcd_gotoxy(1,2);
printf(lcd_putc,"prog running -");
if (usb_cdc_kbhit())
{
commande=usb_cdc_getc();
if (commande==0x09) //test watch dog
{ //
while (TRUE) //
{ //
//
} //
} //
}
delay_ms(500);
lcd_gotoxy(1,2);
printf(lcd_putc,"prog running /");
delay_ms(500);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 06, 2009 1:43 pm |
|
|
That's not a compilable test program.
But, you need to move the test for restart cause to the top of main().
Put it just after the variable declarations in main(), before any other
lines of code.
I don't think you need all that USB stuff to test the watchdog timer's
timeout period. Make a simple, complete, short test program. |
|
|
oliv
Joined: 04 Nov 2009 Posts: 3
|
|
Posted: Tue Nov 10, 2009 2:27 am |
|
|
This is the context my program need to run.
The lacking part of it is a Microchip example "ex_usb_serial".
And the restart cause is working good when WDT restart.
But WDT is already prescaling by 32000.
I can do a test prog, but I think my problem is in the configuration of the WDT.
Do you think that usb is the cause of my problem ?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 10, 2009 1:03 pm |
|
|
You didn't want to make a test program, so I made one.
I used the CCS WDT example file for the PIC18 series:
Quote: |
c:\program files\picc\examples\ex_wdt18.c
|
I kept the code in main() unchanged, but I substituted the 18F4550 and
I used your #fuses statements. You have the PLL5 fuse in your code
which means a 20 MHz crystal or external oscillator is being used.
I installed that crystal on my PicDem2-Plus board. With the HSPLL fuse,
this gives a 48 MHz oscillator frequency, so I put that frequency into
the #use delay statement.
I ran the program and I timed the Watchdog timeouts with a stopwatch.
They occur about every 4.6 seconds. The expected timeout period is
Code: |
128 x 1024
----------- = 4.23 Seconds
31 KHz
|
The internal 31 KHz oscillator has an accuracy of +/- 15%, so 4.6 seconds
is within the expected range for the WDT timeout period. So, it's working.
Code: |
#include <18F4550.h>
#fuses HSPLL,WDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#fuses WDT1024
#use delay(clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//=========================================== |
This was tested with vs. 4.099 of the compiler. |
|
|
|
|
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
|