Number of external interrupts for PIC  - Page 1
Forum section: electronics / general

author: ASG
author_rank: Newbie
timestamp: May 25, 2014, 08:52:21 am
content: HiI'm working on a project where I've 9 sensors outputting a true/false signal. A PIC microcontroller receives these as inputs to external interrupt pins for handling and triggering other operations. The problem is that I don't know if there's a PIC microcontroller, 8-bit preferably, that has as many external interrupt pins as required. I tried Microchip's parametric search but there's not an option to adjust the number of external interrupts.What do you suggest?

author: Psi
author_rank: Super Contributor
timestamp: May 25, 2014, 09:30:51 am
content: Do you really need to sample the sensors that fast or will polling the input pins work fine?Interrupts are really only for time critical things.

author: ASG
author_rank: Newbie
timestamp: May 25, 2014, 10:23:09 am
content: You reminded me of polling. Yes, it may work. The problem is that I still don't have a full picture of the logic for the system that I'm working on. I'm building a three-level parking structure like the one in the picture below. Each parking slot has three sensors, an IPS installed at the center of the platform to detect the existence of a car, and two through-beam sensors installed at the edges of the entry and exist point to make sure that the parked car is not crossing the limits of the parking platform. Three sensors per parking slot and three slots make a total of 9 sensors.I thought that if each sensor has a corresponding external interrupt on the mcu, the program would be easier to write. There could be a method that the 9 sensors share 3 external interrupts, where each interrupt correspond to one type of the three sensors, since the system is designed in such a way that no more than three sensors would change state at a time. However, in this case, the program may be more difficult to write because another method must be devised to decide on which level/platform a given sensor has changed state.

author: Mechatrommer
author_rank: Super Contributor
timestamp: May 25, 2014, 10:38:57 am
content: Quote from: ASG on May 25, 2014, 10:23:09 amprobably no. your picture is not timing critical. use polling and save your arse and precious time. the mcu can do thousands of check per second and give warning in less than a blink of a eye. if you are thinking sleeping mcu to save battery and then to be woken up by interrupt then you are rational.

author: Rerouter
author_rank: Super Contributor
timestamp: May 25, 2014, 10:57:50 am
content: use some capacitors and some diode logic, so whenever a sensor goes positive it gets coupled by the capacitor, through the diode and hits on the rising edge interrupt,this is what i would say to look at for the limit sensors on the outside, if a car that is not on the lift level suddenly breaks the sensor i would want the system to make me aware quickly by immediately polling the changethough the other look is that polling is more than fine, and can take less than a microsecond to read in a port register and a pin (9 on an 8 bit micro) the other thing is short of a fault condition (e.g. hand brake not applied and car in neutral) nothing but the level with the lift can be expected to change, so you could well use a de-mux chip to switch between 3 interrupts if you still wished to use them,

author: dannyf
author_rank: Super Contributor
timestamp: May 25, 2014, 11:01:02 am
content: QuoteDepends on what you mean by "external interrupts".There are "interrupt" pins (typically 1 - 3 of them). They can be triggered by edges or level.There are also interrupt-on-change pins (usually 8 of them), or change-notification pins. They can be triggered by edges only.If that's not enough, you can configure the timers as counters and use their timer / counter input pins. Comparators can do the same as well.More complicated solutions are possible if the above isn't enough.

author: dannyf
author_rank: Super Contributor
timestamp: May 25, 2014, 11:05:45 am
content: QuoteYou could OR the error / fault conditions and use that to level-trigger an interrupt. In the isr, you can read all 9 sensors and display which sensors are faulty.

author: westfw
author_rank: Super Contributor
timestamp: May 26, 2014, 06:14:48 am
content: 1) It will also depend on which PIC family you're talking about. PIC16/18 typically has one 8-bit port worth of "port change" interrupts and a couple of "external interrupt" pins, while PIC24 may have ALL of the GPIO pins capable of generating "input change notification" interrupts, for example.2) pic16/18 will be limited to one or two interrupt vectors regardless of how many pins can interrupt, and you'll have to do some vectoring in software.

author: aboodi
author_rank: Contributor
timestamp: May 26, 2014, 12:11:11 pm
content: Quote from: dannyf on May 25, 2014, 11:05:45 am+1

author: SL4P
author_rank: Super Contributor
timestamp: May 26, 2014, 01:49:51 pm
content: Quote from: dannyf on May 25, 2014, 11:05:45 am+1 This isthe right wayto handle a problem like this.Theonlything you don't get is the weak internal pull-up on the extra pins

author: H.O
author_rank: Frequent Contributor
timestamp: May 28, 2014, 10:24:33 am
content: QuoteI've personally never seen a PIC with a level triggered interrupt, care to enlighten me?QuoteYes, usually 8 but there's certainly no shortage of device with more than 8. The 16F1829 have 10 IOC capable pins which can be set to trig on rising, falling or both edges and the 16F1716 have 25 - for example.QuoteI agree, IF you don't have a device with enough interrupt pins of course. If you DO have the needed interrupt capabillity why waste 9 diodes when you STILL have to connect all the sensors to individual I/O pins?Another option could be to use an IO expander chip with interrupt capabillity but again, the most straight forward is probably to just connect the sensors and use IOC.

author: 22swg
author_rank: Frequent Contributor
timestamp: June 02, 2014, 08:11:19 pm
content: An MCP23017 would give you 16 programmable interrupts multiplexed to one pin , you would have to read the Registers to see which pin . (I2C or SPI)

author: macboy
author_rank: Super Contributor
timestamp: June 03, 2014, 04:32:37 pm
content: Quote from: SL4P on May 26, 2014, 01:49:51 pmThe way you emphasizedthe right wayyou seem to think this is the only right way. Wrong. There are many good ways to handle the issue of multiple devices needed interrupt servicing, and tying all to a single interrupt input is not always the right way. The main issue with this is the extra time spent, at interrupt level, reading status registers from every single device attached to that interrupt pin, for every interrupt that occurs. This adds processing time, and more importantly, interrupt latency for all attached devices. In my opinion, this isoneright way, but it israrely"the"right way.

author: SL4P
author_rank: Super Contributor
timestamp: June 03, 2014, 11:52:36 pm
content: Quote from: macboy on June 03, 2014, 04:32:37 pmFair comment / observation - but I didn't say the ONLY way.In the scope of the OP's original question - I felt it was the cleanest, simplest, most cost-effective way of addressing the problem that the OP was facing.