Pin change interrupt multiple fire
Posted: Tue Nov 14, 2017 2:07 pm
I have a pin (34) setup as an input. This pin is connected to a triac opto that generates a clean signal. I have it setup to generate an interrupt on falling edge. This is so I can detect zero crossings that will be used to fire an output triac. The problem I am having is that with each pulse the interrupt is firing MANY times on both rising and falling edges. It is acting like it is seeing bounces from a mechanical switch not from a clean sign wave signal.
Here is some of the code:
#define ZX_PIN 34
#define TRIAC1 26
void zero_cross()
{
// just toggle the pin for now
digitalWrite(TRIAC1,!digitalRead(TRIAC1);
}
void setup()
{
pinMode(ZX_PIN,INPUT);
pinMode(TRIAC1,OUTPUT);
digitalWrite(TRIAC1,LOW);
attachInterrupt(digitalPinToInterrupt(ZX_PIN),zero_cross,FALLING);
}
void loop()
{
}
Here is some of the code:
#define ZX_PIN 34
#define TRIAC1 26
void zero_cross()
{
// just toggle the pin for now
digitalWrite(TRIAC1,!digitalRead(TRIAC1);
}
void setup()
{
pinMode(ZX_PIN,INPUT);
pinMode(TRIAC1,OUTPUT);
digitalWrite(TRIAC1,LOW);
attachInterrupt(digitalPinToInterrupt(ZX_PIN),zero_cross,FALLING);
}
void loop()
{
}