Several problems with simulating bridge rectifier

I’m trying to get a simulation for a bridge rectifier circuit going, and I can’t figure it out. I have not looked thoroughly through the forums so my apologies if this has already been answered, but here are the details:

  • I’m trying to simulate a circuit that can take in 120 Vrms AC (170V peak), 60 Hz (basically US wall outlet) and spit out a low DC voltage, say between 5V and 16V (voltage across RL). The output doesn’t matter that much, as long as it’s in that range.
  • I’m using spice models I found and modified a bit for the transformer and the diodes in the diode bridge. I need the diodes to be modeled after 1N34A Germanium diodes, and the transformer is a 120VAC to 24VAC 5:1 step down transformer. The other components I used were ones built in to KiCAD, meant for simulation. I’ve attached pictures of the schematic and simulation errors I’m looking at, as well as the spice models I’m using. I tried playing around with the timestep in the simulator settings, but nothing seems to be working.

I’m fairly inexperienced with all this, so I really appreciate any and all help!

Those are signal diodes. In real life the first thing that will happen is they will become “one-shots” :wink:. Why not real rectifier diodes like 1N4001 series?

Do your diodes require an Alternate Node Sequence to specify the correct polarity of the diode pins? SPICE convention is pin 1 is anode and pin 2 is cathode, but most Kicad Symbols have it reversed.

Please add series resistance to the primary side of the transformer. If you don’t know the winding resistance of the coil, then use something like 100m just to get the simulation going. Can either add an explicit resistor component or use the “.options rseries=100m” command found in Section 15.1.2.1 of the ngspice manual.

Here’s another thread which explains one option for implementing the diode bridge. At least switch the signal diode model to the rectifier one found there.

If you still have trouble, please copy/paste here the netlist of the circuit (in the Simulator: Simulation → Show SPICE Netlist…)

The input side may need a ground connection. Even is this is something you will not do in reality (your mains installation provides some ground connection anyway), the simulator needs to get some info where to put the otherwise floating potential of the input. Maybe it is o.k. to use a 1G resistor.

1 Like

Hi Holger, thanks for the reply! This is so cool to have one of the ngspice contributors answering my questions, thank you so much for your time! I’m a bit confused on your message – do you mean that a second ground connection should be added between the voltage source and the transformer?

Also, where are you saying I should add in a 1G resistor? Are you suggesting that should be the .options rseries= value?

Hi Ste, thank you so much for the reply! I watched your KiCon presentation on spice simulation in KiCAD, which was very helpful (I did alternate the pin sequence on the diodes in the original like your presentation talked about)! So cool to have a professional from the KiCAD/spice community answering my questions!!

I swapped out the individual diodes for a diode bridge, following your instructions in the forum thread you linked (but modifying the values to match a spice model I found for a 1N4001 diode, that’s the one I’m working with). I added the .options command to the transformer model as well – the simulation works now!

I do have one more question though, might just be due to my inexperience w/ electrical eng in general:

  • I want the input voltage to be 120rms (170 peak right?), but it looks like the simulator is showing the peak voltage to be a bit less than 640-- what’s the problem there?

Netlist:
.title KiCad schematic .include "C:\Users\Jonathan\Desktop\KiCad Projects\AC to DC Full Wave Rectifier\1N4001 Diode Bridge.txt" .include "C:\Users\Jonathan\Desktop\KiCad Projects\AC to DC Full Wave Rectifier\xformer.lib.txt" V1 Net-_T1-Pad1_ Net-_T1-Pad2_ sin(0 170 60) XT1 Net-_T1-Pad1_ Net-_T1-Pad2_ Net-_T1-Pad3_ Net-_T1-Pad4_ XFORMER C1 Net-_C1-Pad1_ 0 100u RL 0 Net-_C1-Pad1_ 1k R1 Net-_C1-Pad1_ Net-_R1-Pad2_ 330 XD1 Net-_R1-Pad2_ 0 Net-_T1-Pad4_ Net-_T1-Pad3_ D_Bridge_+-AA .save @v1[i] .save @c1[i] .save @rl[i] .save @r1[i] .save V(Net-_C1-Pad1_) .save V(Net-_R1-Pad2_) .save V(Net-_T1-Pad1_) .save V(Net-_T1-Pad2_) .save V(Net-_T1-Pad3_) .save V(Net-_T1-Pad4_) .tran 500m 3 .end

Thank you so much!

Place a resistor 1G from node 2 of your transformer to ground and and another resistor 1G from node 3 to ground. They will not interfere with the electrical circuit, because they are large, but they care for the necessary ground connections, especially of the primary side.

2 Likes

Yes I think when no diodes are conducting, the simulator does not know what is the common mode voltage of the AC input side of the bridge relative to the DC output side. So some sort of resistor between input and output can resolve that. I would be more inclined to try 1 Meg ohms, unless the models have virtually no capacitance etc. across the diodes.

BTW I remember simulating a bridge rectifier power supply with a programmable calculator (HP55?) about 50 years ago.

1 Like

No problem. Glad it was helpful.


The issue here is related to what @holger said:

If you look at your schematic you have two independent loops of circuit, one on each side of the transformer. SPICE requires some electrical path (the magnetic field doesn’t count) to the “zero node” (i.e. GND) for each loop. The left side of your transformer has no such path, what they call “floating”. The easiest way to resolve this is to add a 1G resistor to GND on the left side of the transformer. The 1G value is big enough to not interfere with your circuit operation (practically invisible), but it satisfies the condition for the SPICE engine to operate.


A couple more extra points and tips:

  • Although it works, it’s somewhat bad practice to add a .options statement in a .subckt. It’s better to do it globally so it’s not hidden from the user because it affects all inductors outside the subcircuit too. Just make a text box (shortcut key ‘T’) with the statement and put it somewhere on the schematic.
  • If you are in possession of the actual transformer you intend to use, you can make a better model by using an ohmmeter to measure each sides’ winding resistance and then include actual resistors in your subcircuit definition. The rseries option, although handy, is clunky way to solve the simple problem of having a resistor-less version model of your transformer.
  • Your .tran statement should use a finer timestep (1st value) for this circuit. I suggest something like .tran 1m 500m. You can also put this on the schematic as a text box.
  • Throw some global labels onto your input and output nodes so it’s easier to read the plots.

Here is my recreation of your circuit schematic, with most of the above modifications, along with the zipped project folder.


xformertest.zip (4.9 KB)

3 Likes

What makes you inclined to use 1M vs 1G?

Also, just out of curiosity, would you be able to simulate it on a TI-84?

Well after some thought, I am not certain that there would be a significant difference. I am not a computer scientist; with 1M you would be introducing microamps and with 1G you would be introducing nanoamps. I do not know whether that makes a difference in the amount of calculating (precision) needed. I guess that if the simulator really needs the resistor to be there, that means that it is assuming absolutely no coupling between AC and DC when the diodes are not forward conducting. So if that is the case, then 1 G ohm should probably work.

My experience with programmable calculators is limited to a few HP models using “Reverse Polish Notation”. I think that I got to use first an HP35 (not programmable) and then I think an HP55 which was programmable. Eventually I bought an HP21 (if I remember correctly)…that was programmable and during the 1980s an HP11C which I still have and use today. But with circuit simulators and Spreadsheet calculation, it has been decades since I last programmed a calculator… So I have not ever used a TI-84. I would not want to have to program my HP11C but I guess I could dig up the manual and struggle through it if I needed to do so.

If I remember correctly:

  1. I probably used a fixed Vf (such as 0.7 V) for the diodes. The error from this would not be significant unless the voltages involved are very low.
  2. With limited memory and program steps, I could calculate (something like) ripple valley voltage or RMS ripple current but not both in one “run”.
  3. The results agreed quite well with hardware tests.

BTW the other thing that I have done (alluded to above) in more recent years is spreadsheet simulations. During the 1990s my employer bought (I think it was HSpice?). For the life of me I could not get reasonable results with that. Whatever version of Spice that was, I think it was particularly user “unfriendly.”. But I could simulate a comparator oscillator using an Excel spreadsheet, and my results came out within 1% of the bench test results.

2 Likes

I am inclined to repeat a little what Ste has already said, because it is important for using a Spice simulator:

Each net needs a DC path to ground, to enable the simulator to determine the electrical potential of each node. If this connection is missing, the simulator may deliver a wrong result or no result at all.

If you look at Ste’s circuit schematic, you see the right hand side having some connection to GND. On the left hand side, the mains side, there originally has not been any ground connection, now you have this 1G resistor. However, there is no loop for current flow, so there will not be any current flowing through the resistor. Therefore indeed it does not matter if you put a 1G, or 1Meg resistor or 0 (direct connecting the ground symbol to node 2). Your experiments may show that the simulation results are the same.

However to not suggest to a newbie to directly connect mains with the secondary side circuit, let’s put a 1G resistor between mains and ground.

3 Likes

Thank you, that was really helpful, I appreciate it! The circuit is working now as expected. A few more questions–

  • Is there a way to tune that resistance value in the .options statement?
  • What do you mean by a better model for including resistors in the subcircuit model? How much better is it and in what way?

Sure thing.

Do you mean via the “Tune” feature in the Simulator app? If so, then no. If you need things like this, you’re better off putting explicit resistors in series with the inductors instead of using that .options statement.


The model of your transformer as it stands right now is pretty basic and very ideal. There are things that happen in the real world which your model doesn’t consider.

First is loss due to the leakage inductance or, in other words, the coupling coefficient. This is the number at the end of your K-statement, and it’s 1 which indicates perfect transfer of energy between the windings (i.e. no leakage). In the real world there will be some leakage, so something less than 1. There is a procedure to measure this on a physical transformer so you can put a more accurate number in your model. It requires an LCR meter though, so I would just leave it at 1 for now as long as your transformer uses a non-air core material (e.g. iron or steel).

Second is the loss due to the core of the transformer. The core material can saturate under certain conditions and mess up the magnetic field. Modeling these effects requires a completely different model structure, so I would forget about it and assume no saturation or other core effects occur. If your transformer is rated for 115Vrms 60Hz mains at or above your desired load, then it’s a safe assumption to make.

Last is the resistance in the copper wires your transformer is made out of. The series resistance of these wires create a voltage drop which generates heat (so it’s sometimes called “heat loss”) dependent on how much current your load draws. This effect is easy to model and requires you to find the ESR (equivalent series resistance) of each winding of the transformer. Do this by measuring each side with an ohmmeter. In addition, modeling the ESRs avoids one of your original problems where the SPICE engine can’t simulate a voltage source directly driving a pure inductor. Instead of putting fake 100milliohm resistances just to trick the simulation into running, you’ll be including the actual ESRs of the windings which does that and also gives you better voltage-drop/heat-loss modeling. You can put these resistors in the transformer subcircuit…or explicitly on the schematic external to the transformer, as shown below. You can also use the “Tune” function on the latter.

Depends how heavy your load is and how sensitive your application is to getting slightly lower voltage than intended. The load in your original schematic is 1Kohm+330ohm which is a pretty “light” load (low current) so it might not matter for that. If your load will end up being heavier than that (draws more current), then the voltage drops due to winding ESR will get higher, and your transformer will heat up more. Properly modeling the ESRs will allow you to see these increased drops in your simulation output. Keep in mind that the 330ohm is also causing a voltage drop at your output…but it looks intentional???

1 Like

Ok, thanks for the reply! I don’t have any other questions

Sure. One thing I’ll add is that it looks like you might be using the 330 and 1K to form a voltage divider to acheive a target voltage. If VOUT is going elsewhere to power a device, that device will load down the voltage at the output depending on how much current it draws. You can see this in simulation by putting a DC current source on the output with a value at the estimated average current draw of the device. If the loading down is undesirable, then you need something to “buffer” the output. Typically linear voltage regulators are used for this because they not only buffer but also reduce 120Hz ripple by using a feedback loop to keep the output constant. See @holger 's LM317 example here: Simulation examples for KiCad/Eeschema/ngspice

1 Like

Ok great, thanks! For now I’m just building the rectifier, but good to keep in mind if I decide to go further

1 Like

Progress update-- I added explicit resistor components for the transformer winding resistances (32 & 2 for primary & secondary) which resulted in the simulator saying the output V = 0. I took out the explicit resistors and defined them in the subcircuit instead, giving me the output below-- weird. Why would switching the resistors from being explicit to going in the subcircuit correct the simulation like that? Shouldn’t both get the same result?

They will give the same result…but only if connected properly. Your subcircuit netlist represents the following:
.

You created parallel resistors instead of series ones, so you’re shorting out the inductors and hence getting near zero output. If you want something which represents my previous schematic, you need to do something like this instead:

.SUBCKT XFORMER 1 2 3 4
L1 5 2 250u
L2 3 6 10u
K1 L1 L2 1
R1 1 5 32
R1 6 4 2
.ends

Note that because you have series components additional internal nodes are needed in between those components. I used 5 and 6 above, but to make it easier to read I’ll use different labels (doesn’t matter) and order the lines differently too (also doesn’t matter):

.SUBCKT XFORMER 1 2 3 4
R1 1 INT1 32
L1 INT1 2 250u
L2 3 INT2 10u
R2 INT2 4 2
K1 L1 L2 1
.ends

Hopefully it makes sense. Give that a shot and see what it gets you.

1 Like

There is another issue then:

The inductance of 250uH is far off from the real inductance of a 60Hz mains transformer. Resistor and coil represent a voltage divider (R and jwL). With low L there will be not enough “resistance” to create any reasonable voltage across the coil, thus 0 output.

Indeed it is difficult to find numbers in the web. It seems to me that, depending on size and power capability, the primary inductance is between 10H and 100H or so. The simulation will show, what results are achievable.

I will update my example as well

2 Likes