-1

I used TIMER1 in PIC12F675 with overflow interrupt and the time for over flow around 0.5 sec and in simulation its true

the code of overflow interrupt FUNCTION :

void interrupt int_tmr1(void) {
if((PIE1&(1<<0))&&(PIR1&(1<<0))) //TMR1 OVERFLOW CONDITION 
{
         GPIO^=(1<<0); //TOGGLE LED 
       PIR1&=~(1<<0); //CLEAR TMR1 INTERRUPT OVER FLOW FLAG
}

}

but if i want to increase the duration by editing in the interrupt function like that :

void interrupt int_tmr1(void)
   {
      if((PIE1&(1<<0))&&(PIR1&(1<<0))) //TMR1 OVERFLOW CONDITION
      {
         static unsigned char count=0;
          if(count>10)
         {
          GPIO^=(1<<0); //TOGGLE LED 
           count=0;
          }

    else
    {

   count++;

     }

    PIR1&=~(1<<0); //CLEAR TMR1 INTERRUPT OVER FLOW FLAG
     }

 }

the required time is 5sec but in simulation the time is 6 sec what does that mean ?

vader
  • 889
  • 8
  • 22
  • 1
    It's not clear what your question is or what your problem is. So you've added a counter which requires 10 interrupts to fire before it toggles the LED. What is not happening the way you want it to? What is 5 seconds versus 6 seconds? Where is your timer setup code? Etc. – Ross May 10 '18 at 13:07

1 Answers1

1

you said around 0.5 seconds, which implies that it's not exactly 1/2 second. You are checking >10, which means it has to count up to 11. So at 0.5seconds, you have a delay of 5.5seconds, but again, I'm sure its something like 0.525sec.

Joe Thomas
  • 325
  • 1
  • 7