The circuit shown below is taken from this whole design. I understand the main idea. They want to measure some voltage condition and trigger something else with the comparator. R39 and C38 form a low pass filter. R37 is the pull-up resistor as the comparator's output is open collector. D19 and D20 are protection diodes as the input goes positive and negative. What I don't understand is the arrangement of the resistors R36, R38, R35, and R40. Why are R36 and R38 referenced to ground in the midpoint? How is the comparison process achieved? According to the reference design, the input AC voltage is 230 VAC 50/60 Hz.
The design appears to assume that L and N can be swapped. This is a common problem in countries with reversible mains plugs. The circuit, therefore, needs to accommodate live on either pin.
Let's ignore D19, 20 and C37 for a now.
With the junction of R36 and R38 earthed one of the comparator inputs will be grounded. Remember that the neutral is so called because one of the supply wires has been earthed or 'neutralised' at the supply transformer so its voltage will be close to zero. As drawn, 'AC_N' will be at zero volts and since the top of R38 is at zero volts the junction between them will be at zero volts. The comparator '+' input will now also be at zero volts. Any time AC_L goes negative the comparator output will switch high. The result is a squarewave which goes high when AC_L is negative and low when positive.
Reversing the input polarity inverts the result.
D19 does two things when AC_L goes positive:
- It limits the voltage on IN- to one diode drop above that on IN+.
- It causes the voltage on IN+ to rise above zero somewhat. This is probably a good thing as it gets the inputs away from operating at 0 V (although the chosen device will work down to zero on the inputs.)
Figure 1. Equivalent circuit while AC_L is positive.
You can work out what happens on the negative half cycle or when the live and neutral are reversed.
Note that the whole shown circuit (so, +3.3V, +12V, ZC_IN, etc) should be considered live and thus dangerous).
The shown picture has cut off the name of the output that gives an important hint: ZC_IN, which stands for Zero Crossing in.
D19 and D20 clamp the floating line voltage to a floating 0.7V volt, where R35 and R40 limit the current through D19 or D20. I mean floating with respect to the circuit's ground. R36 and R38 'align' this floating 0.7V with respect to ground. So, the comparator will see a sine wave which matches the line voltage at the zero crossing, but will be clamped between -0.35V and 0.35V.
This zero crossing is required to make a good PFC.
Below a picture of the (clamped) voltages the comparator sees at its input terminals.