qduino interrupts

for a little background, I am new to Arduino but not to programming or microcontrollers. I’ve been working on embedded products for many years and thought I would take a look at Arduino out of curiosity.

With that out of the way, my question has to do with the Qduino mini and interrupts. I have some test code posted below that connects an IR phototransistor to D3 and measures the time of a positive pulse and then sends the time (in milliseconds) and a running pulse counter to the serial port. The signal input is verified on my oscilloscope to be nice and clean without any bounce.

The posted code works. The problem is, I don’t understand why it doesn’t work for the remaining INT pins for the Qduino(INT1, INT2 or INT3). The other pins trigger the ISR on any edge, multiple times. I should only get a printout when single positive pulse completes LOW to HIGH and back to LOW. With INT1, 2 and 3 the printout occurs on the rising edge, the falling edge and the pulse counter will jump many counts instead of incrementally.

Does anyone know why?

#include "Arduino.h"
#include "Wire.h"
#include "Qduino.h"

qduino q;  // initialize the library


//IR detector pin on INT0, only interrupt that works correctly to detect edges
const int   IR_pin    = 3;        //3 works
//problems using INT1, INT2 and INT3



// Variables will change:
volatile int shots = 0;
volatile unsigned long time_of_shot = 0;
volatile unsigned long timing_start = 0;
volatile int update_display = 1;


void setup()
{

  q.setup();

  pinMode(IR_pin, INPUT_PULLUP); 
  
  pinMode(13, OUTPUT);    // Blue user LED for heart beat
  pinMode(10, OUTPUT);    // Red user LED for debug
  digitalWrite(10, HIGH); //off

  attachInterrupt(digitalPinToInterrupt(IR_pin), rising_isr, RISING);
  
  Serial.begin(9600);
  while(!Serial);  // wait for Serial port to be opened
  Serial.println("interrupt demo");

}

//////////////////////////////////////////////////////////////////////////////////


void rising_isr(){

    //disable interrupts before reinitializing ints

    
    detachInterrupt(digitalPinToInterrupt(IR_pin)); 
    timing_start = millis();
    attachInterrupt(digitalPinToInterrupt(IR_pin), falling_isr, FALLING);
  }


  
void falling_isr(){

    detachInterrupt(digitalPinToInterrupt(IR_pin)); 
    time_of_shot = millis() - timing_start;
    shots++;
    update_display = 1;
    attachInterrupt(digitalPinToInterrupt(IR_pin), rising_isr, RISING);
  }
  
  


///////////////////////////////////////////////////////////////
void loop()
{
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);

///////////////////////////////////////////////////////
  
  
  if (update_display){
    update_display = 0;
      
    Serial.print("shots =");
    Serial.println(shots);
    Serial.println(time_of_shot);

  }
  

}

Any insight is appreciated.

Thanks, Dan

Solved -

The issue is with the “digitalPinToInterrupt”, if I edit all attachInterrupt and detachInterrupt commands to use the explicit INT# then they work perfectly. As a matter of fact I verified that I can use all four of the external interrupts that the Qduino lists. INT0 =pin D3 = 0 for the assignment, i.e. attachInterrupt(0, rising_isr, RISING); for INT0

Hope this helps others.

Rgds,

Dan

So it appears the issue was NOT with the “digitalPinToInterrupt” macro. The issue was entirely my fault. I found that even though my input signal (phototransistor detecting IR) was not jittery it was too slow to rise from logic 0 to Logic 1 so in the indeterminate region the interrupt was triggering back and forth from rising to falling edge and back again really fast. I modified my phototransistor circuit to use a npn-pnp stages which squared up the signal and the interrupt problems went away. I’m guessing that the input pin for INT0 on my board uses a schmidt trigger or similar so it was less prone to the slow rise/fall times.