Timer Interrupt Question

Status
Not open for further replies.

mrrmot

New Member
Hey everyone,

I'm writing a program in CCS. I have a timer that causes an interrupt every x mikrosec. I'm using the built-in functions, and wanted to know: Do I need to explicitly clear the interrupt flags, when an interrupt occurs, to prevent that another interrupt occurs during the execution of the service routine? Or do the flags get cleared automatically?

Tnx in advance!
 
Yep you sure do need to clear it, also disable it, when your code is completed for the interrupt, re-enable the interrupt bit.



-BaC
 
Last edited:
I AM NOT SURE, BUT I THINK THAT I READ SOMEWHERE THAT THE CCS TIMER FUNCTIONS CLEAR THE INTERRUPT FLAG AUTOMATICALLY.

DOES ANYONE WITH CCS EXPERIENCE KNOW ANYTHING ABOUT IT?

OOOH, I FORGOT TO ASK SOMETHING ELSE. WHILE THE INTERRUPT SERVICE ROUTINE IS EXECUTING, DOES THE TIMER CONTINUE TO WORK. I MEAN, DOES THE TIMER CONTINUE TO INCREMENT EVEN DURING THE SERVICE ROUTINE?

SO MANY THANKS IN ADVANCE

sorry for the caps lock, noticed it too late.
 
It is very unlikely that the compiler will clear the interrupt flags as you, the programmer, need to know what caused the interrupt. During the interrupt the GIE flag does get cleared to prevent any interrupts during the interrupt and is automatically set when the ISR is finished. The timer carries on running during the interrupt.

Mike.
 
I highly doubt that it will clear it for you. Yes, the timer keeps running that is why you need to disable it and re-enable it when your interrupt routine is complete, along with clearing the bit of course.

EDIT: humm I should have pressed refresh before I posted...sorry Mike..lol

-BaC

 
Last edited:
CCS will clear the interrupt flag

The CCS works bit differently it has "internal" interrupt function that
- detect what interrupt happened
- call your function (you mark your interrupt functions with #int_xxx (xxx is name of interrupt, check doc)
- clear the flag and do the other standard cleanup

Look at the examples folder and you will find many examples of how to use interrupt in CCS .. here is a simple example:
Code:
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

long rise,fall,pulse_width;

#int_ccp2
void isr()
{
   rise = CCP_1;
   fall = CCP_2;
   pulse_width = fall - rise;     // CCP_1 is the time the pulse went high
}                                 // CCP_2 is the time the pulse went low
                                  // pulse_width/(clock/4) is the time
                                  // In order for this to work the ISR
                                  // overhead must be less than the
                                  // low time.  For this program the
                                  // overhead is 45 instructions.  The
                                  // low time must then be at least
                                  // 9 us.
void main()
{
   printf("\n\rHigh time (sampled every second):\n\r");
   setup_ccp1(CCP_CAPTURE_RE);    // Configure CCP1 to capture rise
   setup_ccp2(CCP_CAPTURE_FE);    // Configure CCP2 to capture fall
   setup_timer_1(T1_INTERNAL);    // Start timer 1

   enable_interrupts(INT_CCP2);   // Setup interrupt on falling edge
   enable_interrupts(GLOBAL);

   while(TRUE) {
      delay_ms(1000);
      printf("\r%lu us ", pulse_width/5 );
   }
}
 
Last edited:
BaCaRdi & Pommie, thanks for the information on the timer. I wrote a simple code that proves you were right.

arhi, thanks very much. Turns out the CCS really does take care of the flags automatically.
 
Last edited:
No Kidding, sorry to waste your time in that case.

But, in our defense that is not a common feature. Usual you want to control that process in the code itself. I guess other or just more granular in their design.

-BaC

BaCaRdi & Pommie, thanks for the information on the timer. I wrote a simple code that proves you were right.

arhi, thanks very much. Turns out the CCS really does take care of the flags automatically.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…