Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A ngspice Circuit using LM358

114 views
Skip to first unread message

Anand P. Paralkar

unread,
May 2, 2011, 10:02:00 AM5/2/11
to
Hi,

I am trying to construct a simple current to voltage convertor using the
LM358 single-supply op-amp. As a basic starting point, I am using two
stages. The first stage below is a voltage buffer that will later be
converted to an I-to-V stage. (Voltage source will become a current
source and a resistor will be added.)

The second stage consists of a bias voltage applied on the first stage
output followed by a simple buffer.

I am unable to understand the voltage plot at node 6 (capacitor C1
output). This should show a an AC coupled (no dc offset) complete sine
wave, but ngspice shows kind of a rectified sine wave output!

Any idea?

Thanks for your help,
Anand

==========================================================================
.include /cygdrive/c/work/ngspice/library/LM358-NAT.lib

*First stage

* NI, INV, POS, NEG, OP
X1 1 2 3 4 5 LM358/NS
Vp1 3 0 5V
Vn1 4 0 0V
R1 5 2 0.1 *Short circuit from o/p to inv
Vsource 1 0 sin(0 1 625) *to be replaced with current source

*Second stage
C1 5 6 18pF
R2 6 7 0.1
*Rb1 9 7 100K *voltage divider
*Rb2 7 0 100K *voltage divider
X2 7 8 9 10 11 LM358/NS
Vp2 9 0 5V
Vn2 10 0 0V
R3 11 8 0.1 *short circuit from o/p to inv
=============================================================================

*//////////////////////////////////////////////////////////////////////
* (C) National Semiconductor, Inc.
* Models developed and under copyright by:
* National Semiconductor, Inc.

*/////////////////////////////////////////////////////////////////////
* Legal Notice: This material is intended for free software support.
* The file may be copied, and distributed; however, reselling the
* material is illegal

*////////////////////////////////////////////////////////////////////
* For ordering or technical information on these models, contact:
* National Semiconductor's Customer Response Center
* 7:00 A.M.--7:00 P.M. U.S. Central Time
* (800) 272-9959
* For Applications support, contact the Internet address:
* amps...@galaxy.nsc.com

*//////////////////////////////////////////////////////////
*LM358 DUAL OPERATIONAL AMPLIFIER MACRO-MODEL
*//////////////////////////////////////////////////////////
*
* connections: non-inverting input
* | inverting input
* | | positive power supply
* | | | negative power supply
* | | | | output
* | | | | |
* | | | | |
.SUBCKT LM358/NS 1 2 99 50 28
*
*Features:
*Eliminates need for dual supplies
*Large DC voltage gain = 100dB
*High bandwidth = 1MHz
*Low input offset voltage = 2mV
*Wide supply range = +-1.5V to +-16V
*
*NOTE: Model is for single device only and simulated
* supply current is 1/2 of total device current.
* Output crossover distortion with dual supplies
* is not modeled.
*
****************INPUT STAGE**************
*
IOS 2 1 5N
*^Input offset current
R1 1 3 500K
R2 3 2 500K
I1 99 4 100U
R3 5 50 517
R4 6 50 517
Q1 5 2 4 QX
Q2 6 7 4 QX
*Fp2=1.2 MHz
C4 5 6 128.27P
*
***********COMMON MODE EFFECT***********
*
I2 99 50 75U
*^Quiescent supply current
EOS 7 1 POLY(1) 16 49 2E-3 1
*Input offset voltage.^
R8 99 49 60K
R9 49 50 60K
*
*********OUTPUT VOLTAGE LIMITING********
V2 99 8 1.63
D1 9 8 DX
D2 10 9 DX
V3 10 50 .635
*
**************SECOND STAGE**************
*
EH 99 98 99 49 1
G1 98 9 POLY(1) 5 6 0 9.8772E-4 0 .3459
*Fp1=7.86 Hz
R5 98 9 101.2433MEG
C3 98 9 200P
*
***************POLE STAGE***************
*
*Fp=2 MHz
G3 98 15 9 49 1E-6
R12 98 15 1MEG
C5 98 15 7.9577E-14
*
*********COMMON-MODE ZERO STAGE*********
*
*Fpcm=10 KHz
G4 98 16 3 49 5.6234E-8
L2 98 17 15.9M
R13 17 16 1K
*
**************OUTPUT STAGE**************
*
F6 50 99 POLY(1) V6 300U 1
E1 99 23 99 15 1
R16 24 23 17.5
D5 26 24 DX
V6 26 22 .63V
R17 23 25 17.5
D6 25 27 DX
V7 22 27 .63V
V5 22 21 0.27V
D4 21 15 DX
V4 20 22 0.27V
D3 15 20 DX
L3 22 28 500P
RL3 22 28 100K
*
***************MODELS USED**************
*
.MODEL DX D(IS=1E-15)
.MODEL QX PNP(BF=1.111E3)
*
.ENDS
*$

dagmarg...@yahoo.com

unread,
May 2, 2011, 1:35:25 PM5/2/11
to
On May 2, 9:02 am, "Anand P. Paralkar"

<anand.paral...@gnospammale.com> wrote:
> Hi,
>
> I am trying to construct a simple current to voltage convertor using the
> LM358 single-supply op-amp.  As a basic starting point, I am using two
> stages.  The first stage below is a voltage buffer that will later be
> converted to an I-to-V stage.  (Voltage source will become a current
> source and a resistor will be added.)
>
> The second stage consists of a bias voltage applied on the first stage
> output followed by a simple buffer.
>
> I am unable to understand the voltage plot at node 6 (capacitor C1
> output).  This should show a an AC coupled (no dc offset) complete sine
> wave, but ngspice shows kind of a rectified sine wave output!
>
> Any idea?
>
> Thanks for your help,
> Anand
*First stage

* NI, INV, POS, NEG, OP
X1 1 2 3 4 5 LM358/NS
Vp1 3 0 5V
Vn1 4 0 0V
R1 5 2 0.1 *Short circuit from o/p to inv
Vsource 1 0 sin(0 1 625) *to be replaced with current source

*Second stage
C1 5 6 18pF
R2 6 7 0.1
*Rb1 9 7 100K *voltage divider
*Rb2 7 0 100K *voltage divider
X2 7 8 9 10 11 LM358/NS
Vp2 9 0 5V
Vn2 10 0 0V
R3 11 8 0.1 *short circuit from o/p to inv

<snip>

The LM358 can't swing below ground on single supplies -- feed it -5v
for Vn1.

--
Cheers,
James Arthur

Anand P. Paralkar

unread,
May 3, 2011, 12:43:33 AM5/3/11
to
I tried that. Doesn't help. One can also try with a DC bias to the
first stage input. Say a 2.5V DC bias "Vsource 1 0 sin(2.5 1 625)".
This doesn't help too.

Infact, its not the first stage LM358 output (this is simulated
correctly). Its the node after the LM358 output, the one at the
capacitor "output" (node 6) which I find erroneous.

I was hoping that someone simulates this circuit with another Spice
software and cross-verifies the behaviour.

Thanks for looking into it,
Anand

John Fields

unread,
May 3, 2011, 9:00:17 AM5/3/11
to
On Tue, 03 May 2011 10:13:33 +0530, "Anand P. Paralkar"
<anand.p...@gnospammale.com> wrote:

>I tried that. Doesn't help. One can also try with a DC bias to the
>first stage input. Say a 2.5V DC bias "Vsource 1 0 sin(2.5 1 625)".
>This doesn't help too.
>
>Infact, its not the first stage LM358 output (this is simulated
>correctly). Its the node after the LM358 output, the one at the
>capacitor "output" (node 6) which I find erroneous.
>
>I was hoping that someone simulates this circuit with another Spice
>software and cross-verifies the behaviour.

---
I'll do it if you post or email me a schematic.

Or you can do it yourself, if you like, using LTspice.

It's excellent, free, and you can get it at:

http://www.linear.com/designtools/software/

--
JF

dagmarg...@yahoo.com

unread,
May 3, 2011, 12:25:10 PM5/3/11
to
On May 2, 11:43 pm, "Anand P. Paralkar"
<anand.paral...@gnospammale.com> wrote:

> On 02-05-2011 23:05, dagmargoodb...@yahoo.com wrote:
>
> > The LM358 can't swing below ground on single supplies -- feed it -5v
> > for Vn1.

> I tried that.  Doesn't help.  One can also try with a DC bias to the


> first stage input.  Say a 2.5V DC bias "Vsource 1 0 sin(2.5 1 625)".
> This doesn't help too.
>
> Infact, its not the first stage LM358 output (this is simulated
> correctly).  Its the node after the LM358 output, the one at the
> capacitor "output" (node 6) which I find erroneous.
>
> I was hoping that someone simulates this circuit with another Spice
> software and cross-verifies the behaviour.
>
> Thanks for looking into it,
> Anand


Here's an ACSII version of what I understand your circuit to be: (view
in a fixed font, such as Courier)

Vp1 = 5v
-+-
|\ | Vp2 = 5v
| \3 -+-
Vin>---1-|+ \ C1 |\ |
1v a.c. | \ 18pF | \9
| >-5-+---||--6--R2---7-|+ \
| / | 0.1r | \
.--2-|- / | | >-11---
| | /4 | | /
| |/ | | --8-|- /
| Vn1=0v | | /10
| | |/ |
'------R1-----' Vn2=0v
0.1r

This circuit has several problems--I already pointed out one. If
you're going to feed it a.c. you need dual supplies or the 1st stage
will clip.

The input to the 2nd stage outputs a bias current. You need to
dispose of that current, such as with a feedback resistor or a
resistor to some d.c. voltage.

Last, the coupling capacitor is absurdly low--you might want to
consider what you really want it to do.

--
Cheers,
James Arthur

Jim Thompson

unread,
May 3, 2011, 12:54:51 PM5/3/11
to
On Tue, 3 May 2011 09:25:10 -0700 (PDT), dagmarg...@yahoo.com
wrote:

A simulator in the hands of someone with no basic electronic skills
?:-)

...Jim Thompson
--
| James E.Thompson, CTO | mens |
| Analog Innovations, Inc. | et |
| Analog/Mixed-Signal ASIC's and Discrete Systems | manus |
| Phoenix, Arizona 85048 Skype: Contacts Only | |
| Voice:(480)460-2350 Fax: Available upon request | Brass Rat |
| E-mail Icon at http://www.analog-innovations.com | 1962 |

Remember: Once you go over the hill, you pick up speed

Michael A. Terrell

unread,
May 3, 2011, 2:05:20 PM5/3/11
to


That covers way too many people on the sci.electronics.* newsgroups,
Jim. :(


--
You can't fix stupid. You can't even put a Band-Aid™ on it, because it's
Teflon coated.

dagmarg...@yahoo.com

unread,
May 3, 2011, 3:16:45 PM5/3/11
to
On May 3, 11:54 am, Jim Thompson <To-Email-Use-The-Envelope-I...@On-My-
Web-Site.com> wrote:
> On Tue, 3 May 2011 09:25:10 -0700 (PDT), dagmargoodb...@yahoo.com

Hey, we all gotta start somewhere.... :-)

--
Cheers,
James Arthur

Jim Thompson

unread,
May 3, 2011, 3:21:13 PM5/3/11
to
On Tue, 3 May 2011 12:16:45 -0700 (PDT), dagmarg...@yahoo.com
wrote:

As much as I now use simulators, I would still argue that you should
learn how to do everything by hand/pencil/paper before going on to
using simulators.

John Fields

unread,
May 3, 2011, 3:30:12 PM5/3/11
to
On Tue, 03 May 2011 10:13:33 +0530, "Anand P. Paralkar"
<anand.p...@gnospammale.com> wrote:
>
>On 02-05-2011 23:05, dagmarg...@yahoo.com wrote:
>>
>> The LM358 can't swing below ground on single supplies -- feed it -5v
>> for Vn1.
>>
>> --
>> Cheers,
>> James Arthur


>I tried that. Doesn't help. One can also try with a DC bias to the
>first stage input. Say a 2.5V DC bias "Vsource 1 0 sin(2.5 1 625)".
>This doesn't help too.
>
>Infact, its not the first stage LM358 output (this is simulated
>correctly). Its the node after the LM358 output, the one at the
>capacitor "output" (node 6) which I find erroneous.
>
>I was hoping that someone simulates this circuit with another Spice
>software and cross-verifies the behaviour.
>
>Thanks for looking into it,
>Anand

---
Please don't top post.

Offset the buffer's + input to 2.5V with a fairly high resistance
voltage divider and cap-couple the + input to the source.

On the E-to-I converter, use another divider on the + input to get the
offset, and DC couple the - input to the buffer output and to its own
output through equal value resistors.

Like this, using LTspice:

Version 4
SHEET 1 880 680
WIRE 64 32 -112 32
WIRE 208 32 64 32
WIRE 336 32 208 32
WIRE 528 32 336 32
WIRE 64 48 64 32
WIRE 336 48 336 32
WIRE 256 80 160 80
WIRE 544 80 464 80
WIRE 640 80 624 80
WIRE 208 112 208 32
WIRE 160 128 160 80
WIRE 176 128 160 128
WIRE 528 128 528 32
WIRE 256 144 256 80
WIRE 256 144 240 144
WIRE 368 144 256 144
WIRE 464 144 464 80
WIRE 464 144 448 144
WIRE 496 144 464 144
WIRE 64 160 64 128
WIRE 64 160 48 160
WIRE 80 160 64 160
WIRE 176 160 80 160
WIRE 640 160 640 80
WIRE 640 160 560 160
WIRE 672 160 640 160
WIRE 336 176 336 128
WIRE 496 176 336 176
WIRE 80 208 80 160
WIRE 336 208 336 176
WIRE -112 224 -112 32
WIRE -16 224 -16 160
WIRE -112 336 -112 304
WIRE -16 336 -16 304
WIRE -16 336 -112 336
WIRE 80 336 80 288
WIRE 80 336 -16 336
WIRE 208 336 208 176
WIRE 208 336 80 336
WIRE 336 336 336 288
WIRE 336 336 208 336
WIRE 528 336 528 192
WIRE 528 336 336 336
WIRE -112 400 -112 336
FLAG -112 400 0
FLAG 672 160 OUT
SYMBOL Opamps\\LT1001 208 80 R0
SYMATTR InstName U1
SYMBOL voltage -16 208 R0
WINDOW 3 24 104 Invisible 0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V2
SYMATTR Value SINE(0 1 1000)
SYMBOL voltage -112 208 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V3
SYMATTR Value 5
SYMBOL cap 48 144 R90
WINDOW 0 0 32 VBottom 0
WINDOW 3 32 32 VTop 0
SYMATTR InstName C1
SYMATTR Value 1E-6
SYMBOL res 48 32 R0
SYMATTR InstName R1
SYMATTR Value 100K
SYMBOL res 64 192 R0
SYMATTR InstName R2
SYMATTR Value 100K
SYMBOL Opamps\\LT1001 528 96 R0
SYMATTR InstName U2
SYMBOL res 320 32 R0
WINDOW 0 -42 55 Left 0
WINDOW 3 -57 24 Left 0
SYMATTR InstName R3
SYMATTR Value 100K
SYMBOL res 320 192 R0
SYMATTR InstName R4
SYMATTR Value 100K
SYMBOL res 464 128 R90
WINDOW 0 -31 58 VBottom 0
WINDOW 3 -31 60 VTop 0
SYMATTR InstName R5
SYMATTR Value 10K
SYMBOL res 640 64 R90
WINDOW 0 -28 55 VBottom 0
WINDOW 3 -31 54 VTop 0
SYMATTR InstName R6
SYMATTR Value 10K
TEXT -106 368 Left 0 !.tran 10E-3

--
JF

John Fields

unread,
May 3, 2011, 4:15:59 PM5/3/11
to

---
Delete the second divider and connect the buffer + input to the I-to-E
+ input if you want a DC output in phase with the AC input, and if you
want an ac output in phase with the AC input:

Version 4
SHEET 1 880 680
WIRE 64 32 -112 32
WIRE 208 32 64 32

WIRE 448 32 208 32


WIRE 64 48 64 32

WIRE 256 80 160 80

WIRE 464 80 400 80
WIRE 560 80 544 80


WIRE 208 112 208 32
WIRE 160 128 160 80
WIRE 176 128 160 128

WIRE 448 128 448 32


WIRE 256 144 256 80
WIRE 256 144 240 144

WIRE 288 144 256 144
WIRE 400 144 400 80
WIRE 400 144 368 144
WIRE 416 144 400 144


WIRE 64 160 64 128
WIRE 64 160 48 160
WIRE 80 160 64 160

WIRE 160 160 80 160
WIRE 176 160 160 160
WIRE 560 160 560 80
WIRE 560 160 480 160
WIRE 416 176 400 176


WIRE 80 208 80 160

WIRE 160 208 160 160
WIRE 400 208 400 176
WIRE 400 208 160 208


WIRE -112 224 -112 32
WIRE -16 224 -16 160
WIRE -112 336 -112 304
WIRE -16 336 -16 304
WIRE -16 336 -112 336
WIRE 80 336 80 288
WIRE 80 336 -16 336
WIRE 208 336 208 176
WIRE 208 336 80 336

WIRE 448 336 448 192
WIRE 448 336 208 336


WIRE -112 400 -112 336
FLAG -112 400 0

FLAG 624 160 OUT


SYMBOL Opamps\\LT1001 208 80 R0
SYMATTR InstName U1
SYMBOL voltage -16 208 R0
WINDOW 3 24 104 Invisible 0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V2
SYMATTR Value SINE(0 1 1000)
SYMBOL voltage -112 208 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V3
SYMATTR Value 5
SYMBOL cap 48 144 R90
WINDOW 0 0 32 VBottom 0
WINDOW 3 32 32 VTop 0
SYMATTR InstName C1

SYMATTR Value 1e-6


SYMBOL res 48 32 R0
SYMATTR InstName R1
SYMATTR Value 100K
SYMBOL res 64 192 R0
SYMATTR InstName R2
SYMATTR Value 100K

SYMBOL Opamps\\LT1001 448 96 R0
SYMATTR InstName U2
SYMBOL res 384 128 R90


WINDOW 0 -31 58 VBottom 0
WINDOW 3 -31 60 VTop 0
SYMATTR InstName R5
SYMATTR Value 10K

SYMBOL res 560 64 R90


WINDOW 0 -28 55 VBottom 0
WINDOW 3 -31 54 VTop 0
SYMATTR InstName R6
SYMATTR Value 10K

SYMBOL cap 624 144 R90


WINDOW 0 0 32 VBottom 0
WINDOW 3 32 32 VTop 0

SYMATTR InstName C2
SYMATTR Value 1e-6

dagmarg...@yahoo.com

unread,
May 4, 2011, 12:06:44 AM5/4/11
to
On May 3, 2:21 pm, Jim Thompson <To-Email-Use-The-Envelope-I...@On-My-
Web-Site.com> wrote:
> On Tue, 3 May 2011 12:16:45 -0700 (PDT), dagmargoodb...@yahoo.com
> wrote:

> >On May 3, 11:54 am, Jim Thompson wrote:

> >> A simulator in the hands of someone with no basic electronic skills
> >> ?:-)
>
> >Hey, we all gotta start somewhere.... :-)
>
> As much as I now use simulators, I would still argue that you should
> learn how to do everything by hand/pencil/paper before going on to
> using simulators.

I meant most of us weren't born knowing electronics, not that
simulators were the best teachers.

Pffft....BANG! is one of the best teachers.

--
Cheers,
James Arthur

Jim Thompson

unread,
May 4, 2011, 10:44:51 AM5/4/11
to
On Tue, 3 May 2011 21:06:44 -0700 (PDT), dagmarg...@yahoo.com
wrote:

Certainly! But I learned on tubes (valves for those on the other side
of the pond), so I had no destruction episodes, other than an
occasional resistor that emitted smoke :-)

Jamie

unread,
May 4, 2011, 6:09:57 PM5/4/11
to
dagmarg...@yahoo.com wrote:

Kind of reminds me of when RAD, Java /JavaScript, PHP and related things
came along. Young people called themselves computer programmers! WOW

I think many of those have really forgotten or never knew what real
programming is all about..

Jamie

RST Engineering

unread,
May 8, 2011, 2:47:11 PM5/8/11
to
On Wed, 04 May 2011 07:44:51 -0700, Jim Thompson
<To-Email-Use-Th...@On-My-Web-Site.com> wrote:


>
>Certainly! But I learned on tubes (valves for those on the other side
>of the pond), so I had no destruction episodes, other than an
>occasional resistor that emitted smoke :-)
>
> ...Jim Thompson

You mean you never got a horizontal sweep tube pressed into 40 meter
service so hot the glass got sucked onto the plate before it went
whizz-bang?

Jim

Jamie

unread,
May 8, 2011, 4:26:14 PM5/8/11
to
RST Engineering wrote:

Sure

Made a CB amp years ago for the car using a pair of 6jS6 es....

some Radio shaft power transformers turned around backwards for
an inverter with a multiplier rectifier for the B+///it got warm
in the car after a while..

Jamie

Michael A. Terrell

unread,
May 8, 2011, 7:03:29 PM5/8/11
to


No. Most of us know how to use a tube without melting the glass.

Jim Thompson

unread,
May 8, 2011, 7:43:33 PM5/8/11
to
On Sun, 08 May 2011 19:03:29 -0400, "Michael A. Terrell"
<mike.t...@earthlink.net> wrote:

>
>RST Engineering wrote:
>>
>> On Wed, 04 May 2011 07:44:51 -0700, Jim Thompson
>> <To-Email-Use-Th...@On-My-Web-Site.com> wrote:
>>
>> >
>> >Certainly! But I learned on tubes (valves for those on the other side
>> >of the pond), so I had no destruction episodes, other than an
>> >occasional resistor that emitted smoke :-)
>> >
>> > ...Jim Thompson
>>
>> You mean you never got a horizontal sweep tube pressed into 40 meter
>> service so hot the glass got sucked onto the plate before it went
>> whizz-bang?
>
>
> No. Most of us know how to use a tube without melting the glass.

I used to tune up the bias on my KT88's by watching for plate glow :-)

Michael A. Terrell

unread,
May 8, 2011, 9:50:08 PM5/8/11
to

Jim Thompson wrote:
>
> On Sun, 08 May 2011 19:03:29 -0400, "Michael A. Terrell"
> <mike.t...@earthlink.net> wrote:
>
> >
> >RST Engineering wrote:
> >>
> >> On Wed, 04 May 2011 07:44:51 -0700, Jim Thompson
> >> <To-Email-Use-Th...@On-My-Web-Site.com> wrote:
> >>
> >> >
> >> >Certainly! But I learned on tubes (valves for those on the other side
> >> >of the pond), so I had no destruction episodes, other than an
> >> >occasional resistor that emitted smoke :-)
> >> >
> >> > ...Jim Thompson
> >>
> >> You mean you never got a horizontal sweep tube pressed into 40 meter
> >> service so hot the glass got sucked onto the plate before it went
> >> whizz-bang?
> >
> >
> > No. Most of us know how to use a tube without melting the glass.
>
> I used to tune up the bias on my KT88's by watching for plate glow :-)


I used more ceramic or metal jacketed tubes for high power
applications. The only melted glss tubes I've seen were in color TVs.
If a 4CX250 is glowing, it's already bad. The same goes for 65 KW
Klystrons.

0 new messages