Comparator driving me nuts

Started by brett, September 09, 2015, 08:05:13 PM

Previous topic - Next topic

brett

Hi all. I'm trying to get an Lm311 (Very common comparator) to work in a zero-crossing detector. Which is usually easy, except that I'm using a single supply of 14V. I am using a  pair of voltage divider resistors to bias the -Ve input to 7V, and the +ve input comes in via cap so that it has no DC component.

But ithe output is always latched to 13V. At the output, have a 10k resistor that ties the output 'up', as per most schematics.

What else should I do? The input is always low (near ground) and the output high. I'm officially mystified. Thanks for any help.

ps. The -ve input is at DC 7V. Do I need a cap to ground to also make AC 7 volts? As per 'noiseless' biasing?
Brett Robinson
Let a hundred flowers bloom, let a hundred schools of thought contend. (Mao Zedong)

PRR

> the +ve input comes in via cap so that it has no DC component.

So what IS the DC at that pin?

You do not say that you have forced "any" DC on it. If there is no DC path, pin 2 (being PNP in) will rise up to nearly Vcc, higher than 7Vref, so the output *should* be high.

Also see the Common Mode Limits in Fig 5. Operation is not guaranteed unless input is at least 0.3V above the negative supply. Since your Vee is zero, that +In better be higher than +0.3V.

Additionally: if you have one input near zero, and the other up at +7V, you gonna need BIG swings to "zero cross". Like 7V swings. We might usually DC-bias one input to +7V, the other to +6.9V, cap-couple an AC signal in; now you only need 0.1V swing, and a strong-arm guitar can do that.

If you don't need the speed, LM339 is often easier to use single-supply.
  • SUPPORTER

R.G.

As Paul says, you're going to have to bias both inputs at nearly the same DC voltage. There are actually a few other considerations:

1. There is almost certainly an input voltage max/min range for the comparator. Get either or both inputs outside it, the comparator doesn't work so good, or dies.
2. Bypass the power supply pins as near the comparator package as you can get the capacitors.
3. Use hysteresis. Even a few millivolts will keep the comparator from oscillating like crazy when the inputs are passing one another.

So yes, in this situation, make a bias supply somewhere in the middle of the power supply range. Bypass that point with a capacitor to ground, then run a resistor from that point to each input. Capacitively couple the signal to either input. Use a high value resistor between the output and the **positive** input to ensure a little hysteresis. You want the resistances to drive the + input with maybe 5-10mV of additional drive. This ensures it can't oscillate in the middle, and forces clean transitions.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

brett

Thanks heaps.

You have both explained the issues very well.

Of course I need to DC bias both inputs! For reasons that are now obscure, I was thinking of of the comparator like a -ve feedback op amp, where the output biases the input to equal the -ve input (so that only the + is biased).

For biasing I'll run a 100k resistor from the (10k/10k) bias point to each of the inputs, and add a 10M resistor for +ve feedback hysteresis. My signal is about 200mV p-p, which is enough to almost saturate the LM311. And yes, Paul, I'll use a 393 as soon as they arrive.

Thanks again, gurus.
Brett Robinson
Let a hundred flowers bloom, let a hundred schools of thought contend. (Mao Zedong)

brett

Update: I've been Spice modelling the issues. It seems that to get the zero-crossing points right (unaffected by the biasing), the resistors from Vb to the inputs must be small (1k). I started out with 100k resistors, which was hopeless - the inputs were biased a few hundred mV apart. With 10k resistors the difference was about 100mV (my signal is only 400mV peak-to-peak, so this is still too much difference). With 1k resistors the difference in biasing was tiny, and zero-crossing was almost perfect (50/50) for a good quality sine wave.

The design is quite immune to the resistors used to make the voltage divider (2x10k and 2x100k are ok), and the positive feedback resistor (1M, 4.7M and 10M are all ok).

All of that was Spice modelling. That's one of the easier yet most useful analyses I've done with it. Now to build it.
Brett Robinson
Let a hundred flowers bloom, let a hundred schools of thought contend. (Mao Zedong)

Transmogrifox

I would call into question your SPICE model if you're seeing offsets as severe as that.
https://www.fairchildsemi.com/datasheets/LM/LM311.pdf
Input bias current is max 250 nA and input offset voltage is stated as max 7.5 mV at room temp.  Typical values are less.  Input bias current offset is max 50 nA.  The worst you should see on 100k if the bias point is symmetrically tapped from a common 10k divider is ~100k*50nA = 5 mV.  What are your initial conditions in the simulation?  Did you let the input capacitor transient settle in a transient sim or did you do a DC simulation?  Anyway, these are some things you might consider.

For hysteresis I would think something closer to 1M against a 1k is about as large as you would want to go to have a useful hysteresis.  You can add a small 5 or 10 mV AC in your simulation to emulate noise. 

Yes, there will be steady state noise, but also consider a guitar signal can have several zero crossings due to higher harmonics when the fundamental is near 0.  You may not want to have 1.54 kHz bursts on every 220 Hz zero crossing. 

Aggressive low pass filtering can help too.  It may be of value to get a wav file of typical guitar signal and run that through your sim.  You will be able to learn a lot about how the detector responds to a variety of input signals.

As you do that you can toy with a balance between amount of hysteresis and low-pass filtering needed to get the desired output.  If you're using it to make an octave-down effect or a tuner you will definitely find it educational to play with this more in simulation.

If your LM311 model can't be coaxed into reasonable behavior, you can make a behavioral model with some current sources to emulate input bias currents, voltage-controlled current source with gain to emulate the comparator gain, as well as a voltage source to emulate input offset voltages.
trans·mog·ri·fy
tr.v. trans·mog·ri·fied, trans·mog·ri·fy·ing, trans·mog·ri·fies To change into a different shape or form, especially one that is fantastic or bizarre.

brett

Thanks T. Yes, the modelling and results lined up., even when simulating an LT1011 I was using  and simulating a 100k/100k voltage divider, which might explain some of the extra offsets (I wanted 50k of input impedance). The 4.7M for hysteresis was a mid value chosen on the basis of 1M to 22M in various schematics (from memory, 22M was shown in the LM311 data sheet - it surprised me to see that, but the device gain is >200,000).

I only need a tiny bit of hysteresis because the signal is a constant amplitude VLF RF. Interestingly, an LM386 does a fine job of amplifying the signal, despite being well above audio freqs.

Cheers
Brett Robinson
Let a hundred flowers bloom, let a hundred schools of thought contend. (Mao Zedong)