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

Question regarding external interrupt

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



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

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

Question regarding external interrupt
PostPosted: Tue Mar 07, 2017 4:50 pm     Reply with quote

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

View user's profile Send private message

Re: Question regarding external interrupt
PostPosted: Tue Mar 07, 2017 11:09 pm     Reply with quote

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

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

PostPosted: Wed Mar 08, 2017 7:08 am     Reply with quote

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! Crying or Very sad Embarassed
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