LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
Search this Thread
Old 06-01-2013, 09:46 PM   #1
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Squeeze
Posts: 585

Rep: Reputation: 118Reputation: 118
NGSpice: GNUCap: A simple halfwave rectifier fails.


While I'm not new to electronic circuits, I'm fairly new to EDA.

I have played around with Spice a very long time ago but really had no need for it. Now I do.

I've been trying to simulate a simple half wave rectifier for the last week or so and keep getting wrong results. Let me explain.

The first screenshot shows the circuit, a very very basic 1/2 wave rectifier, but as you can see from the second screenshot, while the voltage from the net labelled op is correct, the voltage across the resistor is inverted. Basic electronic theory tells you that this can never happen. Notice the pin labels on the resistor.

Now after trying and searching for almost two days, I inadvertently reversed the connections on the resistor and the output is now correct as shown in the third screenshot.

I thought it was the version of GNUCap I installed from the Debian repos. I built the lastest tarball but still the same result.

The circuit does not even simulate with NGSpice. The simulation runs forever while using 100% CPU. Again, I build the lastest NGSpice (25), but still the same result.

After trying searching for how a resistor is modeled in SPICE, and not getting anywhere, I'm at my wit's end.

Any help is greatly appreciated.
Attached Images
File Type: png diode.png (8.6 KB, 12 views)
File Type: png half-wrong.png (15.4 KB, 10 views)
File Type: png half-right.png (11.9 KB, 8 views)
 
Old 06-02-2013, 11:55 AM   #2
archShade
Member
 
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
I don't see anything wrong here. Remeber voltages are reletive. Absolute voltages in spice simulations are relevent to the ground point.

So V_op = V_op - V_gnd

But the voltage across the resitor is not relative to gnd so it can be negative. So it all depends on how V_R1 is defined. Looking at your circuit if V_R1 is defined as:
V_R1 = V_R1p1 - V_R1p2
Then you will will get V_R1 = -V_op.

If V_R1 is defined as:
V_R1 = V_R1p2 - V_R1p1
Then you will get V_R1 = V_op.

I did try to recreate the problem in gSchem/GNUCap but could not (this is more due to not being used to these tools as much as anything else).
 
Old 06-02-2013, 08:23 PM   #3
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Squeeze
Posts: 585

Original Poster
Rep: Reputation: 118Reputation: 118
All that you said is true, but it still soes not explain why reversing the resistor gives a different result. Also, what version of gschem are you using and which resistor symbol did you use? I've noticed that resistor-2.sym from the Basic library does not simulate. I'm using 1.6.1.20100214 from the Debian repos. I think I'll build the latest and give that a try.

Also, consider this: Why doesn't the simulation run with NGSpice?

Another point: Consider the circuit shown in this screenshot. It's your basic precision half wave rectifier. With the given configuration of the diodes, the circuit should give a positive half-wave rectified signal at the net labeled Half. Instead, it gives a negative half-wave rectified signal. I've also tried this with KTechLab and the circuit simulates as expected. What gives?

Thanks for the response.
Attached Images
File Type: png halfwave-rect.png (41.5 KB, 7 views)
 
Old 06-03-2013, 02:51 AM   #4
archShade
Member
 
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
Quote:
Originally Posted by towheedm View Post
All that you said is true, but it still soes not explain why reversing the resistor gives a different result. Also, what version of gschem are you using and which resistor symbol did you use? I've noticed that resistor-2.sym from the Basic library does not simulate. I'm using 1.6.1.20100214 from the Debian repos. I think I'll build the latest and give that a try.
I am also using 1.6.1.20100214 from the Debian repos. Although I am having no trouble with either resistor-1.sym or resistor-2.sym, both simulate fine. I think my previous point does explain whats going on. GNUCap define V(R) as:
V(R) = V_Rp1 - VRp2
which in your case gives
V(R1) = V(GND) - V(op) or V(R1) = - V(op).
which is both what you expected and what you got, when you rotated the the resistor 180' you reversed the pins so you had:
V(R1) = V(op) - V(GND) or V(R1) = V(op).
To me this behaviour seems exactley as expected.

Quote:
Also, consider this: Why doesn't the simulation run with NGSpice?
Sorry I cannot help here I do not have NGSPICE installed and it's not in my repos, I will try to install it later to see if I can track down the problem. Although maybe the answer lies in the simulation file.

Quote:
Another point: Consider the circuit shown in this screenshot. It's your basic precision half wave rectifier. With the given configuration of the diodes, the circuit should give a positive half-wave rectified signal at the net labeled Half. Instead, it gives a negative half-wave rectified signal. I've also tried this with KTechLab and the circuit simulates as expected. What gives?
This I do not know, the screen shot is not great and there seems to be more of it than pictured. The OP-AMP does seem to be in inverting configuration though. It's been a while since I have worked with rectifier circuits. Key question does the rectified wave line up with the positive or the negative part of the input? i.e. is V(Half) = rect(V(in) * -1, or is it V(Half) = n_rect(V(in)).

where rect() passes all positive value and filters all negative; and n_rect() passes all negative values and filters all positive values.

Would it be possible for you to upload the *.sch file for the half wave rectifier only. and the diode and op-amp models (I have been using the 1N4007 diode so far as thats what I had on my sysytem).

I'm afraid my experiance with gEDA is limited, I am more used to PSICE/LTSPICE/cadence (in order I started using them). I have only really used the gEDA suite quickley to see how it works.
 
Old 06-03-2013, 08:06 PM   #5
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Squeeze
Posts: 585

Original Poster
Rep: Reputation: 118Reputation: 118
Thank you so much for taking the time to help me with this. It's been quite a while since I've done any sort of circuit design, so this has taken me back to class. Back in my days there was no such thing as Spice etc. It was all breadboard and components, together with your slew of testing and measuring equipment. Again, I am sincerely grateful for all the help.

I've included the stuff in the attached archive. I've added the .txt extension to upload as a text file. I'm sure you know, but for anyone else coming across this thread, to untar:
Code:
mv acdc.tar.gz.txt acdc.tar.gz
tar zxvf acdc.tar.gz
First, the schematic. It's your basic Opamp full wave precision rectifier followed by a simple comparator that should switch low whenever the output of the full wave rectifier stage goes above 1.5V.

Here's a link:
http://sound.westhost.com/appnotes/an001.htm

The comparator is not simulating in the circuit, although, it does on it's own, ie: if I disconnect Pin 4 from the output of the second opamp and put in a Sin 0 2 1 Spice source, it switches as expected.

BTW: I'm using gSpiceUI as a front-end to GNUCap. Thr archive includes the gnetlist output together with the simulation output as acdc.gnucap.tr.

Thanks a whole lot again.
Attached Files
File Type: txt acdc.tar.gz.txt (8.0 KB, 1 views)
 
  


Reply

Tags
eda, gnucap, ngspice, simulation


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] the question of ngspice.I confused! genime Debian 7 03-16-2011 06:39 AM
Wanted help in installing ngspice on Ubuntu 9.04 RockerAsh Linux - Software 1 09-01-2010 02:51 AM
Trying to install ngSPICE, please help John-Z Linux - Software 3 08-18-2008 03:02 PM
where is ngspice abd_bela Debian 3 08-18-2008 02:43 PM
replacing spice and nutmeg with ngspice Berticus Linux - Software 1 08-18-2008 02:26 PM


All times are GMT -5. The time now is 11:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration