View previous topic :: View next topic |
Author |
Message |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
Question regarding external interrupt |
Posted: Tue Mar 07, 2017 4:50 pm |
|
|
I know this is somewhat of a silly question and perhaps I have lost my perspective on how interrupts work, specifically the external interrupt1 (#int_EXT1) I have used this many times in the past and don't recollect working the way it seems to be and perhaps I'm just missing the point or making some stupid mistake.
All I am doing is sensing a momentary switch closure which ties the input of the EXT1 (PIN_B14 on the device I am using a PIC24F16KL402) to ground, this input is tied to Vdd via a 5K resistor so when the switch closes the pin = 0V and Vdd in the normally open position.
Here is my initialization for this interrupt:
Code: |
set_tris_b(0xE347); // 0b1110001101000111
set_pullup(true, PIN_B14);
ext_int_edge(INT_EXT1, H_TO_L);
clear_interrupt(INT_EXT1);
enable_interrupts(INT_EXT1);
enable_interrupts(INTR_GLOBAL);
|
Now my interrupt routine is as follows:
Code: |
#int_EXT1
void ext1_isr(void)
{
KeyFlag=1;
FlashRed(); /// FlashRed is a simple function that I just put there just to debug this, it flashes a led for 100mS
} |
Now when the program is running and I press the switch nothing happens when I first press the switch until I release the switch, then the interrupt takes place and everything within the interrupt takes place which does not seem right as I am specifying an interrupt on an edge going from high to low and not from low to high as it appears to be working? I also tried using ext_int_edge(INT_EXT1, L_TO_H); with the same results.
All I want to do is set a flag when this interrupt occurs and then go to a debounce routine which is looking for the switch in the pressed position but the way this is working the debounce routine could never work.
Any suggestions or clues will be greatly appreciated! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Question regarding external interrupt |
Posted: Tue Mar 07, 2017 11:09 pm |
|
|
cbarberis wrote: |
Here is my initialization for this interrupt:
set_tris_b(0xE347); // 0b1110001101000111
set_pullup(true, PIN_B14);
ext_int_edge(INT_EXT1, H_TO_L);
clear_interrupt(INT_EXT1);
enable_interrupts(INT_EXT1);
enable_interrupts(INTR_GLOBAL);
|
That's not the correct syntax for the ext_int_edge() function.
The PCD Reference manual says:
Quote: | ext_int_edge( )
Syntax: ext_int_edge (source, edge)
Parameters:
source is a constant from 0 to 4.
Source is optional and defaults to 0. |
If you are using EXT_INT1, then the parameter must be 1 as shown below:
Code: | ext_int_edge(1, H_TO_L); |
|
|
|
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Wed Mar 08, 2017 7:08 am |
|
|
I should be ashamed This was clearly indicated in the PCD manual and should have been the first place to refer to before posting this message. THANK YOU PCMprogrammer! |
|
|
|