Hi there!
I'm trying to implement a zero-crossing detector but something strange (at least for me :P) is happening... I hope you can help me...
The circuit that I'm using is the following one:
And it works great, as you can see in the o'scope capture:
The problem arise when I connect the "OUT" to an Arduino's pin (I'm using an Arduino Due).
With the following program:
void setup() {
 pinMode(3, OUTPUT);
 attachInterrupt(7, zero_crosss_int, FALLING);Â
}
void zero_crosss_int()Â {
 digitalWrite(3, HIGH);
 delayMicroseconds(100);
 digitalWrite(3, LOW);Â
}
void loop() {
}
I got the this o'scope capture:
As you can see, the interrupt is triggering at least twice. I was expecting just the first one... I don't know why I'm getting this multiple triggering...
Any idea how can I fix it?
Thanks!
I can't see anything wrong with your code, nor with the library code, however I am not a Due expert. As a work-around you could test the pin state in the ISR, and ignore it if the pin state is not what you expect.
Well you are right but the one issue which you are not considering is that the Due pins are configured for 3.3v while you are using 5v which not only is creating the interrupt issue but will also damage the MCU. hope this will help
cashme14:
Well you are right but the one issue which you are not considering is that the Due pins are configured for 3.3v while you are using 5v which not only is creating the interrupt issue but will also damage the MCU. hope this will help
Nope, in the first screenshoot you will see that the output is 5v, but it wasn't connected to the Arduino at that time. I was just testing the zero crossing detector.
In the second screenshoot you will see that the zero crossing signal is 3.2v, which is fine. I took into account the voltage difference and I connected it properly to the Arduino.
I just changed the input pin!! (7--->22)
I read in another post (ATMEGA Digital Input Characteristics and Hysterisis??? - General Electronics - Arduino Forum) that in some atmega's datasheet "The pins when used as digital inputs have a "Schmitt trigger" characteristic"
So I realized that the pin 7 that I was using was under the "PWM" pin-sector of the board, so I changed to the pin 22 that is under the Digital sector.
I don't know if that claim applies to the Arduino Due, but at least now it works
Does anybody knows something about that??