View previous topic :: View next topic |
Author |
Message |
Vern Hardingham
Joined: 27 Jan 2017 Posts: 3 Location: Canada
|
Watchdog timer on PIC24F |
Posted: Fri Jan 27, 2017 2:32 pm |
|
|
I have:
Code: | #fuses WPOSTS4, NOWINDIS, NOWDT, ICSP1, NODEBUG, NOWRT, NOPROTECT, NOJTAG
#fuses HS, DISUVREG, NOIOL1WAY, OSCI0, NOCKSFSM, PR, PLL3, NOIESO
#use delay(crystal =12M, clock=32M, USB_FULL)
setup_wdt(WDT_512MS);
while(TRUE)
{
restart_wdt();
delay_us(1);
} |
When I compile and run, the processor just keeps resetting.
Can someone help me with this? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Jan 27, 2017 3:08 pm |
|
|
Some more basic info needed:
What actual processor?.
What compiler version?.
Show the basic 'main' containing the code. |
|
|
Vern Hardingham
Joined: 27 Jan 2017 Posts: 3 Location: Canada
|
|
Posted: Fri Jan 27, 2017 5:01 pm |
|
|
The processor is PIC24FJ256GB106
Compiler is CCS PCD IDE v 5.067
Code: | void main()
{
extern GeneratorStates curState;
initialize();
GATE = OFF;
TXKEY = OFF;
PWRCTL = ON;
init_SPI();
ad9833Reset();
init_UART();
displayInit();
displayClear();
delay_ms(1);//without delay here first line does not indent properly
displayCurOff();
displayStartup();
delay_ms(144);
usbstate = USB_INST;
TRISC = 0b10010000;
CS_DAC = 1;
CS_MEM = 1;
SPI_SCK = 1;
delay_ms(1000); // hold startup screen for 1 second
displayClrLn(3);
displaySetcurpos(3, 4);
printf(displayWrite, "Calibrating");
DACcal();
DACunbufsetlvl2(0x00);
reset_FLASH();
unlock_FLASH();
displaySetcurpos(3, 4);
beep(100);
pwrTmr = PWRTIMEOUT;
SECONDS_TMR = ON;
curState = GEN_STARTUP_DISPLAY;
// Enable Watchdog timer here
setup_wdt(WDT_512MS);
while (TRUE)
{
// Reset the watchdog timer here
restart_wdt();
delay_us(1);
// StateMachine_Update();
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 27, 2017 5:32 pm |
|
|
Also, are you running this with an ICD in Debug mode ? |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Fri Jan 27, 2017 9:03 pm |
|
|
Replace #FUSES NOWINDIS with #FUSES WINDIS
Otherwise, just about every time you call the WDT reset, you will reset the PIC. NOWINDIS enables windowed mode for the WDT. You normally don't want that.
Last edited by jeremiah on Sat Jan 28, 2017 9:25 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sat Jan 28, 2017 1:42 am |
|
|
As a comment:
TRISC = 0b10010000;
You are aware that the registers on a PIC24, are 16bit wide, not 8bit?. |
|
|
Vern Hardingham
Joined: 27 Jan 2017 Posts: 3 Location: Canada
|
|
Posted: Mon Jan 30, 2017 11:50 am |
|
|
Thanks Jeremiah, changing to WINDIS got it working. I guess I was thinking that NOWINDIS meant no windowing but actually means no windowing disable whereas WINDIS means disable windowing.
Also thanks Ttelmah, I'll look into the TRISC. I guess I must only be using the low 8 bits otherwise this would cause problems. Where I want to access just 8 bits of TRISB I have defined TRISBH and TRISBL as the 8 bit portions of the register. |
|
|
|