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

External Interrupt 18f4550

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



Joined: 30 May 2009
Posts: 6

View user's profile Send private message

External Interrupt 18f4550
PostPosted: Thu Nov 14, 2013 5:18 am     Reply with quote

I'm using a external interrupt and i'd like to know if is possible when the edge is low to high do something otherwise (border high to low) do another thing.

Thanks.

I know how to use for one case, but i need both.
Code:

enable_interrupts(global);
enable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);   

#int_ext
void interrup()
{
   function_a();      
}

funcion_b ???



Thanks
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu Nov 14, 2013 11:15 am     Reply with quote

you can switch edge triggers for the ext interrupt... i don't know what side effects this might have on your PIC, read the datasheet.

another possibility is to use the "interrupt on change" instead of the EXT int...

you could have a an ISR+Flag+Switch() combo that essentially does one thing on HItoLO and another LOtoHI...

in either case... Keep your ISR short.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
younder



Joined: 24 Jan 2013
Posts: 53
Location: Brazil

View user's profile Send private message

PostPosted: Thu Nov 14, 2013 6:10 pm     Reply with quote

I would try something like that:

Code:

enable_interrupts(global);
enable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);   

#int_ext
void interrup()
{
   Rise_Edge=!Rise_Edge;

      if (Rise_Edge) ext_int_edge(H_TO_L),Flag_Function_A=1; else ext_int_edge(L_TO_H),Flag_Function_B=1; 

   clear_interrupt(INT_EXT);
}

If (Flag_Function_A) ... Flag_Function_A=0;
If (Flag_Function_B) ... Flag_Function_B=0;


I'm not sure if that will works, maybe you test and let us know...
_________________
Hugo Silva
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Fri Nov 15, 2013 1:58 am     Reply with quote

Thing is that you may miss an edge at the start, if the signal is high to begin with. So:
Code:

   //In main
   if (input(PIN_B0))
       ext_int_edge(H_TO_L);
   else
       ext_int_edge(L_TO_H)   
   clear_interrupt(INT_EXT);
   enable_interrupts(global);
   enable_interrupts(INT_EXT);


//interrupt
#int_ext
void edge_handler(void)
{
   if (input(PIN_B0))
   {
       ext_int_edge(H_TO_L);
       //code for the high state

   }
   else
   {
       ext_int_edge(L_TO_H);
       //code for the low state

   }
   //common code for both states.

}

Repeat Gabriel's comment about the ISR. Generally calling functions here is a 'bad sign'. If the ISR is so complex that this is needed (except as a way of making the code more logical), then it is almost certainly longer than it should be.....

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