0
\$\begingroup\$

I'm trying to catch zero crossing (using below circuit) when it exactly happened. Rising and falling edge intervals are not equal and they need 0.3-0.7 ms to reach corresponding logic level. Let say this is okey, hardware is limited in some way but I have another problem. I'm using STM32F4 for ZCD GPIO interrupt. MCU GPIO interrupt callback function is called with delay (0.8-2 ms) which means that MCU does not catch or do not get signal trigger immediately when ZCD reaches appropriate logic level. Be free to comment what really happens in circuit.

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ What is your question? So far you've just stated the limitations of the hardware in the circuit and the microcontroller, but what are you looking to fix or find a solution for? And what are your targeted and acceptable delay times? \$\endgroup\$
    – InBedded16
    Commented May 19, 2023 at 16:41
  • 3
    \$\begingroup\$ Have you probed with oscilloscope if the delay happens before the MCU or in the MCU? \$\endgroup\$
    – Justme
    Commented May 19, 2023 at 16:43
  • \$\begingroup\$ What is POWER connected to? What is AC_SENSOR connected to? Please Edit the details into your question (and not buried in the comments). \$\endgroup\$
    – Transistor
    Commented May 19, 2023 at 18:36

2 Answers 2

2
\$\begingroup\$

You have different problems there, first the time shift between the IR-LED of the optocoupler is going in and then the RTOS-delay what you possibly use with the STM32.

If you look at the rising and falling edges of the 50Hz sine wave, your microcontroller can detect zero by focusing solely on the edges. If, with a rising edge, the optocoupler LED lights up sufficiently brightly to allow a sufficiently high current to flow at the phototransistor so that the logic signal is recognized at the microcontroller I/O pin, then this is also the case when the LED is no longer bright lights up enough, i.e. at the falling edge.

The picture you see with the microcontroller is therefore quite clear, there is a high signal at a defined distance from the zero crossing point. In the middle, where there is a low signal, there is the zero crossing.

It is possible that you switch off all other interrupts while the state changes are expected and the interrupt of the I/O pin is processed directly by the interrupt handler. In this way you always get a constant detection time.

You could test with the oscilloscope whether there is a delay between the detected zero crossing and the real zero crossing, you can then write this delay into the firmware and then subtract it from the detected value.

\$\endgroup\$
2
\$\begingroup\$

What is the voltage of your AC sensor waveform? The opto U304 will not start conducting until the applied voltage is greater than the IR diode's forward voltage, and will then require enough additional voltage to get enough current to get a logic low on the output.

This circuit attempts to simulate the response of the zero crossing detector, showing about 2 ms delay with a 6 V (peak) sine wave.

schematic

simulate this circuit – Schematic created using CircuitLab

ZC Sensor voltages

Here is an LTspice simulation using an actual opto-isolator model. It shows about 1.1 ms delay on zero crossing.

ZC detector with opto

Adding a capacitor across the 1k resistor causes a leading phase shift and a delay of only about 200 us, with a much sharper falling edge. This is due to higher current through the capacitor. And the output transitions for negative zero crossing occur about 2.5 ms early.

ZC detector with opto and phase shift capacitor

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.