Not-quite constant current charging of cap. in ramp generator - Page 1
Forum section: electronics / beginners

author: aneevuser
author_rank: Frequent Contributor
timestamp: February 27, 2020, 03:47:03 pm
content: I have a ramp generator circuit that I've been playing around with. It's based on a non-inverting LM311 with some offset hysteresis:The voltage at point A looks as shown in the saved image from a scope:When the cap. starts to charge, there is a distinct non-linearity at the start. I had assumed that this was due to the fact that when Q2 is off, then the current source is feeding the cap. in parallel with the 47K and 120K resistor chain, and I "proved" this by disconnecting point A from the 47K, and driving point B with a ramp from a sig. gen. under which circumstances the cap. charges nice and linearly as expected.However, having analysed the response of a current source feeding a parallel RC circuit, it turns out that it doesn't look much like what I'm seeing on the scope trace at all (it's roughly a \$1-e^{-{t/RC}}\$ curve, which is very linear for small \$t\$).So the question: can anyone explain what's going on at the start of this voltage ramp, given the circuit as shown? I'm baffled.

author: Tom45
author_rank: Frequent Contributor
timestamp: February 27, 2020, 04:02:07 pm
content: What do you see at A if you replace the capacitor with a 4.7K resistor? The trace seems to start at close to 2 volts now. That makes me think there is something wrong with your constant current circuit. Or maybe Q2 isn't turning on fully?

author: aneevuser
author_rank: Frequent Contributor
timestamp: February 27, 2020, 04:11:43 pm
content: Quote from: Tom45 on February 27, 2020, 04:02:07 pmThe upper and lower thresholds of the Schmitt trigger are about 3.4V and 1.5V so the cap. only charges and discharges between those levels. I don't think that there's a problem with the current source.Though you've made me think about Q2 now - maybe I'm overdriving it and it's taking time to turn on fully - excess base charge and all that?

author: Tom45
author_rank: Frequent Contributor
timestamp: February 27, 2020, 04:49:46 pm
content: It would be interesting to look at A on channel 1, base of Q2 on channel 2, and emitter of Q1 on channel 3. Then expand the time base to better see what is happening when Q2 switches off.

author: StillTrying
author_rank: Super Contributor
timestamp: February 27, 2020, 06:02:46 pm
content: Q2 will overshoot and stay on a bit but that doesn't explain the strange curve, it would be curved the other way.If nothing else fixes it I'd add a 100n decoupling to the inverting input.

author: aneevuser
author_rank: Frequent Contributor
timestamp: February 27, 2020, 07:52:11 pm
content: Quote from: StillTrying on February 27, 2020, 06:02:46 pmThanks. I've taken a look at the inverting input, and it bounces a bit when the o/p transitions - your suggestion of a 100nF decoupling cap fixes that nicely. It doesn't fix the other issue though.However, having thought about the base resistor of Q2, it seems that 120K or thereabouts is enough to drive the transistor into saturation, so 1K is massive overkill - I've swapped this out for a 200K pot, and the charging ramp looks far more linear (though not perfect :-( ) with base resistances > 100K.I'll put up some traces taken at A, the base and the emitter of Q2 tomorrow or at the weekend when I have some time.Anyway, I'm still confused but slightly less so - Q2 seems to be the culprit, I think. Maybe it'd be better with a FET?

author: Renate
author_rank: Super Contributor
timestamp: February 27, 2020, 09:44:48 pm
content: Let's do the math!It ramps about 1.5V in 1mS, right?1.5V*1mS*0.1uF=150uAIf you look at the base of your current source, you will probably see it moving all over.You could connect that to a real voltage source, or make the base resistors much smaller, or put a big cap on it.I like current mirrors, I'd probably replace it with two transistors.

author: StillTrying
author_rank: Super Contributor
timestamp: February 27, 2020, 10:43:01 pm
content: "If you look at the base of your current source, you will probably see it moving all over."Yes, could its base voltage be being temporarily charged by the fast edge through its own collector-base capacitance.The whole of the slope will have some slight curve because at its top ~10% of the constant current is then flowing though the 47k and 120k.

author: aneevuser
author_rank: Frequent Contributor
timestamp: February 28, 2020, 11:07:26 am
content: Quote from: Renate on February 27, 2020, 09:44:48 pmThe current is now set to about 250uA - it may have been 150uA when I took that pictureQuoteHere are the traces for:Q2 collector - channel 1Q1 collector - channel 2Q1 base - channel 3There's some movement but I don't know if you'd classify that as "moving all over"

author: Renate
author_rank: Super Contributor
timestamp: February 28, 2020, 12:20:10 pm
content: Well, just throw a cap on the Q1 base and see how much it changes.Your emitter resistor is only having 0.25 V, that's not a lot.The more voltage on the emitter resistor, the more accurate your current will be.Normally you'd use a zener supply on the base and a couple of volts from the emitter resistor.Ok, you don't have the headroom, because you're running 3V signal on a 5V supply.Since you don't have the headroom, just use a current mirror, the least headroom topology you can do.Another PNP with the collector/base going to the only resistor to ground.Q1 emitter to +5, base to new transistor collector/base, collector to cap.I presume that you actually want to do something with the ramp and not just take the comparator output?Put a unity follower opamp between the cap and the comparator.Now you have a low impedance output that you can use.That will get rid of the 10 microamps that the comparator is taking.

author: Tom45
author_rank: Frequent Contributor
timestamp: February 28, 2020, 02:51:45 pm
content: Quote from: aneevuser on February 28, 2020, 11:07:26 amSomething not right here. Q1 collector and Q2 collector are connected together. Yet the channel 1 and 2 traces are not the same.The base and collector of Q2 plus the base and emitter of Q1 would be interesting. Trigger on the Q2 base.

author: StillTrying
author_rank: Super Contributor
timestamp: February 28, 2020, 03:17:31 pm
content: I've simulated it, Q2's emitter and collector are reversed - maybe.If I simulate it with Q2 the right way around Q2 shorts the cap down to 0V, with Q2's emitter and collector the wrong way around the cap only goes down to 1.6V which is very similar to your first scope image.

author: aneevuser
author_rank: Frequent Contributor
timestamp: February 28, 2020, 03:24:22 pm
content: Quote from: Tom45 on February 28, 2020, 02:51:45 pmYeah sorry - I screwed up - channel 2 is looking at Q1 emitter. I'm a moron.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 28, 2020, 03:25:54 pm
content: You have the hysteresis resistors loading the capacitor; use the 311's "emitter" output and swap the input pins.Tim

author: David Hess
author_rank: Super Contributor
timestamp: February 28, 2020, 08:17:57 pm
content: It looks to me like the 311 is having trouble shutting Q2 off. I would add a 10s of picofarads bypass capacitor around the base series resistor.Quote from: StillTrying on February 28, 2020, 03:17:31 pmCapacitor discharge circuits sometimes reverse the collector and emitter of the discharge transistor to reduce saturation voltage but this requires much higher base drive because the current gain will be lower unless a chopper transistor is used.

author: aneevuser
author_rank: Frequent Contributor
timestamp: February 29, 2020, 11:17:47 am
content: Quote from: T3sl4co1l on February 28, 2020, 03:25:54 pmThis was my first assumption - when Q2 is off, the hysteresis resistors are in parallel with C and being fed by a current source, but this doesn't seem to explain the observed behaviour AFAICS - see my first post.QuoteI'm not sure what you're suggesting here - you mean drop the +ve hysteresis? Can you exapnd?Anyway, I'm not going to have time to look at this till next weekend now, but thanks for all the replies - I ought to add that at the moment my concern is not specifically to improve the ramp, but to understand why this specific configuration is behaving as seen.

author: Renate
author_rank: Super Contributor
timestamp: February 29, 2020, 12:22:19 pm
content: This is just going 'round and 'round with everybody speculating what the problem is without any experiments or changes to the circuit.So here's an experiment:Disconnect the collector of Q2.Set the scope on single trace.Ground the capacitor, then release it.Now try this with the 47k resistor disconnected.Right now we are only seeing 1.5V of ramp.We don't actually know how good the current source is.If we can see the whole 0-5V ramp we can tell if there are problems.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 29, 2020, 12:56:31 pm
content: Quote from: aneevuser on February 29, 2020, 11:17:47 amStill need hysteresis of course, but it can be applied to -in this way, so +in can be straight off the cap with no resistors.Tim

author: aneevuser
author_rank: Frequent Contributor
timestamp: February 29, 2020, 01:45:06 pm
content: Quote from: Renate on February 29, 2020, 12:22:19 pmIn my first post, I mentioned that I've tested this by disconnecting the current source from the 47K and driving point B from a sig. gen. Anyway, here's a trace of the Q1 collector when doing so, with the sig. gen. adjusted to allow complete charging of the cap. It looks reasonably good (if not perfectly linear) to me.Anyway, I have no more time for this this weekend so I shall have to leave it for now. Thanks to all.

author: aneevuser
author_rank: Frequent Contributor
timestamp: February 29, 2020, 01:49:26 pm
content: Quote from: T3sl4co1l on February 29, 2020, 12:56:31 pmCan you put up a sketch of this? I know how to apply offset hysteresis in both inverting and non-inverting forms, but you seem to be suggesting something different - not quite sure what you're getting at here.