Go Down

Topic: Weird interrupt-triggering behavior (Read 1 time) previous topic - next topic

lagart

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...  :D
The circuit that I'm using is the following one:

http://www.dextrel.net/diyzerocrosser.htm


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:
Code: [Select]

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!

vaj4088

The scope photo appears to show interrupts on CHANGE instead of on FALLING.  Good code, good scope photos, I can't explain what is happening.  Sorry.

It would be nice to figure out why this is happening, but in the meantime you could use a variable to ignore every other interrupt.


nickgammon

A well documented problem. Good job.:)

Is this literally the test code? Or is there more, and you excerpted out the relevant parts?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

Which version of the IDE are you using?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

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

lagart

Hey guys! it  works! :D
Thanks for helping me!

Which version of the IDE are you using?
I'm using the 1.6.5 version.


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.
It's a good solution, but I get it working :P


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.

Now the magic code....
Code: [Select]
void setup() {
  pinMode(3, OUTPUT);
  attachInterrupt(22, zero_crosss_int, FALLING); 
}

void zero_crosss_int()  {
  digitalWrite(3, HIGH);
  delayMicroseconds(100);
  digitalWrite(3, LOW); 

}

void loop() {

}




I just changed the input pin!! (7--->22)
I read in another post (http://forum.arduino.cc/index.php?topic=54932.0) 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 :P
Does anybody knows something about that??

Go Up