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

PIC24 external interrupt on edge change

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



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PIC24 external interrupt on edge change
PostPosted: Wed Feb 12, 2014 5:12 pm     Reply with quote

COMPILER: 4.141
DEVICE: PIC24HJ128GP306

Hello, just wondering if there's a way to specify the external interrupts to trigger the interrupt on a L-to-H or H-to-L transition as opposed to firing the interrupt on every state change. The code is at work right now and I'm at home so I can't check in my code but if anyone has any info in the meantime, it would be appreciated.

For the PIC16 and PIC18 devices, there is such a CCS command to specify which transition to fire the interrupt on (ext_int_edge) but that's for PIC16/18.... but in my case, I have an 8kHz clock firing an interrupt on every transition. I am reading data on a pin when the transition goes from L-to-H and I want to disregard the data and the interrupt following the H-to-L transition... but because I cannot figure-out how to disregard the H-to-L transition, I'm in the interrupt at a 16kHz rate while I only need to get the interrupt every 8kHz.

I'm using something like (that's not the exact line but similar) enable_interrupts( INT_EXT_CN, PIN_x ) that tells PIN_x to fir an interrupt on every change.... but I don't want *every* change, just the L-to-H transition.

Thanks,

Ben
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Wed Feb 12, 2014 8:24 pm     Reply with quote

I'm not sure which interrupt you are using since you didn't post the small compilable program, but PIC24 chips have two types of I/O interrupts:

Change Notification (CNI)
These interrupts can occur on any CN PIN and all CN pins that you enable will trigger the same single CNNI interrupt. These trigger on both high and low transitions

External Interrupt
These are on pins INT0, INT1, etc and are listed as INT_EXT0, INT_EXT1, etc in the compiler. These only trigger on one edge. By default, they trigger on L to H transitions. There is a function that can swap that to H to L, but you mentioned only wanting L to H.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Fri Feb 14, 2014 8:53 pm     Reply with quote

Hello (again) Jeremiah,

Thanks for your answer. I had not realized that the INT pins were dedicated external interrupts that had the edge transition flag as opposed to the interrupt-on-change as I am using (PIN B1 I believe).

I will continue to use what I have since the PCB is done. Perhaps the next rev.

Thanks again,

Benoit
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Wed Feb 26, 2014 2:26 pm     Reply with quote

Hello Jeremiah,

I had the time to implement external interrupts and it works at the moment on the L-to-H transition.

Never mind what I had said in my initial post about the fact that I wanted H-to-L transition, I changed stuff and I'm doing something different now.

Basically, my question is *which* function changes the transition and how do I specify the PIN that I want to change the transition on? I'm using 4.141 PCD for PIC24HJ series and the documentation in only for the PIC18 series.

I just downloaded the PCD documentation from their website and it's the same - no further explanations.

So, I have pins D8-D11 tied to a signal.

At the moment, when I put, let's say, D8 to high, I get an interrupt and on my display I print "PIN D8 high".

Now, instead, I need to print something when the pin goes low therefore I need to change the edge for PIN D8.

How do I do that (again, CCS manual doesn't seem to explain how to do it with PCD devices).

This is my code:

Code:
main()
{
   // some code...
   enable_interrupts( INT_EXT0 );
   enable_interrupts( INT_EXT1 );
   enable_interrupts( INT_EXT2 );
   enable_interrupts( INT_EXT3 );

   while(1);
}

I also created 4 ext_int routines:

#INT_EXT0
void INT_EXT_INPUT0( void )
{
   fprintf( MONITOR_SERIAL, "\n\rPIN D8 high" );
}

#INT_EXT1
void INT_EXT_INPUT1( void )
{
   fprintf( MONITOR_SERIAL, "\n\rPIN D9 high" );
}

#INT_EXT2
void INT_EXT_INPUT2( void )
{
   fprintf( MONITOR_SERIAL, "\n\rPIN D10 high" );
}

#INT_EXT3
void INT_EXT_INPUT3( void )
{
   fprintf( MONITOR_SERIAL, "\n\rPIN D11 high" );
}

Thanks again,

Benoit St-Jean
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Wed Feb 26, 2014 5:40 pm     Reply with quote

I haven't had to do it for a while, but I think ext_int_edge() used to be the way to do it on PCD chips. It has two params, the interrupt # (0, 1, 2, etc) and either H_TO_L or L_TO_H as the second param.

So changing EXT2 to H to L would look like:
ext_int_edge(2,H_TO_L);
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Thu Feb 27, 2014 8:42 am     Reply with quote

Yes, you are correct. The first parameter is the interrupt number. I thought I had tried this and it didn't work but maybe I did something wrong. Anyhow, CCS has work to do in their documentation.

Thanks again for your help.

Benoit
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Thu Feb 27, 2014 10:11 am     Reply with quote

I see it listed in the manual. Are you sure you have the PCD manual and not the other one? There are two different manuals out for CCS. Granted, the text descriptions could be updated some. The most recent manual is a copy paste from the "other" manual since it references PIC18, which is not part of the PCD version of the compiler.

I know it worked on the old version 4 compiler in the 4.11x area. That's the last time I used it though. If it doesn't work in version 5, make sure to report the bug to CCS.
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