Pages

Friday, 15 March 2013

NgSpice, bridge rectifier with RC load

This is the second spice example, and now we are going to do a simulation of a bridge rectifier with a simple RC load. Let us assume that we want figure out the waveform of the input and output signal, and calculate the value of the first 10 harmonic of the output signal.



After have drawn a sketch of the circuit, (that is more important especially for complicated circuits), we are ready to write the spice file:


$ Bridge Rectifier - RC load

Vin n1 n2 SIN(0 220 50)

D13 n1 out diode
D23 n2 out diode
D41 0 n1 diode
D42 0 n2 diode

CL out 0 100u
RL out 0 1k

.MODEL diode d


.END

In this circuit we can find a typical non-linear element, the pn diode. In the spice file as all non linear element is described by a model, that is such example is the default model, but we can modified a lot of parameter as the internal capacitance, saturation current, breakdown voltage etc... just have a look to the manual!

To see the waveform of the signal we must do a transient analysis, then before the .END statement we should add the following line:

.TRAN 0.1m 60m
.SAVE tran v(out) in=par('v(n1)-v(n2)')


The first one, do the transient analysis and the second save "only" the vector that we need. Infact without this statement, Ngspice save all the vector of the simulation. Since The input generator is not referred to the ground, we need to define the voltage v(in). After that, we can do the simulation:

ngspice -b -o bridge_rectifier.txt -r bridge_rectifier.raw bridge_rectifier.sp
With the option "-r" or "--rawfile=" we are able to create a rawfile, where the vector of the waveform will be saved. We can see this file with "gwave":


Also, if we don't want use gwave, is of course possible see the waveform inside ngspice, doing an interactive simulation.

But we have not obtained the results about the THD and the value of Harmonics. Just add this line before the .END:

.FOUR 50 v(out)

and execute:
ngspice -b -o bridge_rectifier.txt bridge_rectifier.sp

Look that this time we the option for the raw file is missing. In fact if it was there, then in the output file ngspice tells: ".fourier line ignored since rawfile was produced.". I avoid to write even the fourier transform of the signal ;), but you can guess, just look the waveform, that there are too much harmonics with multiple frequency of 50 Hz! Try to change the value of the RC load to improve it, or more smartly add electronics!

You can download all the file from here:
Spice file
Output file with fourier transform
Raw file

No comments:

Post a Comment