or more likely I'm missing something here..
I'm using the newly released IntervalTimer function with the Teensy3, and have been going in circles, so I'm asking for a sanity check. I've stripped out some basic functionality which demonstrates the problem.
Problem: When using all 4 timers, one of them does not end properly.
Circuit: This does require an external pulsed signal to be present on the listed input pins to serve as triggers to start the timers. I'm using input signals which pulse high every 1.5mS.
The code: listed below is the code which reproduces the problem I'm experiencing. It switches the LED on for the duration of a timer. With all 4 timers active, the last timer will not end - leaving the LED on.
Is this a bug somewhere in IntervalTimer, or am I missing something?
I'm using the newly released IntervalTimer function with the Teensy3, and have been going in circles, so I'm asking for a sanity check. I've stripped out some basic functionality which demonstrates the problem.
Problem: When using all 4 timers, one of them does not end properly.
Circuit: This does require an external pulsed signal to be present on the listed input pins to serve as triggers to start the timers. I'm using input signals which pulse high every 1.5mS.
The code: listed below is the code which reproduces the problem I'm experiencing. It switches the LED on for the duration of a timer. With all 4 timers active, the last timer will not end - leaving the LED on.
Is this a bug somewhere in IntervalTimer, or am I missing something?
Code:
IntervalTimer timer_1;
IntervalTimer timer_2;
IntervalTimer timer_3;
IntervalTimer timer_4;
#define CH1_IN 12 // channel 1 input pulse
#define CH2_IN 10 // channel 2 input pulse
#define CH3_IN 9 // channel 3 input pulse
#define CH4_IN 8 // channel 4 input pulse
#define LED 13
void setup()
{
// setup input & output pins
pinMode(CH1_IN, INPUT);
pinMode(CH2_IN, INPUT);
pinMode(CH3_IN, INPUT);
pinMode(CH4_IN, INPUT);
pinMode(LED, OUTPUT);
// attach Interrupts
attachInterrupt(CH1_IN,ISR_change_ch1,RISING); //CH1 signal change
attachInterrupt(CH2_IN,ISR_change_ch2,RISING); //CH2 signal change
attachInterrupt(CH3_IN,ISR_change_ch3,RISING); //CH3 signal change
attachInterrupt(CH4_IN,ISR_change_ch4,RISING); //CH4 signal change
}
void loop()
{
// do nothing here
}
void ISR_change_ch1()
{
//digitalWriteFast(LED,HIGH);
timer_1.begin(timer_1_output_end, 300); // start a timer for the desired output pw, when timer ends the pulse will be stopped
}
void timer_1_output_end()
{
//digitalWriteFast(LED, LOW);
timer_1.end();
}
void ISR_change_ch2()
{
//digitalWriteFast(LED,HIGH);
timer_2.begin(timer_2_output_end, 300); // start a timer for the desired output pw, when timer ends the pulse will be stopped
}
void timer_2_output_end()
{
//digitalWriteFast(LED, LOW);
timer_2.end();
}
void ISR_change_ch3()
{
//digitalWriteFast(LED,HIGH);
timer_3.begin(timer_3_output_end, 300); // start a timer for the desired output pw, when timer ends the pulse will be stopped
}
void timer_3_output_end()
{
//digitalWriteFast(LED, LOW);
timer_3.end();
}
void ISR_change_ch4()
{
digitalWriteFast(LED,HIGH);
timer_4.begin(timer_4_output_end, 300); // start a timer for the desired output pw, when timer ends the pulse will be stopped
}
void timer_4_output_end()
{
digitalWriteFast(LED, LOW);
timer_4.end();
}