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

INTR_CN_PIN interrupt for multiple pins

 
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

INTR_CN_PIN interrupt for multiple pins
PostPosted: Mon Nov 18, 2013 11:53 am     Reply with quote

PIC: 24HJ128GP306
PCD: 4.140

Hello,

How would I go about to have interrupt-on-change for 5 pins?

At the moment, I have the following:
Code:

#INT_CNI
void INT_B1_ISR( void )
{
//code
}

main()
{
   enable_interrupts( INTR_CN_PIN | PIN_B1 );
}

So when a change occurs on B1, then my code jumps to INT_B1_ISR. That's all fine but what I need is to detect interrupt changes on B1, B8, B9, B10 and B11 and need separate interrupt routines?

Actually, I need one routine for B1 and one separate routine for the others. When the interrupt for the others gets executed, I just want to read the 4 pins. That's it.

Not sure exactly how I'd do it therefore I am asking for perhaps a code example? CCS docs aren't very helpful at this point.

Thank you,

Benoit
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 18, 2013 12:15 pm     Reply with quote

I don't use that PIC but CCS does provide an example(in the FAQ section of Help...) a way to determine which of the PortB high 4 bits caused an interrupt.In this case a 'portB int' is flagged, in the ISR you determine which pin caused it.
If your PIC has separate INT for some pins then I would think that CCS has separate ISRs for each pin, simlar to the 18F46K22 with 2 serial ports.
A look at the device header file will show what to do.

hth
jay
benoitstjean



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

View user's profile Send private message

PostPosted: Mon Nov 18, 2013 12:35 pm     Reply with quote

Hmmm.. Thanks for the info but I'm not sure where that FAQ is in the help. I have the help file opened and searched for it but can't find it.

However, in terms of functionality, it's different on the PIC24's than the PIC18's. I've done the PIC18 int-on-change before and it was easy. This one has up to 24 different int-on-change but I don't see in the CCS help how to make use of these 24 different interrupts with different interrupt routines for each individual pins / groups of pins.

And under the #int_xxx of the CCS docs, I see this (which is, to me, very confusing and useless and inconsistent):
Code:

#INT_EX1  External Interrupt 1
#INT_EX4  External Interrupt 4
#INT_EXT0  External Interrupt 0
#INT_EXT1  External interrupt #1
#INT_EXT2  External interrupt #2
#INT_EXT3  External interrupt #3
#INT_EXT4  External interrupt #4

What's the difference between EX1 and EXT1?? I don't think that's what I need anyhow, I need #INT_CNI, but for different pins.

So anyone with good working code, please post if possible, that would help greatly.

Thanks again,

Benoit
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 18, 2013 1:39 pm     Reply with quote

hmmm... I downloaded the datasheet for the PIC ( 24HJ128GP306
) and it does have 5 external interrupt pins(35,41,42,44,45) and they all can be edge triggered. Register7-4 is the INTCON2 'control' register, 7-8 if the IFS3 register where you can set the edges... so the chip has the capability.
I'm wondering if your compiler version is too old for the chip ??
Someone who use that PIC will know and hopefully will reply soon.
I know that you'll have to create a 'handler'(ISR) for each,so it 'should' be easy. Like you said an example would be great.

cheers
Jay
benoitstjean



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

View user's profile Send private message

PostPosted: Mon Nov 18, 2013 1:48 pm     Reply with quote

Yeah but the PIC24 datasheet also states in <11.5 Input Change Notification> that <Depending on the device pin count, there are up to 24 external signals (CN0 through CN23) that can be selected (enabled) for generating an interrupt request on a change-of-state.>... That's what I want.

However, the way I do it now is on a 100ms timer, I read my inputs and store the last read state of the 4-OR'ed inputs to a variable and upon the next read, I compare to the previous and if different, then I act upon it. And when the inputs change again, then it acts upon that change.

Works for now and the fact that I read at 100ms interval somewhat acts like a debouce so that if the input is triggered by some garbage noise, then the input has to stay put for at least 100ms... static electricity and junk noise is faster than that.

Thanks for your time, it's appreciated.

Benoit
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Nov 18, 2013 1:59 pm     Reply with quote

The change notification interrupt functionality (specifically the set up function) isn't 100% supported (I'm using 4.141). For example, this compiles & works for a dsPIC33FJ256GP710A:

Code:
clear_interrupt(INTR_CN_PIN | PIN_B0 | PIN_B1 | PIN_B2 | PIN_B3);
enable_interrupts(INTR_CN_PIN | PIN_B0 | PIN_B1 | PIN_B2 | PIN_B3);


However, if you change the pin list then the compiler complains about an invalid pin, even if the pin is in fact a valid CN pin. You can get around this by directly writing the appropriate register(s) that control the CN interrupt.

The way the CN interrupt works is essentially like a configurable multi-pin interrupt-on-change. I've found through trial & error & the datasheet that the CN interrupt is very similar to the INT_RB on the 18 series PICs in that you have to read the state of the port(s) in order to clear the mismatch condition that triggered the interrupt. After that, it's up to you to determine which line(s) changed state and take appropriate action.
benoitstjean



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

View user's profile Send private message

PostPosted: Mon Nov 18, 2013 2:06 pm     Reply with quote

Thanks newguy. The way you explain it is what I though it would be, however, the CCS docs is not very good and when you start looking in the Microchip docs and you've never done any of the assembly code, is not very useful since it will still not help in my C code.

If there's a bug with this feature, I suggest you send it to CCS with details on what is the problem exactly and how to reproduce the erratic behaviour and they will look into it, they usually have good support.

Thanks again,

Benoit
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Nov 19, 2013 1:46 am     Reply with quote

Key thing as always is what the PIC can actually 'do'.

Pins that have change notification ability are marked 'CNx' on the PIC pinout.

B1, is CN3, but B8,B9, B10, and B11, do not have CN numbers, so cannot be used for change notification.

On a 'latest' compiler, CCS does correctly allow any of the CNx pins to be used, but four of the pins you want, do not support CNx, so it is not physically possible.....

I just tested code using B1,2,3,4,5, and it merrily interrupts on all five pins.

Case here of 'read the data sheet'.

On older compilers, you could only select one pin for CNx. However even here no assembly is needed. You just select one pin, then set the other bits in the CNEN registers. Just a matter of a couple of #bit defines. But still only works for the pins that can be used....

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