I am using interrupts 0/1 on digital pin 2/3 (rising edge) on the Arduino Pro. My input signal is a square wave. However the rising and falling edge are triggering for either interrupts.
The square wave was also ran through a debouncing circuit found from http://www.eetimes.com/discussion/break-point/4024956/Solving-Switch-Bounce-Problems
My code is attached below. Any thoughts would be appreciated.
#include <avr/interrupt.h> // interrupts library
/*****************************************
// Declaration of Variables //
******************************************/
unsigned long digitalSpeed = 2; //Speed bus connected to digital pin 5
unsigned long digitalDirection = 3; //Direction bus connected to analog pin 1
volatile byte directionflag=0;
volatile byte speedflag=0;
void setup()
{
Serial.begin(9600); // Setup serial with baud rate
attachInterrupt(0, arduino_anemometer, RISING);
attachInterrupt(1, arduino_direction, RISING);
}
void loop()
{
if(speedflag==1)
{
Serial.print("Speed time = ");
Serial.println(millis(), DEC);
speedflag = 0;
}
if(directionflag==1)
{
Serial.print("Direction time = ");
Serial.println(millis(), DEC);
directionflag=0;
}
}
void arduino_anemometer()
{
if(speedflag==0) // Interrupt triggers twice, only ran once
{
speedflag=1;
Serial.print("EICRA ="); //EICRA verify interrupt is configured for rising edge. Noticed 1111 as expected.
Serial.println(EICRA, BIN);
}
}
void arduino_direction()
{
if(directionflag==0) // Interrupt triggers twice, only ran once
{
directionflag=1;
Serial.print("EICRA ="); //EICRA verify interrupt is configured for rising edge. Noticed 1111 as expected.
Serial.println(EICRA, BIN);
}
}