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

start/stop interrupt rountine

 
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

start/stop interrupt rountine
PostPosted: Tue Mar 22, 2005 3:51 pm     Reply with quote

Hi all.
I am having some serious trouble with a very simple problem abut using interrupts.
In my program I use ext,ext1,ext2,timer0 interrupts and i want to enable and disable interrupts with ext2. In ext2 routine, if my program is working(a/d conversion in timer0 interrupt), it closes all interrupts. Also if my program is not working, it activates the program. Something like start/stop A/D conversion.
Firstly i use a variable in main part like "a" and give an initial value of a=1 and also in my other interrupt routines the value of "a" is "1". When program enters ext2 routine i write:

Code:
#int_EXT2
EXT2_isr()
{ if(a==1)
  {output_high(PIN_C1);   //control led
  a=0;
  disable_interrupts(global);
  delay_ms(100);
  pc=0;   
  }

  if(a==0){
  output_high(PIN_C2);      //control led
  enable_interrupts(global);
  a=1;
  delay_ms(100);
  enable_interrupts(global);
  pc=0;
  }
}


And in main part
Code:
   for(;;)
{ output_high(PIN_C7);  // control led
   delay_ms(100);
   output_low(PIN_C7);
   delay_ms(100);}


Now is this the correct way??
Because when it enters ext2, program does not return to main part. There is no change in C7 led. Do I need to put break at the end of if parts.
And i want to cut other interrupts when Ext2 is active but also at the end of a==0 part in ext2 i want to activate forexample ext interrupt, so how can i set High/Low interrupt for ext2.
I know that if I set it high i can not activate another interrupt, is it correct ??
Note: in ext i take channel information
in
Code:
ext1
i set sample rate
in timer0 A/D conversion
in ext2 start/stop my interrupts

Thanks : Wink

Emrah
ariza



Joined: 16 Mar 2005
Posts: 13

View user's profile Send private message

PostPosted: Tue Mar 22, 2005 4:04 pm     Reply with quote

Hi all..


A correction : in notes part

Quote:
in ext1 i set sample rate



thanks Embarassed

Emrah
Ttelmah
Guest







PostPosted: Tue Mar 22, 2005 4:37 pm     Reply with quote

You must _never_ use enable_interrupts(global), inside an interrupt handler.
The interrupt hardware on the PIC, automatically disables the interrupts, when one is being responded to, _and re enables then, when the return from the handler code is executed_. By re enabling the interrupts before this point, you raise the possibility that an interrupt could interrupt an interrupt. The system can only save the registers once (which is done in the global interrupt handler), so if this happens, the original values will be lost, and the program will probably crash.
If you want to disable/enable the interrupts, set a flag in the handler, and have the main code do the disabling. You can quite happily disable/enable any individual handler inside the interrupts without problems (so 'disable_interrupts(INT_EXT', is fine).

Best Wishes
Guest








PostPosted: Wed Mar 23, 2005 12:53 am     Reply with quote

OK!! thanks for advice. But my program main part(A/D conversion) is executed in timer0 interrupt nad I want to interrupt it and after Ext2 interrupt i don't need to return where the interrupt comes. The program starts to wait another ext2 to start the program again. How can i do this?

Best regards
Mark



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

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

PostPosted: Wed Mar 23, 2005 10:43 am     Reply with quote

Not clear on what you are trying to do but you should set flags with the interrupts and handle your tasks in the main.

If you need to enable\disable global interrupts via a pin, then you will need to monitor those pins in the main loop.
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