View previous topic :: View next topic |
Author |
Message |
ciccioc74
Joined: 23 Mar 2010 Posts: 30
|
pic24FJ and wdt confused |
Posted: Thu Feb 11, 2021 12:50 pm |
|
|
Hi everyone. I am trying to set the wdt for PIC 24FJ1024GB610 with Code: | #use delay(crystal=8000000,clock=32000000 ) |
I read the datasheet and the DS39697B but i just can't get it to work.
If I understand correctly I can enable WDT from HW or SW.
So if I write
and then Code: |
setup_wdt(WDT_ON |WDT_2S); |
The PIC should restart every 2S unless I write
if I want to use the wdt HW I enable
Code: | WDTCLK_31KHZ
#FUSES WDT
#FUSES WPOSTS12 |
So i should have a wdt every 2.048 sec
Where am I wrong? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Thu Feb 11, 2021 1:04 pm |
|
|
If that is the same as another chip that was posted recently, you don't
want to OR the entries for setup_wdt. Just use:
setup_wdt(WDT_2S);
and
setup_wdt(WDT_OFF); when you want to turn it off.
The value used for ON/OFF, is 0/1, and these are separate commands,
not values that can be OR'ed into the time,
They are careful to say when values can be ORed. This is not a place
where they can be.
The setup_wdt(WDT_2S); setting, automatically sets the clock and
postscaler. Then ON or OFF starts/stops it when needed. Using this
anywhere in the code results in the fuses being set to match this time. |
|
|
ciccioc74
Joined: 23 Mar 2010 Posts: 30
|
|
Posted: Thu Feb 11, 2021 1:21 pm |
|
|
Thanks Ttelmah
I had already done this test but I do not reset the micro. With other PIC of this project no problem (18f and 32MX) but it doesn't work here.
CCS rev 5.071 with MPLAB
only
Code: | #FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES BROWNOUT //No brownout reset
#FUSES NOJTAG
#use delay(crystal=8000000,clock=32000000 )
|
and in main: |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Feb 12, 2021 1:54 am |
|
|
Add as a separate line:
setup_wdt(WDT_ON);
The point is that you can't 'OR' the operations as you are trying to do.
setup_wdt(WDT_2S);
makes the compiler setup the fuses for the required time.
Then:
setup_wdt(WDT_ON);
actually enables it,
and:
setup_wdt(WDT_OFF);
disables it.
They two things cannot be OR'ed together into one line. They have
to be separate lines. |
|
|
ciccioc74
Joined: 23 Mar 2010 Posts: 30
|
|
Posted: Fri Feb 12, 2021 11:17 am |
|
|
I am only writing to communicate that I have not solved the problem with the WDT. I used a Work Around If i receive a data from slaves i reset a counter otherwise the counter increments every second
Code: | if(contWDT_1>15 && contWDT_2>15 && contWDT_3>15 && contWDT_4>15){
reset_cpu();
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Feb 12, 2021 12:51 pm |
|
|
I have to ask a question. How are you testing this?.
You do realise that the watchdog does not work in an ICD?.
I just tried a test:
Code: |
#include <24FJ1024GB610.h>
#device ICSP=1
#use delay(clock=32000000,crystal=8000000)
#FUSES WDT_SW //Watchdog timer available
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOJTAG //JTAG disabled
#PIN_SELECT U1TX=PIN_B0
#PIN_SELECT U1RX=PIN_B1
#use rs232(UART1, baud=9600, stream=SERIAL1, ERRORS)
void main()
{
int8 reason;
//Basic WDT test
reason=restart_cause();
//Start by printing a message on boot
delay_ms(100);
if (reason==RESTART_WATCHDOG)
fprintf(SERIAL1,"Watchdog restart\n");
else
fprintf(SERIAL1,"Boot\n");
setup_wdt(WDT_2S); //This actually sets the fuses for you
while(TRUE)
{
delay_ms(2500);
//If we get here the watchdog has not triggered.
fprintf(SERIAL1,"No watchdog\n");
}
}
|
and it merrily prints:
Boot
Watchdog restart
Watchdog restart
....
I hadn't got 5.071, so used 5.072. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Feb 12, 2021 4:06 pm |
|
|
re: Quote: | So i should have a wdt every 2.048 sec.
|
I was curious, looked at the datasheet.....well I think it's the right one...
LPRC is used during sleep and has a +-20% variation of the 31KHz clock.
So I sure hope he isn't counting on 2.048 seconds to be accurate.
Jay |
|
|
|