Go Down

Topic: ooPinChangeInt library released: Pin Change Interrupts, object style (Read 3891 times) previous topic - next topic


Announcing the release of Version 1.02 of the ooPinChangeInt library.  Though labeled "1.02", this is actually the maiden release of this library.  See it at http://code.google.com/p/oopinchangeint/ .

The ooPinChangeInt library was derived from the PinChangeInt library (http://code.google.com/p/arduino-pinchangeint/), but it features a more object-oriented approach.  It allows you to call an object's method rather than rely on a C-style function attached to an Arduino pin.  See the included examples for more details.

The ooPinChangeInt library implements Pin Change interrupts for the Arduino environment. This library was designed for the Arduino Uno/Duemilanove. It will likely work with other ATmega328- or ATmega168-based Arduinos; it has been reported to work just fine on the Nano. It will probably not work on the Arduino Mega without some serious updating.

What are Pin Change interrupts? The ATmega328p processor at the heart of the Arduino has two different kinds of interrupts: "external", and "pin change". There are only two external interrupt pins, INT0 and INT1, and they are mapped to Arduino pins 2 and 3. These interrupts can be set to trigger on RISING or FALLING signal edges, or on low level. The triggers are interpreted by hardware, and the interrupt is very fast. On the other hand there are only 2 such pins on the ATmega328p in the Arduino Uno and Duemilanove.

On the other hand the pin change interrupts can be enabled on any or all of the Arduino's signal pins. They are triggered equally on RISING or FALLING signal edges, so it is up to the interrupt code to set the proper pins to receive interrupts, to determine what happened (which pin? ...did the signal rise, or fall?), and to handle it properly. Furthermore, the pin change interrupts are grouped into 3 "port"s on the MCU, so there are only 3 interrupt vectors (subroutines) for the entire body of 20 pins. This makes the job of resolving the action on a single interrupt even more complicated. The interrupt routine should be fast, but complication is the enemy of speed. The ooPinChangeInt library is designed to handle the Arduino's pin change interrupts as quickly and reasonably as possible.


Announcing the release of version 1.03 of the ooPinChangeInt library. From the release notes:

Added MEGA support, as per PinChangeInt. This support has not been tested in this library; if you do use it with the MEGA please let me know. See the Google Code site for more information. Thanks.

Modified to not delete() pins that get detachInterrupt()'ed. Now when you detachInterrupt(), the PORT just disables interrupts for that pin; the PCintPin object remains in memory and in the linked list of pins (possibly slowing down your interrupts a couple of micros).  You can reenable a detached interrupt- but you must do it within the PinChangeInt library (would anyone ever enable an interrupt on a pin, then disable it, then have need to reenable it but not using the library?).

Optimized the interrupt handler with code from robtillaart to take out the checks for changed pins from the while() loop that steps through the pins.

Other bugfixes that follow the PinChangeInt-2.17beta release:

1. PCintPort::curr bug. In the interrupt handler PCint(), we loop as long as PCIFR indicates a new interrupt wants to be triggered, provided DISABLE_PCINT_MULTI_SERVICE is not defined (it is not by default).  Fixed so that if a pin causes the PCIFR to change, we reread the port and look at how it is now.
2. attachInterrupt() now returns an int8_t value:  1 on successful attach, 0 on successful attach but using an already-enabled pin, and -1 if the new() operator failed to create a PCintPin object.
3. Created the enable() method.


possibly slowing down your interrupts a couple of micros.

You could remove the object from the list and add it to a 'disabled' list. If added again it is moved back to the 'enabled' list.
Should be faster and yes a bit more complex (footprint).
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


Yeahhh... next version, I guess. We'll see how complicated it gets to do.


Announcing Release 1.06-rc2 of the ooPinChangeInt library.

This release incorporates a fix from JRHelbert for the Arduino MEGA platform, such that Arduino pins 14 and 15 (on PORTJ) now should work properly. This fix has not been tested, unfortunately, although the code is simple enough that I have high hopes that it works out of the box.

Let me know if you notice any issues.

As usual, the website is at http://code.google.com/p/oopinchangeint/ but the source code is now on Github, and Downloads are not on Bintray.

This code will not work with the Due (not to be confused with the Duemilanove), because the Due is based on an ARM Cortex CPU. For that you simply use the attachInterrupt() function.


@GreyGnome Has there been any update of the ooPinChangeInt library that supports Arduino MEGA?

I've seen the PinChangeInt, but I do not know if it is the same with ooPinChangeInt?

Go Up