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

disable interrupts

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



Joined: 16 Mar 2005
Posts: 13

View user's profile Send private message

disable interrupts
PostPosted: Thu Apr 21, 2005 5:11 pm     Reply with quote

Hi all

In my project I use 18f452 and its three external interrupts with three buttons(using debounce circuit).In ext interrupt routine I enable/disable other two external interrupts. Something like start/stop button.
My all program work in ext1 routine and in ext2 routine I take situation of four pins .I disable these two interrupts with this
Code:

#int_EXT
EXT_isr()
{
 if(a==1)
    {
     a=0;
     disable_interrupts(INT_EXT1);
     disable_interrupts(INT_EXT2);
     }
  else
     {
     a=1;
     enable_interrupts(INT_EXT1);
     enable_interrupts(INT_EXT2);
     }
}

and other routines
Code:


#int_EXT1
EXT1_isr()
   {
    a=1;
   output_high(PIN_C0);      //control led
  delay_ms(20);
    output_low(PIN_C0);
  delay_ms(20);
   ..
  ..
   }
#int_EXT2
EXT2_isr()
   {
    a=1;
    ..
    ..
    ..
   }

After these two interrupt routines are disabled with pressing RB0 pin, if I press RB1or RB2 button nothing happen. When I enable them with pushing RB0, the interrupt routine which I pushed starts to execute(no pushing again).
So how can I prevent this? If program is executing I want to stop it or if It is not working I want to start it. Can anyone tell me what must I do? I gave priority to these interrupts but it doesn't prevent this situation. I think The reason of this is the interrupt flag. Am I right?
Thanks for your advice

BEST REGARDS
EMRAH
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 21, 2005 7:27 pm     Reply with quote

Yes, it is the flags. You will need to clear them when you enable them. Check the manual or help file for clear_interrupt().
ariza



Joined: 16 Mar 2005
Posts: 13

View user's profile Send private message

PostPosted: Fri Apr 22, 2005 5:02 am     Reply with quote

Hi

How can I use clear_interrupt()? because I could not find anything CCS Help. Can you recommend other methods to prevent it?

Thanks for your help

BEST REGARDS
ARIZA
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Apr 22, 2005 6:02 am     Reply with quote

Your version of the compiler might not support it if it is too old. But here it is

Quote:

CLEAR_INTERRUPT( )

Syntax:
clear_interrupt(level)

Parameters:
level - a constant defined in the devices.h file

Returns:
undefined

Function:
Clears the interrupt flag for the given level. This function is designed for use with a specific interrupt, thus eliminating the GLOBAL level as a possible parameter.

Availability:
All devices

Requires
Nothing

Examples:
clear_interrupt(int_timer1);

Example Files:
None

Also See:
enable_interrupts(), #INT




If you compiler doesn't support it, then just clear the appropriate flag bits in the PIR & INTCON registers. I believe yours are all in the INTCON's but you can read the datasheet to find that out.

Quote:
Can you recommend other methods to prevent it?
No, except don't press the other buttons!
ariza



Joined: 16 Mar 2005
Posts: 13

View user's profile Send private message

PostPosted: Sun Apr 24, 2005 9:16 am     Reply with quote

hi all

If I have infinite loop inside Interrupt routine Forexample: an analog to digital conversion (a infinite loop).
Code:
#int_TIMER0
TIMER0_isr()

{
    do {
         for(i=0; i<2; ++i)
              {
                   set_adc_channel(i);
                    delay_us(10);
                    data = read_adc();
                     pc=data;
             }while(TRUE);
       }
}

//Three channel A/D conversion.

Suppose you define the Timer0 interrupt in another interrupt routine forexample ext1 and give the
Code:

#int_EXT
EXT_isr()
{
   setup_timer_0(RTCC_INTERNAL|8);
   enable_interrupts(INT_TIMER0);
   set_timer0(100);
}


Does it contain any risk or is it possible doing like this?
Thanks
BEST REGARDS!
Ariza Smile Very Happy
Ttelmah
Guest







PostPosted: Mon Apr 25, 2005 2:35 am     Reply with quote

Personally, I'd 'reorder' things a little.
Unless you ae using the timer elsewhere, why not leave it programmed to the clock rate you require outside the interrupt. So the 'setup_timer_0' routine, could be in the main. This saves a few instructions in the interrupt handler.
Then set the timer to the required count value, _clear the interrupt flag_, then enable the interrupt. You really need to clear the interrupt flag before enabling the interrupt, since the timer may well have been runnin, and the interrupt therefore may well have triggered, but not been serviced (since the interrupt was disabled).

Best Wishes
ariza



Joined: 16 Mar 2005
Posts: 13

View user's profile Send private message

PostPosted: Tue Apr 26, 2005 8:04 am     Reply with quote

Hi

Quote:
Unless you ae using the timer elsewhere, why not leave it programmed to the clock rate you require outside the interrupt. So the 'setup_timer_0' routine, could be in the main. This saves a few instructions in the interrupt handler.

I must define Timer0 in ext, in my algoritma ext interrupt routine is the importanat part something like starts and finishes all program.

Quote:
Then set the timer to the required count value, _clear the interrupt flag_, then enable the interrupt.
doesn;'t it reset my program because I do all my work in ext routine.
And when program enters in an interrupt routine, doesn't it disable other interrupts? Am I wrong?
By the
Code:
 
#int_EXT
EXT_isr()
if(x==1)
 {
   setup_timer_0(RTCC_INTERNAL|16);
   enable_interrupts(INT_TIMER0);
   set_timer0(100);
 }
else
 {
   setup_timer_0(RTCC_INTERNAL|8);
   enable_interrupts(INT_TIMER0);
   set_timer0(80);
 }
}
SOmething like this, is it possible ?
When program is executing, does it work?
Thanks...
BEST REGARDS Smile Very Happy
ARIZA
Ttelmah
Guest







PostPosted: Tue Apr 26, 2005 8:10 am     Reply with quote

When you are in an interrupt handler, the _global_ interrupt flag is dsabled, but the individual interrupts are not. If the individual interrupts were disabled, it would result in data being lost from everything like serial interrupts when you were in another handler...
Timer0, is running all the time. It's interrupt flag _will_ be set, if you have not had it's interrupt enabled. Hence you _must_ clear the interrupt before enabling it. It is not hard, the compiler supports a clear_interrupt instruction now.

Best Wishes
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