SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By bpeoples9
#124972
Edited to put it back, with solution!

Building a little triac-based dimming thing, and using Atmel's AVR182 app note (http://www.atmel.com/dyn/resources/prod ... oc2508.pdf ) as a basis for the zero cross detector. I'm using an arduino for hardware right now, atmega328.

It's wired into a shield. With the shield unplugged, I can see the AC sine wave just fine. When I plug the shield in, the sine wave goes away, and I just see noise. I'm connecting to INT0, and triggering on rising and falling edges. INT0 is just triggering randomly, on about the same frequency whether the shield is plugged in or if the AC is connected.

The problem turned out to be that the 1MOhm resistors were limiting the current far enough that the signal was lost when I attached the arduino. I ended up building a square-wave generator out of two diodes, a current-limiting resistor, and a zener to test what was going on. When I replaced the 1MOhm resistor with a 51K resistor (increasing the current through the diodes to about 3mA), the signal has enough strength to get through. I'll upload a circuit sketch if anyone wants to see that diagrammed.

I have one outstanding problem is that there seems to be some capacitive coupling onto INT0 from an unknown source -- basically a very sharp 5V spike when the AC is not attached that my scope is picking up as 90Hz, that then decays quickly. A 1K resistor between INT0 and ground sharpens the spike (supporting that it's capacitive), and I'm planning to put a low value capacitor across INT0 and ground to short that spike out, but not affect significantly the square wave signal. In the code ( http://pastebin.com/sZnRHCmH ), if I comment out line 125 (PORTB = mask;) then the spike goes away. In the originally (definitely working) code, I had been assigning PORTB bits as they fell in the if cascade, but that was leading to some funny problems at the very low or very high levels. I also may go back to that if the capacitor idea falls through. This is causing spurious interrupts, and is currently triggering the triacs more or less at random, so it needs to get resolved.
Last edited by bpeoples9 on Sun Apr 10, 2011 8:12 am, edited 1 time in total.