I want to implement phase angle control for a single phase ac fan. To achieve that we need a ZCD circuit interfaced with a microcontroller to get a pulse at zero crossing. As our circuit has some space constraints, we have implemented the same using PIC 18LF45k40 which has built-in ZCD circuitry which generates pulses at Zero Crossing. Below is the circuit for implementing zcd- PIC ZCD implementation circuit

The above circuit is referenced from Technical Brief document - Link here

As you can see, the circuit has a common ground with the AC Neutral which makes the circuit bit questionable as the whole circuit has to be treated as live and raises safety concerns. (Please correct me if I'm wrong)

Putting the above concern apart, the problem I'm facing is the pulses generated from microcontroller is not stable. It swings in the x-axis(time) in the oscilloscope. The code for generating pulse is as follows -

void __interrupt() ZCD(void)
   if(ZCDIE && ZCDIF)
        LATA1 = 1;
        ZCDIF = 0;

        TMR0IF = 0;
        LATA1 = 0;
        LATA1 = 1;


The ZCD Input when the ground is not connected with neutral is a plain DC line. When the ground is connected with Neutral, sine wave superimposes on the DC line as shown below-

DC voltage

The ZCD in pin gets the following waveform when neutral and dc ground are common -


Following are my questions -

1 - Is the ZCD waveform expected this way? There is a very limited resource available on this issue.

2 - The below is the circuit which I've implemented for Zero Crossing. Is this circuit safe and practical?

ZCD Circuit

Triac circuit -

Triac Circuit

3 - Please go through the code and let me know the issue.

4 - Please suggest any circuit or app note which implements the zcd.

  • \$\begingroup\$ Looks to me, from your second scope plot, that this isn't working very well. A ZCD should give you square edges, suitable for a digital input. All you have there is a smaller noisy sine wave. \$\endgroup\$
    – Aaron
    Commented Apr 4, 2019 at 15:30
  • \$\begingroup\$ How is the 3.3V implemented? And with respect to what signal do you measure with your scope? AC neutral? Be careful touching the scope... \$\endgroup\$
    – Huisman
    Commented Apr 4, 2019 at 18:14
  • \$\begingroup\$ @Aaron the second scope is the input waveform for the ZCDIN pin for the PIC Microcontroller. The Pulses are generated from a Digital Pin of the microcontroller depending on the ZCD interrupt internally by the Microcontroller peripheral. The code shown above is the one which generates the pulses for the OptoTriac. \$\endgroup\$
    – Sai Prasad
    Commented Apr 5, 2019 at 6:13
  • \$\begingroup\$ The 3.3v is implemented using a 9V adapter followed by SMPS buck converter (LM2596 based). The circuit has the AC neutral and Ground connected together so basically its measured with respect to neutral. \$\endgroup\$
    – Sai Prasad
    Commented Apr 5, 2019 at 6:15


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.