I am using Teensy 4.0 and I have problems using attachInterrupt with CHANGE mode.
I want an input pin (10) to generate an interrupt when it changes status. In the interrupt service routine (my_isr) I toggle an output pin (3) to see, by my oscilloscope, the timing of the interrupt service routine reactions. I would expect to see the output pin (3) toggling HIGH and LOW at each change of the interrupt pin (10). In reality, on the oscilloscope, I see not just one toggling but several toggling for each status change of the interrupt pin.
It seems to me that one change of the input pin is generating more than one interrupt, rather than generating just one interrupt as I would expect.
I tried studying the manual of the micro and I have found in the GPIO chapter that all digital pins can generate interrupts "on rising" or "on falling" or "on low value" or "on high value". I don't find the possibility of generating interrupts "on changing value".
So I have the following 2 questions:
1) Is there any error in my software below?
2) How can it be possible the use of attachInterrupt with CHANGE mode if the micro has not this possibility on its digital pins?
//--------------------------------------------------------------------------------------
#define PIN_IN 10
#define PIN_OUT 3
void setup()
{
pinMode(PIN_IN , INPUT_PULLUP);
pinMode(PIN_OUT , OUTPUT);
attachInterrupt (digitalPinToInterrupt (PIN_IN), my_isr, CHANGE );
}
void my_isr ()
{
digitalWrite (PIN_OUT, HIGH);
int dummy = 0;
for (int i = 0; i < 1000; i++) dummy ++; // just to create a delay
digitalWrite (PIN_OUT, LOW);
}
void loop() {
}
I want an input pin (10) to generate an interrupt when it changes status. In the interrupt service routine (my_isr) I toggle an output pin (3) to see, by my oscilloscope, the timing of the interrupt service routine reactions. I would expect to see the output pin (3) toggling HIGH and LOW at each change of the interrupt pin (10). In reality, on the oscilloscope, I see not just one toggling but several toggling for each status change of the interrupt pin.
It seems to me that one change of the input pin is generating more than one interrupt, rather than generating just one interrupt as I would expect.
I tried studying the manual of the micro and I have found in the GPIO chapter that all digital pins can generate interrupts "on rising" or "on falling" or "on low value" or "on high value". I don't find the possibility of generating interrupts "on changing value".
So I have the following 2 questions:
1) Is there any error in my software below?
2) How can it be possible the use of attachInterrupt with CHANGE mode if the micro has not this possibility on its digital pins?
//--------------------------------------------------------------------------------------
#define PIN_IN 10
#define PIN_OUT 3
void setup()
{
pinMode(PIN_IN , INPUT_PULLUP);
pinMode(PIN_OUT , OUTPUT);
attachInterrupt (digitalPinToInterrupt (PIN_IN), my_isr, CHANGE );
}
void my_isr ()
{
digitalWrite (PIN_OUT, HIGH);
int dummy = 0;
for (int i = 0; i < 1000; i++) dummy ++; // just to create a delay
digitalWrite (PIN_OUT, LOW);
}
void loop() {
}