Hi All,
Seems I have an interesting problem with getting my chronograph going. I am using a TSOP4838 IR Receiver Modules separated X mm/inch distance from one another - both trigger positive and fire accordingly (haven't put an oscilloscope on them to check the pulse shape or debounce... (don't crucify me just yet...). They trigger INT0 and INT1, respectively. Generation is done by the tone command (which uses timer2 to my recollection).
Standard stuff so far. Now here is the interesting part: INT1 is triggering correctly, whereas my code's INT0 triggers INT1 as well. Read up on the net and saw a different gent having the same problem. Tried pull-downs but to no avail... Gone through the docs and web - might just need a fresh perspective. If INT1 is working -which has the same circuit as INT0, why is it triggering sub routines?
BTW - I am using a Micro - External interrupts on pin 2 and 3 - as the Leonardo.
Thank you in advance - any help is appreciated.
Some results I captured - 3 INT0 triggers with 5 INT1 triggers:
firsttrigger
result
done
firsttrigger
done
result
firsttrigger
done
result
done
done
done
done
done
Here it is - have striped away most of the garnish to this:
/* ------------------------------------------------------------------------------- */
#include <LiquidCrystal.h>
#include <TimerOne.h>
unsigned long timer;
volatile boolean firsttrigger = false;
volatile boolean done = false;
void isrone() {
//Timer1.restart();
//Timer1.start();
firsttrigger = true;
Serial.println("firsttrigger");
}
void isrtwo() {
//timer = Timer1.read();
//Timer1.stop();
done = true;
Serial.println("done");
}
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
tone(13, 38000);
prepareForInterrupts ();
}
void prepareForInterrupts ()
{
noInterrupts();
// reset Timer 1
TCCR1A = 0;
TCCR1B = 0;
TCCR1B |= (1 << CS12); // 256 prescaler 62.5 ns clk * 256
//TCCR1B |= (1 << CS11); // 8 prescaler 62.5 ns clk * 8
TCCR1B |= (1 << CS10); // 1 prescaler 62.5 ns clk
TIMSK1 = (0 << TOIE1);
TCCR1B |= (1 << ICNC1);
firsttrigger = false; //re-arm triggers
done = false; //re-arm triggers
EIFR = (1 << INTF0);
EIFR = (1 << INTF1);
attachInterrupt(0, isrone, RISING);
attachInterrupt(1, isrtwo, RISING);
//Timer1.initialize(400000000); //no more than a 4ms is excepted
//Timer1.stop();
//Timer1.restart();
interrupts();
TIMSK1 = (0 << TOIE1);
}
void loop()
{
//
if (!done || !firsttrigger) return;
Serial.println("result");
//Serial.println(timer);
prepareForInterrupts ();
}
/* ------------------------------------------------------------------------------- */
tsop48.pdf (131 KB)