2.2 RC Filter and Delay Between VCC/2 and the Actual Zero Cross
The series resistor and the input pin capacitance will form an RC filter, which will delay the response compared to the actual zero crossing.
The 1MΩ resistor together with the input capacitance on the AVR introduces a delay that brings the detection very close to the actual crossing. For other AC voltages or series resistors it is recommended to do a test with an oscilloscope to see how close the detection is to the actual crossing. This makes it very easy to check if the zero crossing detection is correct or not. Connect an oscilloscope probe to the mains and another to PB0. A correct detection will show PB0 going high for a short period of time at each falling edge zero crossing (see Figure 1-3 and Figure 1-4).
If the detection is after the actual crossing, the next crossing should be targeted by adding a delay to the action. The delay should be equal to the time left before the next crossing.
The series resistor can also be modified to make the detection closer but note that the maximum current through the AVR’s clamping diode should not be higher than 1mA.