below is my circuit for zero cross detection at 110VAC.
My pcb has 2 of these and they are connected to 2 independent AC sources.
The interrupt should only fire every 16.6 ms but I get lots of false interrupts. I am using the FALLING trigger so my question is: at what voltage difference does the Arduino Nano think the voltage is falling?
I am using 3.3V reference.
Are the false interrupts scattered within a single cycle or are they clustered in one area?
The data sheet does not have any obvious values in the transfer characteristics section. The Current Transfer Ratio value has a range of 50% to 600% so not very useful.
Looks like you will have to get your answer with a scope.
I finally got the scope functional! In the video below I have the serial printout under the scope. The waves in the scope look perfectly fine and I have no explanation why I am getting irregular interrupts. There are 2 waves visible in the scope, the lower is 'city' the upper 'inverter'
here are some values from the serial printout in the video. the first column shows the ms delay between 2 irregular interrupts printouts and the last column is the time measured between two interrupts in the ISR:
3460 city 7
6 city 7
6 city 10
7 city 10
this means:
3460ms nothing irregular happening, then an irregular interrupt within 7ms,
then 6 ms nothing happening, then an irregular interrupt within 7ms
then 6 ms nothing happening, then an irregular interrupt within 10ms
then 7 ms nothing happening, then an irregular interrupt within 10ms
here some more data points:
2456 city 0
6 city 0
6 city 0
7 city 0
6 city 0
6 city 0
3091 city 6
7 city 6
6 city 10
7 city 10
5 city 10
2153 city 0
6 city 0
6 city 0
289 city 0
6 city 0
7 city 0
211 city 7
6 city 10
6 city 10
7 city 10
13261 city 7
6 city 7
6 city 10
7 city 10
6 city 10
26270 inv 0
6 inv 0
6 inv 0
2798 inv 0
6 inv 0
6 inv 0
7993 city 6
6 city 6
6 city 10
6 city 10
7 city 10
5000 city 0
6 city 0
6 city 0
3380 city 7
6 city 7
7 city 10
6 city 10
2507 city 0
7 city 0
6 city 0
2671 city 0
Gut feeling is that the pullup resistor is waay to low in value. Try 100k+.
You only want a needle pulse during the time that the opto LED is off.
Not the "wide" square wave you have now.
Leo..
@Wawa: I tried 47k and it did not change, then I tried 1k and is was a bit better.
@dlloyd: The de-bounce filtered out the low end of the fatly interrupts but the longer once still came thru, but the 0.1uF did the trick. So far I have been running it fore some hours without a false interrupts.
@LarryD: here is a link to the project page - but I think dlloyd solved the problem with the cap.
Glad it worked. I generally prefer a hardware solution with interrupts, but with the low frequency here, a software solution could also work OK. Looks like your zero-cross pulse is wider than 2000µs so the noisy rise is causing some invalid interrupts.
Looking at the scope trace, the zero-cross pulse is a little more than 6000µs wide. So for a software solution, you could try 7000 as a setting in your interrupt routines.
Be aware of the fact that the opto output falling edge will ocurr just before the true AC zero crossing. At some point, the AC voltage is not sufficient to illuminate the input LED and get a response on the output photo transistor. You can find the delay using the scope by triggering on the opto output on one channel and determine the delay of the AC channel. The time difference is the early trigger value of the opto sensor.