14
\$\begingroup\$

I made a dimmable light which turns on or off depending on the luminosity of the environment.

The schematic is below:

Schematic

My problem is with the LM293 comparator.
It compares low voltage levels successfully but not the voltages higher than around 3V (VCC = 3.3V). For example when the pin 3 and 6 are 3.1V and pin 2 is 2.8V, pin 1 is still low.
I have to turn down the pot so that pin 2 voltage becomes as low as around 2.2V to read high on pin 1.

I covered the LDR with tape to drop the voltage to 1.1V and I tested pin2 voltage again. This time as soon as pin 2 went below 1.1V LED turned off, success.
I tried to use 20k pot but the result is the same. I can hack the problem so that comparison occurs at lower voltages by lowering the R2 resistor which will unwantedly limit the voltage range I can work but I want to know the reason of the problem.
Is there something I don't know about comparators?

LM293 datasheet

\$\endgroup\$
9
  • 6
    \$\begingroup\$ +1. Congratulations on a well asked question. Good information provided, question clear and obvious. Keep it up ! :-) \$\endgroup\$
    – Russell McMahon
    Oct 16, 2023 at 10:15
  • 1
    \$\begingroup\$ Indeed it is, and it shows class to give such positive feedback @RussellMcMahon \$\endgroup\$
    – MiNiMe
    Oct 16, 2023 at 10:28
  • 1
    \$\begingroup\$ I'm happy for you to accept the answer that best suits you. However, it is generally recommended that you wait a while before accepting an answer. (My suggestion: A day is probably a sensible minimum). This encourages more people to provide answers and you MAY get some even better ones. In this case the answers you have cover the point well enough BUT even then somebody may have decided to do even better. || You are obviously serious in your efforts. You need to read data sheets for "light reading" :-). Look at terms you do not understand and research what they mean. ... \$\endgroup\$
    – Russell McMahon
    Oct 16, 2023 at 10:28
  • \$\begingroup\$ ... Notes and data re Vcm on page 5 say some interesting thimgs. If you look through electrical characteristics table especially you will learn a lot about device limitations and capabilities. \$\endgroup\$
    – Russell McMahon
    Oct 16, 2023 at 10:30
  • \$\begingroup\$ Oh thank you, first time getting such a feedback. I'll mark the answer later, deal. \$\endgroup\$ Oct 16, 2023 at 10:35

4 Answers 4

11
\$\begingroup\$

Many comparators (same goes for OpAmps) don't accept inputs to near their supply ranges.

If you look at the datasheet for the LM293 (cf link in your post, page 5), you have this table : recommended operation

So for your version (non-B), the recommended input range is 0V to (V+)-2V. So if your supply voltage is V+=3.3V, the correct functionning is only garateed for input signals up to 3.3-2 = 1.3V (nb : your comparator can be used up to 38V supply, so usually, the user don't care about 2V dead band).

What you need, is a comparator that accepts inputs from 0V up to your positive supply (3.3V). Such comparators are called "rail to rail". Not all comparators fulfill have this option, but you should have no trouble finding some that do (some even accept inputs above the supply voltage or bellow ground, but it becomes harder to find).

Why are not all comparators rail-to-rail? Because it is a trade-off with other characteristics (speed, consumption, complexity (therefore price), ...) and it's not always needed. So there are rail to rail versions, some like yours that include only the negative rail, and some that don't reach any supply rail. It's up to you to choose according to your needs.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Oh I heard the rail to rail term before but it didn't sound important until now. Best way to learn is to make mistakes I guess. The sad part is I literally applied nail polish with a needle to print the PCB at hand and it was tedious work, I don't want to do it again. I will need to find a rail to rail comparator that matches the exact pin configuration or I will lower the R2. \$\endgroup\$ Oct 16, 2023 at 10:28
  • 1
    \$\begingroup\$ have a look at the LM393LV (ti.com/lit/ds/symlink/…) : at first glance, it might be a suitable pin compatible replacement (nb : I haven't read the whole datasheet, nor analyzed your circuit in detail, so up to you to check if it fulfills your needs) \$\endgroup\$
    – Sandro
    Oct 16, 2023 at 10:35
  • \$\begingroup\$ Thank you for the recommendation, it is unfortunately only available as SMD but I guess I can find a substitute with a simple research. \$\endgroup\$ Oct 16, 2023 at 10:46
  • 1
    \$\begingroup\$ Sorry, I was going too fast. MCP6542 (ww1.microchip.com/downloads/en/DeviceDoc/…) is also pin compatible and rail to rail, and exists in DIP8 package \$\endgroup\$
    – Sandro
    Oct 16, 2023 at 11:07
  • \$\begingroup\$ I didn't tell the package I required no problem. Since MCP6002 is much easier to find for me I am considering using it. I'm not fully sure yet. I came across MCP6022, LMC6482 on my way but they had unnecessary features for me. \$\endgroup\$ Oct 16, 2023 at 12:31
12
\$\begingroup\$

That's not surprising – Datasheet p.5 lists "Recommended Operating Conditions", where the maximum input voltage should be at most Vcc - 2.0V.

So, wrong device.

You could replace it with, for example, the typically cheaper MAX919 (or another IC from the MAX917–MAX920 series, which is a bit slower, but from what I'd guess your application is, you don't care too much whether the on/off logic takes 2 µs or 5 µs to react to external inputs.

(I'm lazy when it comes to soldering – I could see me just dropping in an Attiny10, which has 4 ADC channels, and use 3 ADC channels just to implement a digital window comparator with debouncing logic, so that I don't fluctuate when the "LDR" input is close to either potentiometer-set threshold.)

\$\endgroup\$
2
  • \$\begingroup\$ I didn't know comparators had such limits. Thanks. \$\endgroup\$ Oct 16, 2023 at 10:21
  • \$\begingroup\$ you're most welcome! nice question! \$\endgroup\$ Oct 16, 2023 at 10:22
8
\$\begingroup\$

The LM393 (and many other opamps and comparators) has a common mode range that inputs must lie within for the device to function correctly.

For the LM393 this range is

  • VS = 3 to 36V
    Range = (V–) to (V+) – 1.5 V

  • VS = 3 to 36V, TA = –40°C to +85°C <-- ie for full specification
    Range = (V–) to (V+) – 2.0

However, the LM393 is unusual, and more flexible than most comparators in that only one of the two inputs must lie in this range, while the other has less damanding requirements.

Page 5 of the datasheet says

  • The voltage at either input should not be allowed to go negative by more than 0.3 V otherwise output may be incorrect and excessive input current can flow. The upper end of the common-mode voltage range is limited by VCC – 2V. However only one input needs to be in the valid common mode range, the other input can go up the maximum VCC level and the comparator provides a proper output state. Either or both inputs can go to maximum VCC level without damage.
\$\endgroup\$
2
  • 1
    \$\begingroup\$ The last fact explains why SET part works properly as it works at lower voltages and RESET part doesn't work as it works at higher. Thanks. I will be careful while choosing comparators from now on. \$\endgroup\$ Oct 16, 2023 at 10:22
  • \$\begingroup\$ @CaveScientist As I noted, this is a somewhat unusual capability. Many comparators and opamps just have a Vcm mode that always applies to both inputs. The LM293 allowing one input to assume any otherwise legal value is a bonus. \$\endgroup\$
    – Russell McMahon
    Oct 17, 2023 at 10:20
5
\$\begingroup\$

A tricky issue with comparators, which data sheets aren't always clear about, is that the term "common mode range" may describe any three different concepts:

  1. A range beyond which inputs may be "pegged", causing excessive current to flow in the device and perhaps causing damage.

  2. A range beyond which inputs may behave as though they are "pegged", without causing device damage. If both inputs are above the the range or both are below the range, either input may behave as though pegged at a level above or below the other, meaning the output might be arbitrarily high or low. If only one input is above the top of the range, however, it would be above the other input even if pegged to the top of the range, and likewise if below the bottom.

  3. A range which, if exceeded, would not cause damage to the device but might cause unpredictable behavior if exceeded by either input. Raising an input above the top of the range may cause the device to behave as though it is below the bottom of the range, or vice versa. This behavior can cause some comparator-based circuit designs to "get stuck", if they try to use a comparator's output to bring a voltage back in range. Once an input gets far enough above the top of the range to make the output report it as being lower than the other input, a feedback loop which causes that input to go higher whenever it's lower than the other would push that input further out of range.

Unfortunately, data sheets aren't always clear on which kind of limitation applies near the positive rail and near the negative rail. As Russell McMahon notes, the LM393 data sheet is nice in that regard, but many data sheets aren't.

Incidentally, if anyone is curious why behavior #3 would occur, the following is a simplified but conceptually typical comparator design. You may click "simulate" link below, then the "Simulate" button and "Run time domain simulation" to see how it works.

schematic

simulate this circuit – Schematic created using CircuitLab

Notice that most of the time, the output will be low when the slowly-changing signal is below the quickly-changing one, but when the slowly changing signal approaches ground the output will go high. This happens because the output goes low in response to current flowing from the collector of Q2 into the base of Q3. This requires not only Q2 be turned on, but also that its emitter voltage be higher than the collector (which is tied to Q3's base). If the base input is too low, Q2 will be switched on, but the current flowing from the emitter to the base will pull the emitter too low for it to convey any current to Q3's base.

Comparator ICs use more than three transistors, of course, but many have an input stage which is somewhat similar to this. Comparators that are designed for "rail to rail" operation often combine a circuit similar to this one with a circuit that's essentially a "mirror image" version where the input transistors would ground an output signal in response to a higher voltage (which would work well near the bottom rail, but fail near the top rail), and then switch between the outputs of the two circuits as needed to yield correct operation.

\$\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.