# Realize if(0) condition in analog circuit ?

I have a question that I think is really noob-like and I'm dead sure there's a pretty simple answer, but I couldn't figure it out myself and didn't really know what to put into google, so here we go.

I have a RC Circuit that has a square wave input voltage going from 0 to e.g. 3 Volt. I need to pass the voltage across the capacitor to another circuit ONLY IF the input voltage currently is zero.

So basically, what I need is: if (V_in==0) passVoltage();

in analogue hardware.

My thoughts so far:
- Comparator: Compare input_voltage to ground? but then, if this gives me a "true" statement, what to do? I can't use it to like, flip a switch, can I ?
- P-Mosfet: Don't really think this is what I'm looking for as it alters the signal, doesnt it?

Maybe a combination of comparator and mosfet?

• And what should happen in the "else" clause, when V_in is not zero? And how do you handle the fact that a voltage will never really be exactly zero, you're dealing with continuous signals here, with physical properties like noise and such.
– pipe
Commented Mar 21, 2017 at 12:49
• What do you mean by "P-mosfet .. alters the signal"? Commented Mar 21, 2017 at 12:49
• @ratchetfreak Uhm, what. Please explain that solution in an answer to the question, because I have no idea how an inverting circuit would do anything useful here.
– pipe
Commented Mar 21, 2017 at 12:50
• Hi pipe, the "else" should simply block the signal. I know that its not gonna be dead zero, but I'll work around that with treshold levels. Commented Mar 21, 2017 at 13:06
• Thus if signal is not zero, output of the circuit is zero, if signal is zero, output is also zero. Just connect input to the ground. Commented Mar 21, 2017 at 14:03

• Comparator: Compare input_voltage to ground? but then, if this gives me a "true" statement, what to do?

One thing you need to realize is that with analog values, the voltage is never zero. There is external noise, if you put an oscilloscope between two traces (like the signal you want to measure and ground) you will see noise, you can attenuate noise (in the frequency range you desire) with filters but it will never go away completely.

This being said, lets suppose for a minute that you did have a magic box with two analog inputs that could find out when the two signals were equal to each other and output 1V if the signals were equal, and 0V if they were not. If both the inputs have noise (lets say 100uV of noise riding on top of the DC signal, which would be low for a beginner circuit), then you would never see 1V on the output of the box. If you did it would only output 1V for a very short time and then go back to zero. Equal to does not work for analog.

You need to compare the voltages, lets say you set a threshold and found the voltage only when it dips below a certain value. So if you have a 3.3V square wave with 1mV of noise, when the wave dips down near zero there is still noise, so you set a threshold at 10mV (right above zero, but not quite). You still find the values of when it is near zero. You can also get 'glitches' if you don't set the threshold high enough or have too much noise as shown below, so size the threshold high enough.

A comparator is what you need, it 'compares' any two voltages. If you make a resistor divider that can set the threshold for one of the comparing voltage, and the square wave input for the other.

• Wow, thanks for the details! Worked perfectly fine :) Commented Mar 22, 2017 at 13:13

Use a comparator, with the positive comparator pin voltage adjusted just above 0 Volts, with a simple resistor voltage divider. Then, connect negative comparator pin to your square wave. With this configuration, your comparator will output 1 when the square wave input is 0. Then connect your comparator output to a BJT transistor's base, biased in saturation mode, or to a relay. This way, the BJT will switch on when square wave input is 0.