Searching \ for '[PIC]: Conflict between Timer0 and Timer1 on PIC16' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=time
Search entire site for: 'Conflict between Timer0 and Timer1 on PIC16'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Conflict between Timer0 and Timer1 on PIC16'
2002\07\24@095342 by Donovan Parks

flavicon
face
Hello,

Is there a known conflict between Timer0 and Timer1?  When I setup Timer0
and Timer1 as  free-running timers the PIC is generating a Timer1 interrupt
even though TMR1IE = 0 before I enable interrupt.  What is amazing, is that
when I print off the value of TMR1IE in the interrupt routine it is 0!
However, if I remove my code associated with Timer0 the problem stops.

Has anyone else experienced this problem?

Regards,
Donovan

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2002\07\24@100421 by 8859-9?B?1m1lciBZYWxo/Q==?=

Most definitely a programming error.  I use tmr0 together with tmr1 with
the 877 all the time, with no problems.  Send the int routine if
possible.

Omer YALHI
.....oyalhiKILLspamspam@spam@teksan.com.tr
http://www.teksan.com.tr
Tel : +90 212 613 22 00
Fax: +90 212 544 70 35


{Original Message removed}

2002\07\25@005423 by Donovan Parks

flavicon
face
Hello Omer and company,

Here is the code I am using to initialize TMR0 and TMR1 along with the
interrupt routine.

/***************************************************************************
***
Purpose: Interrupt Service Routine
****************************************************************************
**/
void interrupt IntVector(void)
{
static TMR0_Count = 0;   // track number of Timer0 interrupts

if(TMR1IF)
{
 gTimeout = TRUE;
 TMR1_LED = LED_ON;        // this LED lights!!! - why????
                                                 // TMR1IE is set to 0 in
TMR1_Init()
 TMR1IF = 0;
}
else if(T0IF)
{
 if(++TMR0_Count == TICKS_PER_SEC) // toggle heart beat every second
 {
  RB5 = !RB5;   // toggle LED to show program is alive
  TMR0_Count = 0;
 }
 T0IF = 0; // clear Timer0 interrupt flag
}

}

/***************************************************************************
***
Purpose: Initialize ports
****************************************************************************
**/
void PortsInit()
{
ADCON1 = 0x06;  // set PORTA to digital output for debugging
TRISA=0x00;
PORTA=0xFF;   // start all pins high (inverted logic LED's off)
WARNING_PIN = LOW; // warning pin, RA5, needs to start low
}

/***************************************************************************
****
* Purpose: Initialize Timer0 to interrupt at a periodic rate.
****************************************************************************
***/
void TMR0_Init()
{
CLRWDT(); // (Required before prescalar can be assigned to Timer0)
PSA = 0; // assign prescalar to Timer0
PS2 = 1; // set prescalar to 256
PS1 = 1;
PS0 = 1;
T0CS = 0; // set Timer0 for Timer mode (increment on every inst. cycle)

TMR0 = TMR0_RELOAD; // set Timer0 to generate an interrupt at a user
defined     // rate

T0IE = 1;  // enable Timer0 interrupt
}

/***************************************************************************
***
Purpose: Initialize Timer1 as a free running timer
****************************************************************************
**/
void TMR1_Init()
{
TMR1IF = 0;    // disable Timer1 interrupts
TMR1IE = 0;
T1CON = 0b001000001; // setup Timer1 as free running timer with 1:4
      // prescaler

// setup CCP module to capture mode
TRISC1 = INPUT;
TRISC2 = INPUT;
CCP1CON = 0b00000000; // disable
CCP1IF = 0;
CCP1IE = 0;
CCP2CON = 0b00000000; // disable
CCP2IF = 0;
CCP2IE = 0;
}

/***************************************************************************
***
Purpose: Initialize system and then wait for packets
****************************************************************************
**/
void main()
{
PIR1 = 0x00;  // clear all interrupt flags
INTCON = 0x00;  // disable all interrupts and then
   // set the interrupts we want enabled below

PEIE = 1;  // enable peripheral interrupts (i.e. I2C)

PortsInit();
TMR0_Init();
TMR1_Init();

GIE_ON;   // enable interrupts

while(TRUE);
}


{Quote hidden}

> {Original Message removed}

2002\07\25@064717 by Michael Rigby-Jones

flavicon
face
{Quote hidden}

Only when the ISR wasn't written properly :o)  When in the ISR, you have to
check both the interrupt flag bit and the mask bit in order to stop
servicing false interrupts e.g.

in C:
if(TMR1IE && TMR1IF)
       {
       // service timer 1 interrupt
       }

in ASM:

       btfsc   INTCON,TMR1IE
       btfss   INTCON,TMR1IF
       goto    nextint
tmr1int:
       ; service timer 1 interrupt


nextint:
       ; check for other interrupt or exit

HTH

Regards

Mike

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu


2002\07\25@070656 by 8859-9?B?1m1lciBZYWxo/Q==?=

I would definitely revise my code like this:


void interrupt IntVector(void)
{
 static TMR0_Count = 0;

 if(TMR1IE && TMR1IF)
 {
   gTimeout = TRUE;
   TMR1_LED = LED_ON;

   TMR1_Init()
   TMR1IF = 0;    // -> I would put this first thing, just before
gTimeout = TRUE;
}

 if(T0IE && T0IF)              // --> removed else added inte flg ->
definetely open to mistakes!!!
 {
   if(++TMR0_Count == TICKS_PER_SEC) // toggle heart beat every second
   {
     RB5 = !RB5;   // toggle LED to show program is alive
     TMR0_Count = 0;
   }

   T0IF = 0; // clear Timer0 interrupt flag
}
}


regards

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2002\07\25@170539 by Donovan Parks

flavicon
face
Hello,

Thanks for all the help with my interrupt routine.  Live and learn.

Thanks,
Donovan


{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...