LORENZ529 / arduino-pinchangeint

Automatically exported from code.google.com/p/arduino-pinchangeint
0 stars 0 forks source link

Issues testing interrupts on PORT D #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Define Interrupts on pins 4 through 12... Port B & D
2. Create individual "pin3func() for every pin
3. Get some "bad" interrupts; can not get PORT B to interrupt.

What is the expected output? What do you see instead?

USING A NANO....Using the JAN 15 version 1.4

interrupt on pin 9 is CONTINUOUS; must DISABLE looking at pin 9.  Tested on a 
new HW and the same condition exists.  I believe the HW is GOOD.  

Get valid interrupts on pin 5,6,7

Interrupt on pin 4 INCORRECTLY triggers dual interrupts; 4 & 12

IS IT POSSIBLE THAT I HAVE NOT PROPERLY LOADED/POSITIONED THE CORRECT FILES???

Disabled ALL ports using the NO PORTB/C/C PINCHANGES defines and I still get 
the PB interrupts!!  They should have been masked OFF??? 

Help is appreciated.. I am now reading the additional information you have 
provided in the detailed sections.  I am off to babysit and read and will 
return later this evening.  

Thank you for providing the code.  I did NOT want to learn the details of yet 
another chip and its interrupt scheme and greatly appreciate the work you 
helped me avoid by sharing the code.

emurphyiii@mail.com

Original issue reported on code.google.com by Kestr...@att.net on 28 Jan 2012 at 1:53

GoogleCodeExporter commented 8 years ago
Hi, I wil look at this.  According to the schematic of Nano 3.0, pin 4 is 
connected to ground.  Are you sure you're using pin 4?

Original comment by m...@schwager.com on 2 Feb 2012 at 1:50

GoogleCodeExporter commented 8 years ago
Ok, one problem we have:  The PinChangeInt code is designed to work on the 
Arduino Uno / Duemilanove.  The Arduino files to convert between Arduino pin 
numbers and the ATmega328p ports are not the same on those as they are on the 
Nano.  So when you say you are working with pin 9 on the Nano, this is D6.  
Thus you must define the attachInterrupt() function in PinChangeInt  as working 
with pin 12.  Sorry about that, but I don't have a Nano :-(.  Worse, the 
digitalPinToPort(), digitalPinToBitMask(), etc. macros/functions that the 
library uses actually come from the Arduino header files, which aren't set up 
to work with the Nano.  In short, for me to modify the code to work with the 
Nano would be fairly difficult and without a Nano of my own I'm reluctant to 
work on it.  At present, it's easier (especially for me) to ask that you refer 
to the Nano schematic:  
http://arduino.cc/en/uploads/Main/ArduinoNano30Schematic.pdf , look at the pin 
you want to use in the upper left hand corner, then check to see what is the 
Arduino Uno / Duemilanove equivalent pin there (D6, D7, A3 etc.), and correlate 
that to the port using the diagram at 
http://arduino.cc/en/Hacking/Atmega168Hardware .  For example:  Pin 6 on the 
Nano is D3.  You want to attach an interrupt to pin 3, then, like this:  
PCintPort::attachInterrupt(3, &yourfunction, FALLING);  This is the same as 
PORTD, pin 3.  

Original comment by m...@schwager.com on 2 Feb 2012 at 5:10

GoogleCodeExporter commented 8 years ago
Let me know if that helps.

Original comment by m...@schwager.com on 2 Feb 2012 at 5:11

GoogleCodeExporter commented 8 years ago
Hmmm...  I've been using a nano without issue.   In your example sketch where 
you define the pin number, I use the digital pin number as labeled on the chip. 
 So, for D2, I #define Pin1 as a 2.  I have only tested this for digital input 
pins on the nano D2 - D7.  Your explanation seems harder than this.  I have the 
nano selected in the Arduino IDE and I'm on Arduino 1.0. 

Original comment by steve.ha...@gmail.com on 3 Feb 2012 at 4:40

GoogleCodeExporter commented 8 years ago
I should also note I'm still using pinchangeint v1.3.

Original comment by steve.ha...@gmail.com on 3 Feb 2012 at 5:06

GoogleCodeExporter commented 8 years ago
Abstract: IGNORE MY COMMENT 2
Interesting, Steve.  I don't know how that works, though.  If you tell the 
library to attach to D2, that's pin 32 on the Arduino.  ...Ooooh!!! I get it.  
It's the 32 pin MLF package, which has a different pinout than the 28 pin DIP- 
that's what confused me.  So, it's still pin 2 on PORT D.  The physical port on 
the Arduino never really enters into it, it's the PORT and pin (aka, "PD2") 
that count.  Thanks!

Please ignore my previous rambling.

Original comment by m...@schwager.com on 3 Feb 2012 at 4:17

GoogleCodeExporter commented 8 years ago
If your code works on 1.3, it should work with 1.4.  No structural changes were 
made inside that (theoretically) would affect the selection of pins.

Original comment by m...@schwager.com on 3 Feb 2012 at 4:19

GoogleCodeExporter commented 8 years ago
Glad to hear it's making sense.  You have a note on your Wiki under Usage
that states the nano won't work and translation is required.  If this is
all good now, you might want to update that.  It's working great for me!

Original comment by steve.ha...@gmail.com on 3 Feb 2012 at 5:33

GoogleCodeExporter commented 8 years ago
There is indeed a bug in my code.  Thanks to Ron for finding it.  The 
attachInterrupt switch statements are missing the "break" statements.  I 
believe they should look like this:

    switch (portNum) {
#ifndef NO_PORTB_PINCHANGES
    case 2:
        port=&portB;
        break;
#endif
#ifndef NO_PORTC_PINCHANGES
    case 3:
        port=&portC;
        break;
#endif
#ifndef NO_PORTD_PINCHANGES
    case 4:
        port=&portD;
        break;
#endif
    }

...I continue to investigate.

Original comment by m...@schwager.com on 13 Feb 2012 at 6:01

GoogleCodeExporter commented 8 years ago
I have 1.6beta available for download.  Let me know if it makes things better.  
I am also working on a test sketch that will hopefully uncover some of these 
things in the future.

Original comment by m...@schwager.com on 23 Feb 2012 at 6:29

GoogleCodeExporter commented 8 years ago
Thanks.  I will try this out too as I only need interrupts on Port D enabled.

Original comment by steve.ha...@gmail.com on 23 Feb 2012 at 7:49

GoogleCodeExporter commented 8 years ago
My test script is completed.  I now test with it, and with a rotary encoder 
library that I wrote.  Double the testing for double the fun!  I think this is 
completed and will mark this as Finished in a few days.

Original comment by m...@schwager.com on 28 Feb 2012 at 11:07

GoogleCodeExporter commented 8 years ago
I tested the latest version 1.7 on my nano and it is successfully reading 6 
receiver channels.  I've enabled the NO_PORTB_PINCHANGES and 
NO_PORTC_PINCHANGES flags and am using the pin state variable in my sketch.  
Thanks a bunch!

Original comment by steve.ha...@gmail.com on 29 Feb 2012 at 5:42

GoogleCodeExporter commented 8 years ago
Killer!  :-)  Thanks for the update.  Setting the flags should make for a 
fairly nice speed bump; especially it will help make the pin state variable 
accurate.

Original comment by m...@schwager.com on 29 Feb 2012 at 3:37

GoogleCodeExporter commented 8 years ago
This has been fixed for some time.  I'll stick a fork in it and call it done.

Original comment by m...@schwager.com on 25 Apr 2012 at 12:34