App note: Zero cross detector for AVRs

Posted on Sunday, December 23rd, 2012 in app notes by DP


Atmel describes how to implement zero cross detection on an AVR. Zero cross detection is used to find the exact moment when a signal crosses from positive into negative, or vice-versa. This is useful in periodic AC signals as it gives you a reference point of when a new half period has started.

This application note shows the user how to implement a zero cross detector with a minimum of external components. It should be noted that this solution will not give any
galvanic isolation for the microcontroller against the AC mains. The zero cross sense resistor can be a way for electronic noise to get into the system.

This entry was posted on Sunday, December 23rd, 2012 at 9:00 pm and is filed under app notes. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

5 Responses to “App note: Zero cross detector for AVRs”

  1. Tom Price says:

    This might be OK for some purposes but in my view it would generally be safer and more useful to isolate the microcontroller from the mains voltage using an optocoupler or digital isolator. Note that it relies on internal diodes to restrict the input voltage, which not all microcontrollers have.

  2. eff zog says:

    What does an opto-coupler cost these days!! Looks up part on dipmicro site which happened to be opened in other window: 4n35 3.5KV isolation is 0.36 cents quantity1 , 0.2326 cents quantity 5 –


  3. Matseng says:

    Eff, the 4n35 is 0.36 dollar, not 0.36 cent :-) but still rather cheap.

    In some situations it makes perfect sense to use this method. For instance in an intelligent light switch/dimmer. A PIC10F costs less than $0.50 so adding a $0.36 optocoupler and a bigass dropping resistor plus an transformer for power it is a waste of money.

  4. Graham says:

    It’s very similar to what Microchip suggest as a cheap way of detecting zero crossing. They do note that the zero cross event is detected before it occurs in one polarity change (positive to negative), but I didn’t see any mention that it would be late in the other polarity change (negative to positive). Would have been nice to see them suggest using two resistors in series, rather than one. I agree that this is probably only of use when there is no isolation needed from the mains.

  5. AMS says:

    Yeah you should probably isolate it if you’re going to be touching it, but for things that are going to be touching mains anyway (running off a capacitor-ballasted rectifier) its the easiest way to get a zero-crossing.

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Recent Comments

  • Edward Mallon: A lot of us have ended up at this sensor / screen combination. But I couldn't afford the extravagance of six dedicated control lines on...
  • Andy: Me!!!
  • Bill F: Taking my place in line........
  • Mikee: 11
  • Clara: Thanks, Cinco!