View previous topic :: View next topic |
Author |
Message |
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
Watchdog and timer0 |
Posted: Sun Jun 25, 2006 3:55 pm |
|
|
in my running code where i use timer0 if i want to add watchdog I got a problem, timer0 stops running
and watchdog doesn't run. If i cancel timer zero code and watchdog begin running correctly. I tryed to use timer 1 or timer 2 but ive a big delay in code with them configured as timer0. Immediately after powerup if i press a key to send some bytes in rs232 i can see bitstream starting after some seconds. instead with timer0 it starts immediately.
what could be the problem?? |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Sun Jun 25, 2006 7:36 pm |
|
|
Post the smallest code segment that demonstrates the problem.
Which PIC?
Is the WDT fuse enables or software enabled?
What is your #use delay directive? _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
![](templates/subSilver/images/spacer.gif) |
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
|
Posted: Mon Jun 26, 2006 5:55 pm |
|
|
This is beginning of my working code only without watchdog:
Code: | #include <16f628A.h>
#fuses INTRC, NOPROTECT, NOPUT, NOWDT, MCLR, NOLVP , BROWNOUT
#use delay(clock = 4000000)
int count_time=0;
int acceso; //
int pulsante=0; // variabile anti debounce on-off
int premuto=0;
int sforzo=0;
int porta=0;
int prima=0;
int comparatore=0;
int attivo=0;
int errore=0;
int allarme=0;
int timeout=0;
#define INTS_PER_200MS 20 // (20000000/(4*256*256))
BYTE seconds; // A running seconds counter
BYTE int_count; // Number of interrupts left before a second has elapsed
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 60 times
if(--int_count==0) // per second.
{
if((premuto==1) || (premuto==3))
errore++;
else
errore=0;
int_count=INTS_PER_200MS;
}
}
main()
{
SET_TRIS_A(0b11111111);
SET_TRIS_B(0b11110011);
output_low(PIN_B2);
output_low(PIN_B3);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ);
//setup_wdt(WDT_576MS);
int_count=INTS_PER_200MS;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_32);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(TRUE)
{
// restart_wdt();
if(!input(PIN_B0))
delay_ms(15);
if(!input(PIN_B0) && (comparatore==255) && (attivo==0) )
{
++premuto;
comparatore=0;
attivo=255;
porta=1;
errore=0;
allarme=0;
};
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Jun 27, 2006 4:14 am |
|
|
Very simple answer.
There is only _one_ prescaler available, for _either_the watchdog (where it is used as a postscaler), or Timer0. As soon as you call 'setup_wdt(WDT_576MS);', you set the prescaler to be fed from the watchdog timer, and not from timer0.
Read the data sheet. Section 6.3.
With the prescaler used for timer0, you can only enable/disable the watchdog (not set it's rate), and it'll default to approximately 18mSec interval.
Use either Timer1, or Timer2 (the former is 16bit, and the latter has it's own independant prescaler), if you want to use a prescaler with the watchdog.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
|
Posted: Tue Jun 27, 2006 6:36 am |
|
|
ok thanks for your help.
I tryed with TIMER 1 or 2 but i had different problems. code started with some seconds of delay after power up. i can't understand why. this doesn't happen with timer 0. |
|
![](templates/subSilver/images/spacer.gif) |
|