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

timer1 interrupt on overflow

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ljb



Joined: 19 Nov 2003
Posts: 30

View user's profile Send private message

timer1 interrupt on overflow
PostPosted: Tue Sep 27, 2005 7:57 am     Reply with quote

My prog uses timer1 to interrupt on overflow, this increments a task counter which is tested by a case block to run the next task.

I am using an 18f2620 and trying to accomplish the following :
At the end of each task (case) I would like to test if a timer1 interrupt has occured (overflow) whilst the task was being processed. This would indicate that a task has taken longer than its alocated time and a flag could be raised.

a simplified version.

#int_timer1
void scheduler(void){
switch(--taskCntr){
case 0 : DO THIS TASK;
break;
case n : DO THIS TASK;
break;
}
TEST IF AN OVERFLOW OCCURED WHILST PERFORMING A TASK.
}

My first thought was to set a irs entered flag on a normal entry, clear the overflow interrupt and if the isr is re-entered, check the flag and clear it if the flag is already set then exit this second isr. Then on completion of the task, check the state of the flag to see if an overflow occured during the task.
Is this the best way? How do I test for an overflow ?
I hope this explanation makes sense and many thanks to anyone who can help.
Les
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Sep 27, 2005 8:07 am     Reply with quote

The PIC is interrupt mechanism is non reentrant so you cannot interrupt the PIC inside an interrupt handler of the same priority level (the 18F has two priority levels - Normal and High).

You could clear the timer interrupt flag and at the end of the switch statement test the state of the flag again to see if it is still clear. If the flag is not clear then the task ran for too long. However - you may need to use the "no clear" option on the interrupt handler to make sure the compiler does not clear it before you want it to.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
ljb



Joined: 19 Nov 2003
Posts: 30

View user's profile Send private message

PostPosted: Tue Sep 27, 2005 10:27 am     Reply with quote

Let me see if I have this straight;
If I clear the interrupt with clear_interrupt(timer1) after entering the isr, then if the isr is still running a task when another overflow on timer1 occures the interrupt flag for timer1 will be set, which I can check for at the end of the task.
Looking in the data sheet, its the TMR1IF bit that is set on overflow, is this the bit that is cleared by the clear_interrupt(timer1) instruction?
How would I check this bit? I've never checked individual bits in registers before.

Name bit 7 bit 0
PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF
^
/ \
Many thanks for your help
Les
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Sep 27, 2005 10:50 am     Reply with quote

Quote:
Let me see if I have this straight;
If I clear the interrupt with clear_interrupt(timer1) after entering the isr, then if the isr is still running a task when another overflow on timer1 occures the interrupt flag for timer1 will be set, which I can check for at the end of the task.


Correct

Quote:

Looking in the data sheet, its the TMR1IF bit that is set on overflow, is this the bit that is cleared by the clear_interrupt(timer1) instruction?
How would I check this bit? I've never checked individual bits in registers before.



Code:


Boolean InterruptStatus(long InterruptSource)
///////////////////////////////////////////////////////////////////////////
//
// Subroutine InterruptStatus
//
//   Tests the interrupt flag for the given Interrupt Type
//   Returns TRUE if the corresponding Interrupt Flag is set (event has occurred), FALSE otherwise
//
///////////////////////////////////////////////////////////////////////////
   {
   Boolean status = false;
   switch   (InterruptSource)
      {
      case INT_TIMER0 :
         status = bit_test(INTCON, TMR0IF);
         break;

      case INT_RDA :
         status = bit_test(PIR1, RCIF);
         break;

      default:
         break;
      }
   return(status);
   }

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
ljb



Joined: 19 Nov 2003
Posts: 30

View user's profile Send private message

PostPosted: Tue Sep 27, 2005 11:07 am     Reply with quote

Thats great Andrew,
I try it tomorrow.
Thanks for your help
Les
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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