View previous topic :: View next topic |
Author |
Message |
snash
Joined: 30 May 2009 Posts: 6
|
External Interrupt 18f4550 |
Posted: Thu Nov 14, 2013 5:18 am |
|
|
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
|
|
Posted: Thu Nov 14, 2013 11:15 am |
|
|
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
|
|
Posted: Thu Nov 14, 2013 6:10 pm |
|
|
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: 19559
|
|
Posted: Fri Nov 15, 2013 1:58 am |
|
|
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 |
|
|
|