Comparator misbehaviour - lend a brother a hand... - Page 1
Forum section: electronics / projects

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 06, 2025, 06:59:37 am
content: Hello folks,I have this fairly straightforward schematic:It's been giving me a headache so I was hoping to get some pointers. Ideally, when writing this out, rubber ducking this as I'm doing now should yield some answers, otherwise I trust the combined brainpower of this forum should get me a hint or twoA signal between 0.3-4.75V should yield a logic '0', the input signal has an offset of about 100mV and that should yield a logic '1'. Originally, I wanted to achieve this with the comparator and include some hysteresis to improve noise immunity. I calculated the thresholds to be 0.15-0.25V or thereabouts. Weirdly, the lower threshold was only 0.1V or so. This was already something I didn't (and don't) get. Originally, I thought input bias current might set things askew but according to the DS (https://www.onsemi.com/download/data-sheet/pdf/ncs2250-d.pdf) that should be an order of magnitude lower. I started tuning R4 to raise the threshold again, it still didn't work as intended so I figured to forget about the hysteresis (at least for the time being) and get the rest of the circuit to work before maybe revisiting that.So I replaced R4 with 33k and got rid of R6. The idea was to get a stable and predictable reference voltage.It didn't work that way. In yellow the input signal, in green the +IN pin. That is... not stable. Now, I can hit it with a hammer (ie put a 100n cap or something) but I don't like sweeping something under the rug I don't understand. In addition, that would kinda eliminate the possibiity of revisiting hysteresis after.(Minor disclaimer: I'm not doing the actual probing myself, that is being done about 1000km away from me)So... any ideas? Why was the original threshold voltage "off"? Why is the voltage devided output so unstable? Would love to hear some thoughts.

author: moffy
author_rank: Super Contributor
timestamp: March 06, 2025, 07:23:23 am
content: It looks like capacitive coupling between the output and input, possibly internal to the comparator. Reduce the resistor values by a factor of 10 and the noise should reduce accordingly. That might also affect the offset issue, and leaves open the use of hysteresis, but at the cost of increased power consumption.

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 06, 2025, 08:07:46 am
content: Thanks! I'll have a look. Don't care that much about power consumption, so that would be acceptable. Also had a look at the layout to see where I might get some coupling.Let's just say that in my mind I did a better job. There are limits to what you can do with a dense 2-layer board but it's not great nonetheless.

author: mtwieg
author_rank: Frequent Contributor
timestamp: March 06, 2025, 12:27:38 pm
content: Agree with moffy. In fact there doesn't seem to be any DC feedback at all; the +IN pin seems to always settle to the exact same DC level regardless of the input/output level. Almost as if R6 had been replaced by a small capacitor.

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 06, 2025, 01:04:56 pm
content: For the above test I tossed R6 (in essence to make it a comparator without hysteresis, to simplify things). Possibly there's enough parisitics there, possibly due to poor layout..

author: temperance
author_rank: Super Contributor
timestamp: March 06, 2025, 01:20:50 pm
content: You might want to read this part of the data sheet:QuoteYou probably have a decoupling capacitor close to the IC and that, considering the fact that you have a two layer PCB, the power supply trace inductance towards the IC is resonating with the decoupling capacitor when the output stage changes.You can try a small series resistor in series with the IC before the decoupling capacitor to dampen the oscillation.About the trigger level:QuoteWithout R6 and 475 K and 10 K the trigger level is about 100 mV. So I think that R6 is broken, bad solder joint, probed to death,...

author: mtwieg
author_rank: Frequent Contributor
timestamp: March 06, 2025, 01:35:28 pm
content: Quote from: Ice-Tea on March 06, 2025, 01:04:56 pmOops, missed that in your first post.Yeah there is something bizarre going on when looking closer at the waveforms. It seems that both rising and falling edges of IN- cause drops in IN+ (most of the time...?), which isn't explain by a bit of capacitive feedback. Can you take a scope capture showing the comparator output as well (or just IN+ and output if you only have a 2 channel scope)?

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 06, 2025, 01:39:45 pm
content: Quote from: temperance on March 06, 2025, 01:20:50 pmHadn't considered that... I should be able to see that on the supply, pin then. I'll have a look.

author: xvr
author_rank: Frequent Contributor
timestamp: March 06, 2025, 01:41:06 pm
content: QuoteHm. I got thresholds (with R6 influence) as 0.1-0.24V Close to your real numbers.Do not forget that R6 should be taken in account for both comparator output states: in High it will be connected in parallel to 475K resistor, in low - to 10K

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 06, 2025, 01:47:18 pm
content: Quote from: mtwieg on March 06, 2025, 01:35:28 pmNo worries. Not like I'm paying you big bucks to help me out ;-) A gift horse and all that.I'll have a look at the out later on. There's some logistics involved

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 06, 2025, 02:10:07 pm
content: Quote from: xvr on March 06, 2025, 01:41:06 pmEh? It's been a few weeks, think I used an online calculator for that. Guess I'll have to recheck at least... Thanks!

author: temperance
author_rank: Super Contributor
timestamp: March 06, 2025, 04:56:27 pm
content: The trigger levels are:$$\frac{5 V}{475 K || 330 K + 10 K}.10 K= 244 mV$$$$\frac{5 V}{475 K + 330 K || 10 K}.330 K || 10 K= 100 mV$$

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 07, 2025, 07:36:20 am
content: The other way around me thinksSolved part of the mystery. I swapped the 475k and 330k resistor aroundThat's why it deviated from my calculations (by which I mean the online calculator I found).

author: temperance
author_rank: Super Contributor
timestamp: March 07, 2025, 02:07:46 pm
content: I corrected my mistake.So the schematic was wrong.

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 09, 2025, 08:59:07 pm
content: As I have the analog braintrust on the line, might as wellabuseuse it a bit more ;-)The above comparator is fed by a transimpedance amplifier.Mostly works, the 0.5p is not equiped. I know there's a risk of instability, but it seems to be OK. I'm guessing the parasitics maybe are enough? In yellow, output of the amp. In green, output of the above comparator. The weird thing is rising and falling edges.. seem to slow down? The first portion of the slope is quite fast, then it tapers off. At first I thought it was just the bandwidth limitations showing but it seems like the first part of the edge corresponds to what I would expect, the second does not? Dicked around a bit with LTSpice, there itdoesneed 0.5p to be stable enough but otherwise it works as it should. Corresponding more to the initial "fast" slope, rather than the slow one. Based on the dicking around, I will probably add a cap to keep the reference more stable, but I'm not sure if that explains the weird stuff.The problem with the weird stuff is that it happens around the threshold of the comparator and thus it introduces huuuge amounts of delay.Pretty sure I'm just hitting the limits of my analog kung-fu, so again, wouldn't mind a consult ;-)

author: mtwieg
author_rank: Frequent Contributor
timestamp: March 10, 2025, 12:23:00 pm
content: Quote from: Ice-Tea on March 09, 2025, 08:59:07 pmHard to tell if the transimpedance amp is working properly by looking only at its output and not it's input. Are you sure the light source driving D3 has nice rectangular edges?You should definitely add C3 (should adjust its value empirically), clearly the amplifier output is has a tone of overshoot/ringing on it.

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 10, 2025, 12:55:27 pm
content: Quote from: mtwieg on March 10, 2025, 12:23:00 pmAccording to the specification it should... Kinda difficult to check as for that I'd need a photodiode and transimpedance appQuoteDoing that right now. Not a lot of margin, though. If I add more than 0.5p the BW is gone..EDIT: re overshoot, pretty sure that's probing error. I'm not doing that myself and peaks correspond more to another channel than actual overshoot...

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 12, 2025, 07:47:25 am
content: My guess is there's already about 2p's worth of parasitic capacitance for the feedback cap (and that's too much).- cheap 0805 thick film resistor from chinese resistor kit- hand soldering- GND not cleared around input pins- other black voodoo stuff

author: mtwieg
author_rank: Frequent Contributor
timestamp: March 12, 2025, 12:57:07 pm
content: Quote from: Ice-Tea on March 10, 2025, 12:55:27 pmHere's a suggestion: try measuring the response of the TIA circuit by injecting signal via a function generator as shown in the attached schematic. Leave the photodiode in place so its capacitance is properly represented, but couple in with a relatively large resistance (R4) so it doesn't significantly affect the impedance at the inverting input. R2 is part of the function generator, and C2/R3 help minimize distortion while not affecting the biasing conditions of the circuit.QuoteMaybe. Easy way to check would be to disconnect/disable the comparator and just watch the TIA output.Quote from: Ice-Tea on March 12, 2025, 07:47:25 amWhat makes you think 2pF is "too much"? If that's what's required to make the circuit stable, then it's necessary (unless you can reduce capacitance at the inverting input somehow).Quote from: Ice-Tea on March 12, 2025, 07:47:25 amTypical parasitic capacitance of SMT resistors is on the order of tens of femtofarads (AFAIK there's no significant difference between thick and thin film). IMO it's unlikely that even the cheapest "chinese" resistor is going to be much more.Simple way of estimating the parasitic feedback capacitance is to measure bandwidth while adding capacitance. For example if adding 3pF causes bandwidth to decrease by a factor of 4, then your baseline capacitance is 1pF.

author: Ice-Tea
author_rank: Super Contributor
timestamp: March 13, 2025, 06:51:16 am
content: Quote from: mtwieg on March 12, 2025, 12:57:07 pmThat makes a lot of sense, thanks.QuoteI'm comparing to some simulated feedback capacitances. Simulated, it's unstable with nothing, fine with 0.5p (also fast enough), with 2p it seems BW limited and the waveform looks a lot like what I observe.RL, it's perfectly stable without a feedback cap but also seems as limited as with 2p in the simulation. 0.5p doesn't really move the needle, so I'm guessing it's ratiod by whatever is already present in the circuit.QuoteThere's preciously little models available but the ones I found after writing the above confirm what you are saying: something like 40-50fF for 0603, 60 or so for 0805. No real difference between thin and thick. Bit less than what I thought it would be.QuoteWhich is more or less how I figured there must be a few p already there... Another option might be simply not having enough GBP in the opamp. So the current plan is to :- continue poking around- I have a few opamps with higher GBP on order- revise the layout, pull away gnd around input pins and feedback path.Thanks for helping out!