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

Interrupt on change - Pic18f27k40

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



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

Interrupt on change - Pic18f27k40
PostPosted: Wed Jan 05, 2022 5:24 am     Reply with quote

Hi guys.

I have some questions about the IOC function. Looking in the device file it says, // Constants used in ENABLE/DISABLE_INTERRUPTS() are
Code:

#define INT_IOC_B2_H2L       0x2104C210
#define INT_IOC_B3_H2L       0x2108C210
for the pins I am interested in using.

My plan was to use these in a function so as to act on the transition for each of the pins on port B after the processor detected the interrupt. My other thought is that this would provide a more flexible solution to triggering on specific pins as opposed to using something like ext_int_edge(H_TO_L).

My question & it is not clear in the help file is what should appear above the function so as to use these pin defines within the function itself.

I was thinking #INT_EXT, but not too sure.
Code:

#INT_EXT
void IOC_isr() {
       
      { 

Any guidance much appreciated.

Thanks Scott.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 05, 2022 6:49 am     Reply with quote

It's in the .h file for the PIC:
Quote:

#define INT_EXT2_H2L 0x6002C204
#define INT_EXT2 0x00C204
#define INT_IOC 0x0FFFC210
#define INT_TIMER0 0x00C220
#define INT_AD 0x00C301
#define INT_AD_THRESHOLD 0x00C302
#define INT_CSW 0x00C340
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Wed Jan 05, 2022 7:46 am     Reply with quote

And, with the knowledge that this is the Interrupt On Change interrupt,
look at the example ex_ioc.c, which shows how to enable and test which
interrupt has triggered.
scottc



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

PostPosted: Thu Jan 06, 2022 10:22 am     Reply with quote

Thanks Guys,

The example code was a big help, seems like the #INT_IOC works well.
I like the flexibility of doing the pin assign which I think generally makes using ISR's alot easier and somewhat more predictable.
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Tue Jan 18, 2022 11:09 am     Reply with quote

I could use some elaboration on this topic.

I have the same question as I'm adding a new protocol requiring IOC on B3 on three projects which are using PIC18F26K40 (same as above), 45K40, and 67K40.

The ex_ioc.c example file uses one ISR to service all IOC pins, but there are dozens of IOC capable pins on these processors. It would be too slow to handle all inside one ISR.

Using the 26K40's header as my example, when one wants to use the first serial port, the (vague) header file offers:
Code:
#define INT_RDA                   0x00C520

And in the program one creates the ISR like this:
Code:
#INT_RDA
void ui_buff_rx_isr() {
    <isr code>
}


Now here is the problem. The device header file offers this for IOC on B3:
Code:
#define INT_IOC_B3                   0x3108C210

However, when I try to use the interrupt in the same manner:
Code:
#INT_IOC_B3
void IOC_B3_ISR(void) {
    <isr code>
}
the compiler balks with the following error:
Quote:
Error#7 Invalid Pre-Processor directive


Please tell me I am making a mistake and that I do not have to test for which IOC happened inside my ISR!!! Shocked I plan to add more IOC inputs in the future and change-testing inside the ISR will simply not be fast enough.

Thanks,
Kyle
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Tue Jan 18, 2022 12:00 pm     Reply with quote

Simple answer, there is only one interrupt for the IOC.
What there are are separate flags set to say which pin has triggered the
interrupt, but you have to poll these flags.
Now the chip does have other interrupts, such as INT on RB0. If you want
separate interrupts you need to switch the using these.Even these though
the separate interrupt handlers are called by polling. There is only one
interrupt vector for _all_ the low priority interrupts, and one other for all
the high priority interrupts. In this vector the code then polls the flags to find
which interrupt has actually triggered. To have separate interrupt vectors
you have to switch to one of the DsPIC's.


Last edited by Ttelmah on Tue Jan 18, 2022 12:05 pm; edited 1 time in total
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Tue Jan 18, 2022 12:04 pm     Reply with quote

That's unfortunate. Thank you for the clarification.

For those who find this thread in the future: This is how the K40 processors actually work. There is one interrupt for change, with flag bits for the individual pins. This is not a limitation of the CCS compiler.

-Kyle
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