Experimenting with comparators failed: sine to square - Page 1
Forum section: electronics / beginners

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 11:34:17 am
content: Hi.What I want to do is turn my 10M sine wave (from an arb currently, set at 1Vpp, Hi-Z output) to a square wave. As simple as that.I thought of using a comparatorr and I had a bunch of TLV3501(datasheet) lying around and thought of using one. The shutdown function will come in handy, but currently its SHDN pin has been tied to ground.You can find a schematic (with a generic comparator) hereNow when I probe the output of the comparator I expect some kind of square wave, but instead I have a perfect 110MHz sine wave. Incidentally the same happens when I apply no input. But the input is there (probed it). So there is something I am doing wrong. Can you help me please? Do I need some kind of load? A 10k or 100k resistor won't do the trick.Thanks

author: tszaboo
author_rank: Super Contributor
timestamp: January 01, 2021, 12:01:38 pm
content: As a start, you should terminate your input. 50 Ohm to GND sounds like a good idea.

author: S. Petrukhin
author_rank: Super Contributor
timestamp: January 01, 2021, 12:39:48 pm
content: How did you observe the signal at the output of 110 MHz to make a conclusion about the shape of the output signal?

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 01:02:10 pm
content: Quote from: NANDBlog on January 01, 2021, 12:01:38 pmI tried 50 Ohms termination not to GND but to the point where the external conductor of the coax is connected. It still looks awful BUT it's a 10MHz and looks like a squarewave. I don't know why the signal sucks. Maybe sloppy setting? (Breadboard, leads too long, no shielding) Or is there something that could blatantly influence the result and I've not taken into account? Perhaps I should really terminate to GND and not the midway point?I'm sorry if I sound noob but I usually work with dc and I am unfamiliar with these thingsanyway the psu is stable and clean so the noise definitely does not come from that

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 01:03:56 pm
content: Quote from: S. Petrukhin on January 01, 2021, 12:39:48 pmI think I do not understand the question since I can only come up with stupid answers. Would you care to clarify please?

author: S. Petrukhin
author_rank: Super Contributor
timestamp: January 01, 2021, 01:14:19 pm
content: Quote from: Moriambar on January 01, 2021, 01:03:56 pmYou just wrote that 10MHz looks good. At 110MHz, not many oscilloscopes can show a rectangular signal beautifully. And not all probes can provide the passage of such a signal. At a minimum, you need to select the x10 mode on the oscilloscope probe. And watch Dave's video about it.

author: ledtester
author_rank: Super Contributor
timestamp: January 01, 2021, 01:16:14 pm
content: Quote"ac coupling" is a standard technique to change the DC offset of a signal. Have a look at this stackexchange answer:https://electronics.stackexchange.com/a/104165You might try feeding that into one comparator input and 2.5V into the other.Also, is the output of your arb floating or is it referenced to earth ground?

author: tszaboo
author_rank: Super Contributor
timestamp: January 01, 2021, 01:52:53 pm
content: Quote from: Moriambar on January 01, 2021, 01:02:10 pmWait, I just saw your schematic again...As a general rule, you should always connect the shielding of a coax to ground, direct connection, low impedance (short wide). If your signal is AC, and you dont want to have a negative rail, you should AC couple the signal.Or TI has a reference circuit:https://www.ti.com/lit/ug/slau505a/slau505a.pdf?ts=1609507214639&ref_url=https%253A%252F%252Fwww.google.com%252FChanging a few resistors might be necessary.

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 02:16:41 pm
content: Quote from: S. Petrukhin on January 01, 2021, 01:14:19 pmI am 10x. My intent was just probing the output, I did expect a 10MHz square wave. I definitely did not expect the 100MHz sine, so my setup is definitely not up for it. What I meant is that I could measure the input 10MHz and it was fine

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 02:19:23 pm
content: Quote from: ledtester on January 01, 2021, 01:16:14 pmSo you're basically saying to ac couple the ouput of the signal and later bias it?I think it's earth referenced that's why the scope reference is takne on the reference of the arb

author: CaptDon
author_rank: Super Contributor
timestamp: January 01, 2021, 02:22:08 pm
content: Your coax shield has to go to ground!!!! Why did you connectthe ground braid to a mid-point???

author: Wallace Gasiewicz
author_rank: Super Contributor
timestamp: January 01, 2021, 02:40:47 pm
content: I just use a NAND gate to change sine to square. Just connect both inputs to same sine wave (center conductor of generator) and shield to GND.Works fine.You may have to isolate with cap if your source has DC on it.You may need a cap to GND on the V+ of the NAND chip. Usually a 2.2 uF cap.The logic gates I have used require much more than ONE volt signal to work.I have not tried just a comparator for this.From the data sheet, the comparator you are using only requires the one volt you are using (or less). Maybe you need pull down resistor on the input. Perhaps a cap to GND at V+. However what ref voltage are you using? Should the ref volt be close to zero? I looked at you schematic ref volts are half of V+ which is way above your input.Maybe try higher voltage input? Is your ref voltage input (gnd) stable?

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 02:59:09 pm
content: Quote from: CaptDon on January 01, 2021, 02:22:08 pmWhy so?And I did 'cause I do not know anything, and I wanted my signal biased but did not think of any better solution. Can you point me towards explanations please?

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 02:59:55 pm
content: Quote from: NANDBlog on January 01, 2021, 01:52:53 pmYea, following that link has definitely improved the circuit to the point that I really need to shorten the lead and do it better. Thanks

author: Zero999
author_rank: Super Contributor
timestamp: January 01, 2021, 04:04:06 pm
content: The data sheet for the TLV3501 says it has a maximum toggle frequency of 80MHz, so you shouldn't expect this to work.https://www.ti.com/lit/ds/symlink/tlv3501.pdfUse a fast Schmitt trigger logic IC, such as the 74LVC1G14, with the input biased to half the supply and the input AC coupled.https://assets.nexperia.com/documents/data-sheet/74LVC1G14.pdf

author: jpb
author_rank: Super Contributor
timestamp: January 01, 2021, 04:19:05 pm
content: If you just want to produce the square-wave rather than design and build your own circuit, then one option is to use this board (I use them for a similar purpose) but they are a bit pricey (depends how much you value your time).Alternatively it will give you a working circuit you could modify:https://www.digikey.co.uk/product-detail/en/analog-devices-inc/DC1766A-A/DC1766A-A-ND/3973495

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 05:53:31 pm
content: Quote from: Zero999 on January 01, 2021, 04:04:06 pmwhy 80MHz toggling frequency is not enough for 10 MHz sine waves?

author: S. Petrukhin
author_rank: Super Contributor
timestamp: January 01, 2021, 05:56:59 pm
content: Quote from: Moriambar on January 01, 2021, 05:53:31 pmOriginally you were talking about 110 MHz.

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 06:01:07 pm
content: Originally you were talking about 110 MHz.No, perhaps my English failed me, in my original post I saidQuote from: Moriambar on January 01, 2021, 11:34:17 amBut then I ran into problems specifically:Quote from: Moriambar on January 01, 2021, 11:34:17 amI'm sorry for the misunderstanding but I expected a 10MHz sinewave converted into a 10MHz square wave, instead I have a perfect 110MHz sine wave at the output.The problem is solved now, more or less. I have my 10MHz square wave, I just have to adjust leads and caps values to make the whole thing better (it's a poor shape).Thanks and sorry again for the mishap

author: hugo
author_rank: Regular Contributor
timestamp: January 01, 2021, 06:09:58 pm
content: This simple circuit works fine (I've used a HCT4093 but it was a long time ago):

author: Zero999
author_rank: Super Contributor
timestamp: January 01, 2021, 07:57:01 pm
content: It was me who misunderstood. The original post was quite clear that input is a 10MHz sine wave. The CD4093B is marginal at 10MHz, with a 5V supply, so might work, but be unreliable.The TLV3501 should be fine. You'll probably need to add some hysteresis. Is there a decoupling capacitor? It wasn't one on the schematic. What about the layout? Is it on a breadboard?Try this.

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 08:03:27 pm
content: Quote from: Zero999 on January 01, 2021, 07:57:01 pmYes there are two decoupling, one on the main line, and 100nF right beside the comparator. May I ask the purpose/functioning of that feedback loop? I mean, how will this ensure that the sine will be "centered" between 5V and GND?Regarding your second question: yes right now it's on a breadboard and I know that is FAR from optimal. But many posts confirmed what I suspected: the maing problems were due to my ignorance and not the setup (this will be the cause of other problems later).Thanks

author: S. Petrukhin
author_rank: Super Contributor
timestamp: January 01, 2021, 09:13:14 pm
content: The output signal will be between Gnd and Vcc because the comparator is powered by Gnd-Vcc and it will never output less than Gnd and more than Vcc. Feedback is needed to create a hysteresis-the difference between the voltage on (it will be slightly higher) and off. This is necessary to avoid commotion/biunsin at the switching point. After reaching the on point, the comparator will push itself up to quickly move away from this point.The voltage at the inverting input will set the switching threshold, and you can use this voltage to shift the switching phase. Since a separation capacitor is added to the circuit, it will eliminate the constant component ov input voltage and you can connect the inverting input to Gnd. In fact, you get a zero detector of the beginning of the period in this way.

author: Moriambar
author_rank: Unknown
timestamp: January 01, 2021, 09:27:44 pm
content: I tried the hysteresis thing but the output is always 0 then

author: S. Petrukhin
author_rank: Super Contributor
timestamp: January 01, 2021, 09:32:03 pm
content: Quote from: Moriambar on January 01, 2021, 09:27:44 pmThis means that the input signal was insufficient. You are applying 2.5V to the inverting input, hence switching requires a voltage slightly higher than 2.5V. Connect the inverting input without a divider to Gnd and you will get switching at a point very close to zero of the input signal.

author: S. Petrukhin
author_rank: Super Contributor
timestamp: January 01, 2021, 09:34:02 pm
content: You may have damaged the input signal by feedback - it puts a load on the signal source, sometimes this requires a buffering amplifier.

author: radiolistener
author_rank: Super Contributor
timestamp: January 02, 2021, 02:46:49 am
content: Here is Chinese TLV3501 module for 3 USD:https://www.aliexpress.com/item/4000543686133.htmlI tested it from 1 kHz to 80 MHz - works ok.And here is how it works:

author: radiolistener
author_rank: Super Contributor
timestamp: January 02, 2021, 02:53:05 am
content: Also, here is frequency counter on TLV3501.I didn't tried it, but may be it will help you:

author: Moriambar
author_rank: Unknown
timestamp: January 02, 2021, 08:24:17 am
content: Quote from: S. Petrukhin on January 01, 2021, 09:34:02 pmsweet

author: vk6zgo
author_rank: Super Contributor
timestamp: January 02, 2021, 11:55:14 am
content: Quote from: Moriambar on January 01, 2021, 11:34:17 amHow do you manage to use a comparator to increase your input frequency by a factor of eleven?If you can reproduce this you are financially "set" for life, especially, if you can achieve other multiplication factors.Maybe your comparator coincidentally, just likes to oscillate at 110MHz?Have you checked for output with the input wiring connected, but the 10MHz source turned off?

author: Wallace Gasiewicz
author_rank: Super Contributor
timestamp: January 02, 2021, 12:55:25 pm
content: S. Petrukhin is correct. The input voltage and the reference voltages have to "cross" in order for the comparator to change output from pos to neg (or the other way)Your input is plus minus one volt and your reference is +2.5 volt. The input never "crosses" the reference voltage. Input has to get to at least 2.5 Volts to change output, and then go below 2.5 V to change again to get your square wave.Can you increase your input voltage to 3 volts??? That would be 6 volts peak to peak. You will then get a square wave that goes from zero to VCC and back.OR as I said before try setting the reference to GND.There are circuits that do use the comparator for an oscillator,but 110 MHZ???Probably intrinsic to the comparator somehow?

author: Zero999
author_rank: Super Contributor
timestamp: January 02, 2021, 01:08:30 pm
content: Quote from: vk6zgo on January 02, 2021, 11:55:14 amWe haven't seen the layout: poor construction can cause oscillation. If it's built on a breadboard, with the TLV3501 on one of those SMD to DIP adaptor boards of course, it wouldn't be surprising if it oscillates.As far as multiplying the frequency by 11 is concerned: harmonic filtering is a method to multiply one frequency by a fixed amount, but it only works over a limited frequency range. It's not impossible that there's a tuned circuit at around the 110MHz mark which is selecting the 11th harmonic, in which case increasing/decreading the input frequency a little will cause the output frequency to change proportionally.

author: David Hess
author_rank: Super Contributor
timestamp: January 02, 2021, 10:49:04 pm
content: The reference voltage can be derived from the input using the "data slicer" configuration.Alternatively the reference voltage can be derived from the output to force a 50% duty cycle.

author: vk6zgo
author_rank: Super Contributor
timestamp: January 03, 2021, 01:03:29 am
content: Quote from: Zero999 on January 02, 2021, 01:08:30 pmNot impossible, but most unlikely.A "one step" frequency multiplication of 11 times is very far from the standard frequency multiplication schemes that were used in the past, which mainly used cascaded frequency doublers & triplers, with theveryoccasional quadrupler.The problem with "one step" frequency multiplication by large multiples (& why it was rejected as a viable method), is that the amount of harmonic energy available to provide the multipled output is minimal at the higher harmonics.If it was found unsatisfactory, even with dedicated high "Q" LC resonant circuits, it makes the possibility of it happening "accidentally", unlikely in the extreme.Another possibility arises, that the comparator is in fact, oscillating at around 110MHz, but it has become "locked" to the incoming 10MHz signal.To my mind, it would be more likely to lock to 100MHz, though.The possibility of oscillation is why I suggested the OP leave all the input connections in place, & just turn off the 10MHz source,then check what appears at the output.Even if a signal around 110MHz appears at the output, the possibity of "locking" as mentioned sbove still remainsThe best way to check if the input & output signals are in sync would be to monitor the 10MHz signal on one channel of an Oscilloscope, triggering from that input, & look at the 110MHz output on the other channel.If the latter is stationary on the display, it is, somehow, related to the input 10MHz signal, if not, it is just an unrelated oscillation.

author: Moriambar
author_rank: Unknown
timestamp: January 03, 2021, 03:40:44 pm
content: So I discovered many many mistakes but not everything is solved.Now I have my input signal AC-coupled and I have then biased it in order to obtain some kind of 10MHz square wave.The result is horrible, but I do not think this is due to the setup directly, since this time touching the leads does not yield anything different.Is there any way to clean up the signal? Unfortunately now I'm not at my bench so I can't quickly check other things.Thanks

author: Zero999
author_rank: Super Contributor
timestamp: January 03, 2021, 05:59:49 pm
content: Quote from: Moriambar on January 03, 2021, 03:40:44 pmIt looks like poor construction. Please post a photograph of the actual circuit.

author: Moriambar
author_rank: Unknown
timestamp: January 04, 2021, 01:12:52 pm
content: I can't take a picture now, unfortunately. But I think the problem is somewhere else.Here's my new schematicWhat I notice is that probing V+ and V- looks ok, meaning that I see the V- value crossing more or less halfway the 2Vpp 10MHz sine. That looks fine too.My scope probes are GND referenced and set to 10x.When I probe the output of the comparator though I get a waveform that is an ugly excuse for a square wave. It is 10MHz, and it is basically very similar to the pic I posted above.Using some kind of cap from V- to GND remove the jitter, but then I noticed that probing the output actually disturbed the input: probing V+ (channel 1), V- (channel 4) and the output (channel 2)I have the following pic.As you can see V- is "disturbed"(V+ too, but to a lesser extent) by the probe on the output, with around 1Vpp.So I think that I did not either listen to something important or understand something important.If anyone wants to help, thanks!

author: David Hess
author_rank: Super Contributor
timestamp: January 04, 2021, 04:45:16 pm
content: The problems do look like poor layout and poor decoupling, but high source impedance can also cause oscillation. Jim William wrote about problems with comparators specifically:https://www.analog.com/media/en/technical-documentation/application-notes/an13f.pdf

author: Moriambar
author_rank: Unknown
timestamp: January 04, 2021, 05:41:16 pm
content: Quote from: David Hess on January 04, 2021, 04:45:16 pmthis is a wonderful read, thanks.My mistake was: long ground leads.Now I'll just have to adjust the V- voltage in order to have 50% duty cycle, I think I can pick it up from here.thanks for the link again