EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: Ditch on February 04, 2021, 07:59:08 pm

Title: Simple Comparator Problem
Post by: Ditch on February 04, 2021, 07:59:08 pm
Hi There,

Noob here so please be gentle with me. I thought I had my head around Comparators and how they work but I can't seem to get my circuit to operate as I expected. I'm sure this is me missing something!

I've created the circuit shown in the image but with 12v applied to or removed from pin 3 of the Comparator, the output is always 5v?

I was expecting the output to pull down to 0v without the 12v being applied to pin 3 and raising to 5v (vcc) when the voltage is applied but i get a steady 5v no matter what.

The microchip pin RC4 is set as an input and if I short RC4 to 0v then the microchip accepts this input.

I have the same circuit on input B of the Comparator.

Any help, advice or pointers would be very much appreciated.

Ian


(http://fasecontrols.co.uk/Comparator.png)



Title: Re: Simple Comparator Problem
Post by: Benta on February 04, 2021, 08:05:51 pm
Your input voltages are waaay outside the operating envelope of the LM393. One is +12 V, the other is +9 V. This at a supply voltage of +5 V.

If you're the lucky, the LM393 survived.

Title: Re: Simple Comparator Problem
Post by: Ditch on February 04, 2021, 08:14:25 pm
Ok. Thanks Benta.

So do I need to keep the input voltages to the Comparators in pins below Vcc?

Ian
Title: Re: Simple Comparator Problem
Post by: ataradov on February 04, 2021, 08:21:42 pm
Yes, you do. The maximum voltages on the pins are specified in the datasheet. Usually they are specified in relation to the VCC. Something like VCC+ 0.6 V.

The part would have survived with resistors like that.

It would actually work if you just flip R2 and R3. It will give you ~3V threshold.

But you also don't want to leave the input floating if there is no voltage on the R4.

Adding correct resistor dividers on both inputs would solve all your problems.
Title: Re: Simple Comparator Problem
Post by: Ditch on February 04, 2021, 08:29:22 pm
Ha. Thanks for your help.

Would the easiest way to solve this to simply supply the Comparator with a 12v supply. The datasheet says supply voltage max of 36V.

Ian
Title: Re: Simple Comparator Problem
Post by: ataradov on February 04, 2021, 08:30:29 pm
Sure. That would work too.

What are you actually trying to do?
Title: Re: Simple Comparator Problem
Post by: Benta on February 04, 2021, 08:31:57 pm
Yes, you do. The maximum voltages on the pins are specified in the datasheet. Usually they are specified in relation to the VCC. Something like VCC+ 0.6 V.

That would be the "Absolute maximum rating".

The LM393 datasheet is not very nice on this point.

The relevant section is "Recommended operating conditions", which specifies an input voltage range of 0...Vcc-1.5 V. In your case 0...+3.5 V.

Title: Re: Simple Comparator Problem
Post by: Benta on February 04, 2021, 08:34:12 pm

Would the easiest way to solve this to simply supply the Comparator with a 12v supply. The datasheet says supply voltage max of 36V.


No. In that case your maximum input voltage should be limited to 10.5 V.
Use the resistor dividers instead.

EDIT: and unless your input signal is sharp with fast, well defined edges: add hysteresis. This is almost always good practice.

Title: Re: Simple Comparator Problem
Post by: Ditch on February 04, 2021, 08:56:29 pm
Thanks Guys,

I'm trying to bring input into the microchip from a remote key switch (external cabling).

I think I'll do the voltage divider thing and keep the Comparator inputs below 5v.

I only need this input to switch on. Once it has the microchip latches this until rebooted so hysteresis shouldn't be a problem.

Thanks for your help.

Ian
Title: Re: Simple Comparator Problem
Post by: ataradov on February 04, 2021, 08:58:04 pm
Why do you even need a comparator?

Just divide your external voltage and feed it into the MCU pin. You may want to think about input protection if the cabling is long. But as a first approximation a simple divider would work.
Title: Re: Simple Comparator Problem
Post by: Benta on February 04, 2021, 09:03:49 pm

I think I'll do the voltage divider thing and keep the Comparator inputs below 5v.


Keep them below 3.5 V as per previous posts (and the datasheet).
Title: Re: Simple Comparator Problem
Post by: Ditch on February 04, 2021, 09:59:59 pm
Why do you even need a comparator?

Just divide your external voltage and feed it into the MCU pin. You may want to think about input protection if the cabling is long. But as a first approximation a simple divider would work.

Is that acceptable practice? I'm using the comparator to protect the microchip from external influences which in my mind is the better option? Could I simply use a divider, a bit of filtering and Zener diodes to protect the microchip? Sorry if I'm sounding dumb, I'm learning as I go!

Ian
Title: Re: Simple Comparator Problem
Post by: ataradov on February 04, 2021, 10:27:32 pm
Yes, it is acceptable and common practice. Your comparator is also a silicon device, so if you think that your system may have interference capable of affecting silicon devices, then you still need protection.

Typically protection would include at least a current limiting resistor and a pair of Schottky diodes to the power and ground rails of the device. This is at the minimum. Depending on the environment and how robust your device needs to be, you may need to add more protection (TVS devices, RC filters, ferrite beads).

And in the extreme case you may need to resort to using optocouplers.
Title: Re: Simple Comparator Problem
Post by: Ditch on February 04, 2021, 10:41:09 pm
Thanks ataradov, you're an absolute gent.

I think I'll go down this route.  :-+