LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (http://www.linuxquestions.org/questions/general-10/)
-   -   NGSpice: GNUCap: A simple halfwave rectifier fails. (http://www.linuxquestions.org/questions/general-10/ngspice-gnucap-a-simple-halfwave-rectifier-fails-4175464415/)

towheedm 06-01-2013 09:46 PM

NGSpice: GNUCap: A simple halfwave rectifier fails.
 
3 Attachment(s)
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.

archShade 06-02-2013 11:55 AM

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).

towheedm 06-02-2013 08:23 PM

1 Attachment(s)
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.

archShade 06-03-2013 02:51 AM

Quote:

Originally Posted by towheedm (Post 4964306)
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.

towheedm 06-03-2013 08:06 PM

1 Attachment(s)
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.


All times are GMT -5. The time now is 02:24 AM.