I would have thought it's quite simple?, the digital input is used to detect the zero crossing point of the mains, the analogue input actually measures the voltage.
Thanks, my friend, for your answer.
Let's see if I understand how the circuit works.
The zener diode is to keep the voltage, at transistor's base, at a secure level (max 3.9 Volts).
When the main's voltage is above 0, the transistor is saturated and the level, at the pic's pin is 0.
When the main voltage arrives at 0, the transistor will not conduct and the level, at the pic's pin will be 1.
Is this correct?
For the other circuit, the one that goes to the ad pin, the zener diode is to keep the max voltage at the pic's pin, at 3.9 Volts, and the 1K1 resistor with the 10K resistor, make a voltage divider.
Is this alo correct?
So, in the software, when the pic's i/o pin is at logical level 1, it's time to read the mains voltage.
I start to read the a/d, after the i/o pin goes to 0, and at this point, for some time, while the level at the i/o pin is 0, I keep reading the a/d.
After that, I pick the higher value read and this will represent the voltage at mains power supply (for the positive ac semi-cycle wich represents 1/2 of the total mains voltage).
Is this right?
Thank you very much.