EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: Peeps on July 14, 2018, 04:50:55 am

Title: Confusion about using a comparator to generate a square wave
Post by: Peeps on July 14, 2018, 04:50:55 am
(https://i.imgur.com/8kdBlwv.png)

This circuit which I found in an industrial electronic device uses an LM339 comparator to compare the offset sine wave to a reference voltage of 5V and creates an inverted square wave as a result. From what I've read, R2 exists to feed back some of the output to change the reference slightly to create a hysteresis effect although in simulation the reference voltage hardly changes.

What I don't understand and haven't quite been able to figure out is why the output square wave never goes above 5V. Regardless of the supply voltage, the square wave maxes out at 5V. I feel like it should go as high as Vcc but this is not the case. Can someone help this fool understand why?
Title: Re: Confusion about using a comparator to generate a square wave
Post by: oPossum on July 14, 2018, 04:56:17 am
Comparators are usually open collector or open drain. They will sink current, but not source current.
Title: Re: Confusion about using a comparator to generate a square wave
Post by: JS on July 14, 2018, 05:22:29 am
The voltage change would be only 1/121, since the ratio of the resistors is such. The reference won't change, but effectively it does by shifting the input signal by that ammount on the non inverting pin. There you will see a small jump when the voltage crosses the threshold. That's there as you said to generate hysteresis, so the noise while crossing the line doesn't make the output to jump back and forth before settling, or if the voltage crossing is too slow, the output could act as a linear amplifier making strange things, for this circuits you usually want some ammount of hysteresis.

JS

Title: Re: Confusion about using a comparator to generate a square wave
Post by: Peeps on July 14, 2018, 07:35:41 am
 |O thank you, I knew I was missing something obvious and that was it. I kept thinking about it in terms of a traditional op-amp and not a comparator.
Title: Re: Confusion about using a comparator to generate a square wave
Post by: JS on July 14, 2018, 02:53:14 pm
|O thank you, I knew I was missing something obvious and that was it. I kept thinking about it in terms of a traditional op-amp and not a comparator.
More like the opposite, it has POSITIVE feedback so it doesn't want to be stable, one state one the other, wich makes it stable (against the rails) and once it's there id doesn't want to go to the other state, it preferes to stay, till the change is big enough.

JS
Title: Re: Confusion about using a comparator to generate a square wave
Post by: mikerj on July 14, 2018, 05:46:57 pm
|O thank you, I knew I was missing something obvious and that was it. I kept thinking about it in terms of a traditional op-amp and not a comparator.
More like the opposite, it has negative feedback so it doesn't want to be stable,

It has positive feedback, in order to provide hysteresis.
Title: Re: Confusion about using a comparator to generate a square wave
Post by: JS on July 14, 2018, 08:44:22 pm


It has positive feedback, in order to provide hysteresis.

Yes, it does, thanks.

JS

Title: Re: Confusion about using a comparator to generate a square wave
Post by: Zero999 on July 14, 2018, 10:27:23 pm
Another option is to use a comparator with a push-pull output, such as the LMC6762 or TSX3702.
http://www.ti.com/lit/ds/symlink/lmc7211-n.pdf (http://www.ti.com/lit/ds/symlink/lmc7211-n.pdf)
https://www.st.com/resource/en/datasheet/tsx3702.pdf (https://www.st.com/resource/en/datasheet/tsx3702.pdf)