### Author Topic: Voltage ramp using RC circuit and opamp  (Read 6141 times)

0 Members and 1 Guest are viewing this topic.

#### Tim4444

• Contributor
• Posts: 13
##### Voltage ramp using RC circuit and opamp
« on: December 28, 2016, 07:19:29 pm »
Hello everyone,

I am trying to create a voltage source that initially increases in a ramp like manner and then stays stable.

To do this I am using an buffer opamp with an RC circuit circuit on the non-inverting input (picture attached). The idea is to feed an input voltage (Vin 3 V) into an RC circuit (R1 and C1), and then take the voltage across the capacitor and feed it into then non-inverting input - this will create a slowly rising voltage on the non-inverting input with a slope determined by the RC time constant (R1 and C1 give a tau of 4.7 s). To kick-start all of this I close switch 1 (picture).

Because I have opamp's Vout attached directly (no resistors, voltage dividers, etc) to the inverting input , I believe the voltage at the inverting input should match the voltage at the non-inverting input. I can then use this voltage to power an LED. Overall, when S1 is closed, the voltage across the LED should light up to full brightness after about 5 seconds (determined by RC,C1 time constant).

I tried this with the V+ and Vin being from separate sources and it worked well (I used a battery pack for the Vin and a power source for the V+). But, when I try having both the V+ and Vin from the same source, e.g. both from a power supply set at 3 V, the circuit does not work at all. Can anyone tell me why this is? I feel like there is something about opamps that I do not understand here (I am a beginner) - without knowing what happens in an opamp I thought thevoltage source (V+) should not affect the input voltage (Vin).

Tim

p.s. Switch 2 is just there to drain C1 when after use.

#### Benta

• Super Contributor
• Posts: 2608
• Country:
##### Re: Voltage ramp using RC circuit and opamp
« Reply #1 on: December 28, 2016, 07:54:27 pm »
There are quite a number of problems with your circuit. The first is, that driving an LED from a voltage source (your opamp) is a bad idea.
The immediate problem regarding your question is, that your opamp will either not work at 3 V, or that the opamp output will not supply enough voltage at a supply voltage that low.

Either way, it's not a viable design.

The following users thanked this post: Tim4444

#### Ian.M

• Super Contributor
• Posts: 9133
##### Re: Voltage ramp using RC circuit and opamp
« Reply #2 on: December 28, 2016, 08:47:56 pm »
Use a low voltage CMOS rail-to-rail output OPAMP, designed for 3V single supply operation, scale C1 down by a factor of 100 to 10uF and R1 up by the same factor to 470K, add 100R in series with S2 to limit the transient discharge current and add a suitable current limiting resistor in series with the LED, and it will perform as expected, provided the LED Vf<<3V, however if the object is to ramp up the LED brightness it will be piss-poor as the Led will not noticeably light below its Vf threshold voltage (an over-simplification) then will rapidly increase in brightness with an eventual slow tailoff to full brightness as set by the curent limiting resistor.    To do better you'd need a second OPAMP wired as a voltage controlled current source to drive the LED If in proportion to the ramp voltage, and should probably replace the RC ramp + buffer with a Miller integrator.

The following users thanked this post: Tim4444

#### pitagoras

• Regular Contributor
• Posts: 116
• Country:
##### Re: Voltage ramp using RC circuit and opamp
« Reply #3 on: December 28, 2016, 08:58:18 pm »
First things first.
LEDs are driven by a 15mA current, not by a voltage. You always need a resistor. In your case (3V-2V)/15mA = 68 ohm (aprox)
where 3V is the output voltage of the opamp, 2V is the voltage drop across the led diode.
Second, you want an integrator. See for example http://www.electronics-tutorials.ws/opamp/opamp_6.html

The following users thanked this post: Tim4444

#### Tim4444

• Contributor
• Posts: 13
##### Re: Voltage ramp using RC circuit and opamp
« Reply #4 on: December 28, 2016, 09:57:44 pm »

> I understand now that integrator opamps are a another good way to create a ramp voltage. Most things I see on-line though are integrators (link given by pitagoras) that produce a positive voltage ramp on the output in response to a negative step voltage applied to the inverting input, by adding a feedback capacitor from Vout to the inverting input (http://www.electronics-tutorials.ws/opamp/opamp_6.html). Can I use an integrator opamp to give me a positive voltage ramp in response to an positive input voltage? How could I do this?

> In my circuit that I posted before, the voltage at Vout constantly sat around 1.9 V, even when switch 1 was open (therefore no Vin, only V+). Do you know why this may be? The opamp is model LM741CN. Is it maybe something to do with a min Vout for this particular opamp?

> Third question regards currents and opamps? In general, I hear it is a bad idea to source current from the output from this kind of opamp. Why is this? I understand from your replies that i also should use a voltage-controlled current-source-opamp after my initial opamp to that controls Vout. Can you point me in the right direction of any particular good opamps for this?

Thanks again,

Tim

#### pitagoras

• Regular Contributor
• Posts: 116
• Country:
##### Re: Voltage ramp using RC circuit and opamp
« Reply #5 on: December 28, 2016, 10:13:24 pm »

you can use an inverter (google opamp inverter) or invert the diode.

S1 open means open input. YouÂ´re probably measuring noise.

The max current depends in the ratings of the amplifier. Get used to read datasheets.
Search how much current the opamp can drive, and how much power it can dissipate without burning.

#### bson

• Supporter
• Posts: 1740
• Country:
##### Re: Voltage ramp using RC circuit and opamp
« Reply #6 on: December 28, 2016, 10:30:22 pm »
The idea is to feed an input voltage (Vin 3 V) into an RC circuit (R1 and C1), and then take the voltage across the capacitor and feed it into then non-inverting input - this will create a slowly rising voltage on the non-inverting input with a slope determined by the RC time constant (R1 and C1 give a tau of 4.7 s).
The RC charge (cap voltage) as a function of time is:

$V(t) = V_0 \times e^{-\frac{t}{RC}}$

The RC discharge (cap voltage) as a function of time is:

$V(t) = V_0 ({1 - e^{-\frac{t}{RC}}})$

As you can see the "slope" isn't linear.
« Last Edit: December 28, 2016, 10:36:29 pm by bson »

#### Ian.M

• Super Contributor
• Posts: 9133
##### Re: Voltage ramp using RC circuit and opamp
« Reply #7 on: December 28, 2016, 10:36:06 pm »
A LM741CN is *NOT* a rail-to-rail OPAMP and is *NOT* suitable for low voltage single supply operation.

Here's a LTspice sim using their generic level 2 OPAMP model that ramps LED current very close to linearly from 0 to 12.5mA (set by R8 and U2's input divider).  Its using a 5V supply as I couldn't get it to run properly below 3.7V. To fix that it would need a better low-voltage rail-to-rail OPAMP model.

D2 provides a little voltage offset so the LED current starts from zero as a Miller ramp generator cant start from zero unless you have a negative bias supply.

The source vReset and the .model SW are highly LTSPICE specific, to provide timed control of SW1, the integrator reset switch.  If you are using a different simulator you'll have to find out how to do a timed switch for yourself.

#### Audioguru

• Super Contributor
• Posts: 1508
• Country:
##### Re: Voltage ramp using RC circuit and opamp
« Reply #8 on: December 28, 2016, 10:55:18 pm »
It seems that you did not look at the datasheet of the 741 opamp or its datasheet. Its design is 48 years old and its datasheet shows only a +15V and -15V (30V) supply.
Its output goes to 5V less than its power supply voltage when its output current is only 2.5mA and its inputs do not work if their voltage is within 3V from the positive or negative supply voltage.

#### Tim4444

• Contributor
• Posts: 13
##### Re: Voltage ramp using RC circuit and opamp
« Reply #9 on: December 28, 2016, 11:32:26 pm »
Hi everyone,

Thanks for the replies. I now understand that a lot of my problems are due to me choosing the wrong opamp.

Until now (i am new to opamps) I have not come across the term rail-to-rail. I now assume that my 2 V on the output with switch 1 open is likely due to the opamp output unable to reach V- (ground) because it is not designed to reach the bottom rail.

Thanks for all the other suggestions. And thanks for the circuit simulation Ian , I see there is a opamp integrator feeding into a opamp controlling a current source. It may take me a while longer to get my head around this though.

Finally, I realise that my increase in voltage will not be linear as the charging of c1 is not linear. Was just hoping for a ramp of some sought.

Thanks again

Tim

#### Ian.M

• Super Contributor
• Posts: 9133
##### Re: Voltage ramp using RC circuit and opamp
« Reply #10 on: December 29, 2016, 02:11:27 am »
I've figured out why the sim wont work down to 3V Vcc: The LED Vf is too high!

NSCW100 is a white LED with a Vf of typ. 3.6V @If=20mA
It works at Vcc=3V if you substitute NSSW008CT-P1 which is also a white LED but has Vf of typ. 3.2V @If=20mA but its running out of headroom for the transistor Vce drop, so you need to reduce R8, and increase R4 to decrease the burden voltage of the R8 current sense resistor.  22R and 150K work nicely.

Also I've found a real-world OPAMP that will work for this application in simulation @3V: LT1078A.  You wouldn't actually want to use it because of its boutique pricing, and I'd probably use a 'jellybean' dual CMOS OPAMP - anything rated for single supply operation down to 2.8V should work.
« Last Edit: December 29, 2016, 02:13:35 am by Ian.M »

#### nugglix

• Regular Contributor
• Posts: 208
• Country:
##### Re: Voltage ramp using RC circuit and opamp
« Reply #11 on: December 29, 2016, 07:24:41 am »
@OP

Some nice videos on generating sawtooth/triangle wave forms:

and

You should watch them for the basic principles explained there.

As usual: I strongly recommend Alans videos, they're priceless.

#### Ian.M

• Super Contributor
• Posts: 9133
##### Re: Voltage ramp using RC circuit and opamp
« Reply #12 on: December 29, 2016, 09:15:01 am »
Well I've redesigned the two OPAMP ramp circuit a bit.  I've eliminated the offset diode D2, and overridden the NSCW100 LED model parameter N to simulate a LED with Vf=2.4V @If=20mA, and made some other tweaks to get it to ramp up to 30mA @Vcc=3V.

R9 tweaks the hold-off to make sure the LED stays off when SW1 is closed.  You can trim the LED current by changing R8 without affecting the rest of the design.

N.B. the current is dependent on the OPAMP Vcc and its max output high voltage (see trace o1 (integrator output). An OPAMP with a true rail-to-rail output will probably need R4 tweaked a bit, or (assuming there's enough headroom for LED Vf), you'll get more current than you expect.

If your LED Vf is too high for the available headroom, you could feed just the LED from a higher voltage (limited by Q1 dissipation at max current).

However this circuit is of academic interest only.  An ATtiny programmed to PWM the LED would be the easiest option (supported by the Arduino IDE), which would vastly reduce the part count, cost, quiescent current consumption, and also allows you to linearise the perceptual brightness increase.  Alternatively a PIC12 with PWM would be a good choice if you already have a toolchain for 8 bit PICs
« Last Edit: December 29, 2016, 09:34:45 am by Ian.M »

#### Zero999

• Super Contributor
• Posts: 14576
• Country:
• 0999
##### Re: Voltage ramp using RC circuit and opamp
« Reply #13 on: December 29, 2016, 10:15:21 am »
Well I've redesigned the two OPAMP ramp circuit a bit.  I've eliminated the offset diode D2, and overridden the NSCW100 LED model parameter N to simulate a LED with Vf=2.4V @If=20mA, and made some other tweaks to get it to ramp up to 30mA @Vcc=3V.

R9 tweaks the hold-off to make sure the LED stays off when SW1 is closed.  You can trim the LED current by changing R8 without affecting the rest of the design.

N.B. the current is dependent on the OPAMP Vcc and its max output high voltage (see trace o1 (integrator output). An OPAMP with a true rail-to-rail output will probably need R4 tweaked a bit, or (assuming there's enough headroom for LED Vf), you'll get more current than you expect.

If your LED Vf is too high for the available headroom, you could feed just the LED from a higher voltage (limited by Q1 dissipation at max current).

However this circuit is of academic interest only.  An ATtiny programmed to PWM the LED would be the easiest option (supported by the Arduino IDE), which would vastly reduce the part count, cost, quiescent current consumption, and also allows you to linearise the perceptual brightness increase.  Alternatively a PIC12 with PWM would be a good choice if you already have a toolchain for 8 bit PICs
I couldn't get it to work. You used a symbol which isn't in my library so I replaced it with a voltage controlled switch but the results are still different to what you've shown.

#### Ian.M

• Super Contributor
• Posts: 9133
##### Re: Voltage ramp using RC circuit and opamp
« Reply #14 on: December 29, 2016, 10:56:57 am »
Your switch model is FUBARed - an off resistance of 1Meg is far too low for an integrator circuit using a 100K input resistor. My smulation had a near ideal switch - on resistance 1 milliOhm, off resistance 1 GigaOhm. Try increasing Roff to 20Meg, which is pretty much the minimum for acceptable linearity.

To use my simulation without the SPDT switch model, replace SW1 with a current controlled switch (csw) which is a standard part in lib\sym, and set its 'SpiceModel' line to vReset, and its  'Value' to SW.

N.B. the order of these two is non-intuitive as the W (csw) device takes its controlling voltage source parameter before its model parameter.

N.B.2. W (csw) is controlled by the current through a voltage source.  Shorting the source + setting its internal resistance to -1 will result in a positive current of 1A per Volt with no extra components.

N.B.3. The high impedance -in node of U1, which is significantly affected by 10Meg leakage resistance is an excellent reason *NOT* to build this circuit in real life.  Large capacitors with low enough leakage are $expensive$ and even if you reset it with a bare glass + solenoid reed relay and bend out the in- pin so the node and all components to it are in free air, it will be problematic.   You have been warned - use an 8 pin MCU!
« Last Edit: December 29, 2016, 12:12:26 pm by Ian.M »

#### Zero999

• Super Contributor
• Posts: 14576
• Country:
• 0999
##### Re: Voltage ramp using RC circuit and opamp
« Reply #15 on: December 29, 2016, 12:04:09 pm »
Yes, I messed up the switch model. Here's the corrected version.

#### Ian.M

• Super Contributor
• Posts: 9133
##### Re: Voltage ramp using RC circuit and opamp
« Reply #16 on: December 29, 2016, 12:14:47 pm »
Yes, that's got it.  However its worth learning how to use a csw switch as it results in a far less cluttered schematic.  You can also define the power supply and the switch control as SPICE netlist lines in a schematic . command text block if you really need to hide non-physical or off-board parts.  I've fixed it up to use the csw symbol and hidden the sources as described.
« Last Edit: December 29, 2016, 12:33:35 pm by Ian.M »

The following users thanked this post: Zero999

Smf