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

External interrupts on the RB?

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



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

External interrupts on the RB?
PostPosted: Thu Jun 28, 2018 5:58 am     Reply with quote

Hello,
I am working on one of my old projects that uses 18F2685, I am reading the datasheet (Chapter 9) 9.6 and 9.8.
I am intrested in button connected to either RB0 or RB4 to wake up the device from sleep, if I understod the datasheet currectly they both will do the same thing?
I also read the ccs_manual, nothing there except #INT_RB on page 153.

So my questions are:
1- What is the different between INTx Pin Interrupts (RB0, RB1 and RB2) and PORTB Interrupt-on-Change (RB4, RB5, RB6 and RB7)? Its seems as the second option is what meant for the button use?
2- How to use each in CCS compiler? An example of both to show the different technique on how to use would be great.

Thank you
temtronic



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

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 6:10 am     Reply with quote

re: Q#1 The discrete RB0, RB1,RB2 interrupts mean the RB0 ISR ONLY gets triggered by the RB0 pin. Now I don't use that PIC, but some allow the interrrupt on the edge( +ve going or -ve going or both ((IOC))), so you'll have to read your datasheet to see what's available. The PORTB4-7 interrupt requires you to read the entire port, then mask/test which pin actually caused the interrupt. CCS has example code and check the FAQ section as well as the '#INT ' section of the manual.
If you only have 2 buttons, consider what hardware configuration you need.PB0 and PB1 sound good and frees up the entire Port B for byte wide operation but only you know what's best .
Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 6:34 am     Reply with quote

temtronic,
Thank you for the reply, I actually have one button to wake up the PIC and two more button to do other things along with the first button, 10 seconds of no button press and the PIC go back to sleep. So I only interrupt on one button.

However its not clear yet as far as my question regarding the difference and uses? Why would you use one over the other and how?

Thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 7:06 am     Reply with quote

INT_RB is an _interrupt on change_. It'll trigger when the signal changes. So you will get both an interrupt on the button making, and another when it is released. Now 'big caveat' at this point. To use INT_RB for buttons, you _must_ have hardware debounce on the signal, or you will get multiple signals when the button operates. INT_RB is great for things like quadrature encoder inputs, and with suitable debounce can be used for buttons. The downside is since you don't know which button has triggered it, you have to then read the port, work out what button changed, and which way it changed. The standard INT_xx interrupts _only_ trigger on the programmed edge, and each is unique. So a separate handler is called for each signal. INT_RB triggers on every change on any input in the block it supports (some chips allow you to mask pins 'off' but the older chips don't).
INT_RB responds to any change between the p[physical 'port' and it's internal latch. The tach is set whenever you read the port. So when INT_RB triggers you _must_ read the port to reset the latch, or the interrupt cannot be cleared.

There are examples with the compiler. Look at ex_pbutt.c and ex_sk_rotary_encoder_isr.c (for interrupt on change). There are many others using the standard interrupts.
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 7:42 am     Reply with quote

Ttelmah,
Thank you for the reply,
I have hardware denounce, I have used INT_RB on RB4-RB6,
INT_xx ?
How can I use the RB0-RB2 if I only want to interrupt (from sleep) on RB0? I will use Button.c for RB0-RB2 in the main loop when the PIC is a wake.
Thank you
temtronic



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

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 7:43 am     Reply with quote

The big difference or rather why you choose one method of interrupt is based on hardware. IF B0 and B1 are available, it might be best to use them as it keeps Port B free for say byte wide uses OR perhaps there's an internal peripheral you may want to use in the near future(client's always need 'something' else...). The flipflop of this is perhaps an internal peripheral is on the B0 pin and now you need it, arrgh.
This gets down to you looking at the options and seeing what's best for your application.
As Mr. T says the PB4-7 is a nybble IOC type interrupt and needs to be coded for the PIC to 'see' which pin did the interruption. I've used both ways on several projects over the decades.
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