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

Watchdog timer is not working in 18F26K22
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

Watchdog timer is not working in 18F26K22
PostPosted: Wed Jan 15, 2014 7:09 pm     Reply with quote

Device used: 18F26K22
Problem: Watchdog Timer is not working.( gtemp1 is increasing in spite of
timeout)
Things checked : I checked the configuration bit of CONFIG2H(0000000). but register of WDTEN is not set as I want(00000011).

I think that this is problem of compiler.

Help me.
Quote:

#include <18f26k22.h>
#device *=16 adc=10 //This don't affect UART
//#device pass_strings=in_ram
#device ICD=TRUE
#FUSES WDT1
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES DEBUG //Debug mode for use with ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOHFOFST //High Frequency INTRC waits until stable before clocking CPU

//#use delay(int=16Mhz,clock=64Mhz,restart_wdt ,clock_out)
#use delay(int=16Mhz,clock=64Mhz,clock_out)

#use rs232(UART1,baud=9600,stop=1,parity=N,bits=8,errors,stream=SER1)
#use rs232(UART2,baud=19200,stop=1,parity=N,bits=8,errors,stream=SER2)
#priority RTCC,RDA,RDA2,EXT
#ZERO_RAM
#byte PORTC = 0x0f82
#byte WDTCON = 0xfd1

#include <stdio.h>

#define PTX1_SENOR PORTC,5

#use fast_io(c)

int32 gtemp1=1234567;
int1 Pinao_flage=0;
int8 Incr_flage = 0;
int16 CONFIG2H = 0;

void LEDblinking(int1);
void Increasing(int1);


void main()
{
delay_ms(10); //Waiting to remove strange dipaly of LCD.
fprintf(SER1,"%c%c", 0xa3,0x01); // Clear display

setup_wdt(WDT_ON);
//write_program_eeprom (0x300003, 0x03);
//WDTCON = 0x01;

while(true){


CONFIG2H = read_program_eeprom (0x300003);




fprintf(SER1,"%c%c%c", 0xa1,0,0);
fprintf(SER1,"UART1=%lu \r\n", gtemp1);
fprintf(SER1,"%c%c%c", 0xa1,0,1);
fprintf(SER1,"UART1=%x \r\n", CONFIG2H); // value read :0x00(0b00000000) --> I expected 0x03(0b00000011)--> This shows that Watchdog Timer is not enable.

delay_ms(2000);

Increasing(1);
}




}

//-----------------------------------------funtion----------------------------------------------
void LEDblinking(int1 Pinao_flage)
{
if(Pinao_flage==1){
output_high(PIN_A0);
}
else {
output_low(PIN_A0);
}
}

void Increasing(int1 Incr_flage) {

if(Incr_flage==1){
gtemp1++;

}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 15, 2014 7:34 pm     Reply with quote

Quote:

Problem: Watchdog Timer is not working

#include <18f26k22.h>
#device *=16 adc=10 //This don't affect UART
//#device pass_strings=in_ram
#device ICD=TRUE
#FUSES WDT1
FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES DEBUG //Debug mode for use with ICD



Read the help file for ICD2 (or any programmer) in MPLAB:
Quote:

PIC18F Limitations:

The SLEEP instruction cannot be used when debugging.

The Watchdog Timer (WDT) cannot be used when debugging.

You cannot view the stack even though you can access it.

You must connect the AVDD and AVSS pins for the device to program.

You cannot single step through an interrupt

Due to hardware restrictions the debugger/emulator cannot jump to the interrupt vector memory location in single step or animate mode.

Breakpoint can corrupt Shadow Registers
Shadow register values can be trashed if a breakpoint is set inside a routine where they are used. Store values elsewhere if you need to use a breakpoint in this situation.

Corrupted value for 16-bit mode TMR1H when single stepping
If you change the value of TMR1H in 16-bit mode, the register should only change when writing to TMR1L, but this does not happen in single step mode when TMR1L is listed in the watch window.

Since the TMR1L is listed in the watch window, it is being read from the debugger/emulator on every step. Therefore, once you change the TMR1H, on the next step a read of the TMR1L is being performed (because it is listed in the watch window), which overwrites the changed value of the TMR1H.

TMR1H is only updated upon a read or write of TMR1L in the silicon.
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 1:31 am     Reply with quote

In sipite of removing "#FUSES DEBUG", This is not working.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 1:45 am     Reply with quote

You have to get rid of everything that puts it in Debug mode. Also remove this:
Quote:
#include <18f26k22.h>
#device *=16 adc=10 //This don't affect UART
//#device pass_strings=in_ram
#device ICD=TRUE


Also make sure the Release/Debug box at the top of MPLAB is set to "Release".

Then it should work.
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 1:55 am     Reply with quote

My Compiler version: 5.017

As you give me advice , I did, but this is not working . I did not in Debug Mode.

Quote:

#include <18f26k22.h>
#device *=16 adc=10 //This don't affect UART
//#device pass_strings=in_ram
//#device ICD=TRUE
#FUSES WDT1
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
//#FUSES DEBUG //Debug mode for use with ICD
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 2:08 am     Reply with quote

Experiment. Look at the top of the .h file for your PIC. See the list of
allowable fuses there. Add the WDT fuse:
Quote:
#include <18F26K22.h>
#fuses HSH, WDT, WDT1
#use delay(clock=20M)

//========================
void main()
{

while(1);
}


Then to see what you get after it's compiled, look at the end of the .LST
file. Then you will see that finally, you get what you want (WDT enabled):
Quote:

Configuration Fuses:
Word 1: F200 HSH PLLEN PRIMARY FCMEN IESO
Word 2: 031E PUT BROWNOUT BORV19 WDT WDT1
Word 3: BF00 CCP2C1 PBADEN CCP3B5 HFOFST TIMER3C0 CCP2B5 MCLR
Word 4: 0081 STVREN NOLVP NOXINST NODEBUG
Word 5: C00F NOPROTECT NOCPB NOCPD
Word 6: E00F NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 400F NOEBTR NOEBTRB
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 3:40 am     Reply with quote

As you say, I did. So it was enable. but Pic is dead. What is the problem?
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 3:44 am     Reply with quote

I am using internal oscillator. Is this problem?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 3:07 pm     Reply with quote

If your PIC doesn't work, then go back to a simple "blink the LED"
program. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=49060&start=6
Maybe try it with the #use delay() set to 4 MHz, instead of 64 MHz.
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 6:40 pm     Reply with quote

I changed internal clock 64Mhz to 4Mhz. This works well. This is solved.
Thank you for your help.
But again in 64MHz it is not working. Can not I use watchdog timer in internal clock 64Mhz ? What is the problem ?

Code:

#FUSES WDT
#FUSES WDT1
#use delay(int=4Mhz,clock=4Mhz,clock_out)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 7:56 pm     Reply with quote

Quote:
But again in 64MHz it is not working

What is not working ? Is the blinking LED not working ?

Post your complete test program that shows the problem.
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 11:57 pm     Reply with quote

Pic is dead and not blinking.
I tested 4MHz and 64MHz. From this test, I found that For 4Mhz it is working well from WDT1 to WDT32768 but for 64Mhz it is working well from WDT16
to WDT32768. Why is it dead below WDT16 In 64Mhz clock ?
As I know , Primary clock is not related with Watchdog timer clock.
Is not Watchdog timer clock independent of primary clock?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 17, 2014 12:34 am     Reply with quote

Quote:
Why is it dead below WDT16 In 64Mhz clock ?

If you want help, post a complete test program that shows the problem.
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Fri Jan 17, 2014 2:01 am     Reply with quote

Seriously, do what PCM programmer said a few posts ago, and step 'back' to a simple flash an LED program. No WDT.

Verify that at each clock rate you are trying to use, with a one second 'flash', the LED does flash at one second intervals.

The obvious problem is that the processor is not clocking at the rate you think. So when you set it up for 64MHz, it is actually running at perhaps 16Mhz. Then when the delay_ms(10) is called, this takes much longer than expected. Long enough for the watchdog to trigger at the higher rates. I'm actually surprised it'll work at any clock rate with WDT1, or WDT2, since in both these cases the watchdog would timeout, in this delay. I suspect you think the watchdog doesn't start till you use 'WDT_ON', but this is not the case. To set it like this you need the fuse WDT_SW.
Then at 19200bps, every character you print takes basically 0.5mSec. Your prints together are going to take perhaps 12+mSec, so if the watchdog is working correctly, the code as posted can't work with a watchdog setting below 1:16.....
If you are going to use the watchdog, several things apply:

It must be restarted more frequently than the timeout interval.
Enabling a watchdog, then scattering 'restarts' through the code (including using features like the restart_wdt, in delays and serial I/O), makes enabling it pointless.
To work correctly, the watchdog must _only_ be restarted when things are all running correctly, and the restart that does this should be setup so it can only be reached if everything is running correctly.

Adding a watchdog, without proper code to control it, is pointless, and won't help your code reliability at all.
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Fri Jan 17, 2014 2:02 am     Reply with quote

I tested by three conditions(different clock and Watchdog timer prescale)

Test 1:clock 64Mz, Watchdog timer prescale: 1:16(64ms)
--> LED is blinking because Watchdog timer is restarted so that PIC is reset.


Code:

#include <18f26k22.h>
#device *=16 adc=10
#FUSES WDT
#FUSES [b]WDT16[/b]
#use delay(int=16Mhz,[b]clock=64Mhz[/b],clock_out)
#ZERO_RAM
#use fast_io(c)

void LEDblinking(int1 Pinao_flage)
{
    if(Pinao_flage==1){
         output_high(PIN_A0);   
    }
    else {
        output_low(PIN_A0);
    }
}


void main()
{

setup_wdt(WDT_ON);
[b]LEDblinking(1); //LED ON
delay_ms(5000);[/b]
}



Test 2 : clock 64Mz, Watchdog timer prescale: 1:1(4ms)
--> LED is not blinking. I don't know why.

Code:

#include <18f26k22.h>
#device *=16 adc=10
#FUSES WDT
#FUSES [b]WDT1[/b]
#use delay(int=16Mhz,clock=64Mhz,clock_out)
#ZERO_RAM
#use fast_io(c)

void LEDblinking(int1 Pinao_flage)
{
    if(Pinao_flage==1){
         output_high(PIN_A0);   
    }
    else {
        output_low(PIN_A0);
    }
}


void main()
{

setup_wdt(WDT_ON);
LEDblinking(1); //LED ON
delay_ms(5000);
}



Test 3 : clock 4Mz, Watchdog timer prescale: 1:1(4ms)
--> LED is blinking well like test 3.but period of blinking is shorter than test 3. Namely led is blinking rapidly.

Code:

#include <18f26k22.h>
#device *=16 adc=10
#FUSES WDT
#FUSES [b]WDT1[/b]
#use delay(int=16Mhz,[b]clock=4Mhz[/b],clock_out)
#ZERO_RAM
#use fast_io(c)

void LEDblinking(int1 Pinao_flage)
{
    if(Pinao_flage==1){
         output_high(PIN_A0);   
    }
    else {
        output_low(PIN_A0);
    }
}


void main()
{

setup_wdt(WDT_ON);
LEDblinking(1); //LED ON
delay_ms(5000);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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