# Logic signal generation from sine wave or clipped sine wave

#### gunrunnerjohn

Joined Jun 8, 2014
6
I have an application where I have a 18 VAC sine wave that I need to generate a logic signal for a PIC processor input port for.

The sticking point is the sine wave is controlled by a triac, and depending on the external system mode of operation, it can either be a full wave, a clipped waveform with only the positive half or only the negative half of the sine wave. It's not a problem to generate the logic signal from the full wave or positive clipped waveform, but I haven't cracked the code of how to do it with the negative alternation.

My current solution is an AC opto-coupler and a couple of resistors, that solves the problem, but the board footprint is larger than I like, and they are also more costly than a few discrete components if I can come up with a scheme that will work.

#### crutschow

Joined Mar 14, 2008
29,467
If you AC couple the waveform, then it will always go through 0V and you can use a comparator to detect that zero crossing.

#### gunrunnerjohn

Joined Jun 8, 2014
6
I'm not just coupling an AC waveform, that was easy. However, the half-wave rectified waveform doesn't go through zero volts.

#### BR-549

Joined Sep 22, 2013
4,928
What is it about the 18 VAC signal that you want to logically detect, to give to the PIC?

#### shteii01

Joined Feb 19, 2010
4,644
Run it through inverting amplifier with gain of 1?

#### gunrunnerjohn

Joined Jun 8, 2014
6
What happens if I have only the positive side of the sine wave? Inverting that loses the signal input.
Right now, I have this which I've been unable to improve on, maybe it's as good as it gets. I'm feeling like I'm swimming upstream trying to minimize this, maybe it's not worth the effort. Obviously, this outputs negative logic, low is an active signal.

#### crutschow

Joined Mar 14, 2008
29,467
I'm not just coupling an AC waveform, that was easy. However, the half-wave rectified waveform doesn't go through zero volts.
If you run the half-rectified wave through a capacitor, it will go through zero volts.

See simulation:

#### Bordodynov

Joined May 20, 2015
2,982
See

#### gunrunnerjohn

Joined Jun 8, 2014
6
Right, there's just too many components. I'll probably stick with my opto-isolator, I wanted to optimize the footprint. I still have to filter the output to get the steady logic signal after the comparator which will add several more components.

#### Bordodynov

Joined May 20, 2015
2,982
Right, there's just too many components. I'll probably stick with my opto-isolator, I wanted to optimize the footprint. I still have to filter the output to get the steady logic signal after the comparator which will add several more components.
A dual diode (BAT54S) and a resistor with a capacitor- Is it too much?
Give me your full schematic and I'll do it simulation.