Several problems with simulating bridge rectifier

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

Ah, that makes sense. So when the resistor was 100mohm, the 250uH inductor impedance would swamp out the resistor. Now with 32ohm it swamps out the inductor. OK, so I guess adding the measured ESR without the measured inductance to match it was a poor idea. My bad. I suppose if one wants to make decent models of their inductive components they ought to invest in an LCR meter.

Ok makes sense – I tried one simulation with the resistors explicitly defined and one with them defined in the subcircuit following your instructions. Running with the resistors defined in the subcircuit results in a voltage output, but having them defined explicitly doesn’t. Is that what @holger is talking about?


Is there a way to measure or approximate the inductances of the transformer just using a multimeter?

I think that the I-V characteristic of a mains frequency transformer will generally be very non-linear. It is defined by the B-H loop. Therefore discussing it in terms of simple inductance is likely to be inaccurate, and it will be difficult to find such a specification.

Have a look at this waveform

image

or see

https://www.google.com/search?sxsrf=APq-WBspHbZGNB2l3tdEH_ep6wyJTUWYmw:1647146597049&source=univ&tbm=isch&q=transformer+magnetizing+current+waveforms&fir=IuNPlP09iPsZsM%2C9WZIMGOqtq9pUM%2C_%3BCPyoalV7xqgyRM%2CyfyQHq6g-owMzM%2C_%3B5h7bFYVsqWoQDM%2C9WZIMGOqtq9pUM%2C_%3B49vQNxn-BycsNM%2CeqozhziyQTkxpM%2C_%3BpzaCE_r4qUZ3mM%2CeqozhziyQTkxpM%2C_%3BdNqteTe84IoPlM%2CNcreJdeewVj8KM%2C_%3BweQUtmMwhccypM%2C7wEcsc-woK-drM%2C_%3BDFELbnojamkWdM%2C9WZIMGOqtq9pUM%2C_%3BO1Oe06wKf553FM%2CgPzXv0_S0mLL8M%2C_%3BwX_flI0f_PluDM%2CXPIBQeGYpMMZ6M%2C_&usg=AI4_-kTM8GD8Nj5ETzc2tgwx0Md-fgPs_g&sa=X&ved=2ahUKEwillr2eo8L2AhXUPn0KHewFCEIQjJkEegQICRAC&biw=2133&bih=1121&dpr=0.9#imgrc=dTRqJY3_Y0nwpM

BTW one could make the magnetizing current waveform much more linear by introducing a gap in the transformer core. But that would greatly increase the magnetizing current, would increase losses, and would generally gain no other benefits.

1 Like

No, that’s not what he’s talking about. It sounds like you have two separate issues being conflated. First is introducing the resistors into the subcircuit correctly. You haven’t shown that in your screenshot, so it’s possible you haven’t done it correctly. Second is that your measured values of 32ohm and 2ohm don’t mesh well with the very low values of inductance which you specified in the micro-henry range. High wire resistance will correlate with higher inductances, simply because a longer piece of wire (more resistance) results in more turns around the core (higher inductance). When you increased the primary resistance from 100milliohm to 32ohm, it completely overshadows the puny little 250uH as if it’s no longer there anymore.

Not that I know of. But I don’t think you need the exact values unless you want to calculate the actual K of the transformer. Holger’s suggestion is to increase the primary into the 10 to 100 Henry range. That puts you into the ballpark of an actual AC mains transformer’s typical primary inductance. So to keep your same turn ratio, you can do something like 25H in the primary and 1H in the secondary. You can also see his LM317 power supply example in this post as another reference:

1 Like

Is the inaccuracy caused by ignoring this a huge deal? I don’t really know much about electrical engineering and want to make as many simplifying assumptions as I can make, at least in this first attempt to build the rectifier.

It depends upon what you are analyzing. If you have a typical transformer that is heavily loaded, then this current waveform might be a small percentage of the total. But if the transformer core is being heavily driven (maybe it is designed for 220 VAC 60 Hz and it is being used with 250 VAC 50 Hz) and the output loading is light, then this current component is likely to be significant.

My guess is that there are some SPICE models which better account for this. But component modeling is not an area of my expertise.

EDIT: If the transformer is powered by the mains, and you are generally concerned with output characteristics, then IMHO it is not so likely to be an issue.

1 Like

Ok, sorry forgot to include that-- now it looks to be the same


1 Like

Also, this might not be the right place to ask this question, but basically my process from here is assembling the components onto a breadboard prototype and testing with a function generator. The function generator I have access to has voltage that’s way too low (I’d need the amplitude to be 170VAC) – do you have any recommendations for inexpensive function generators that would do the job?

I doubt that there is such a thing. Understand that what you are doing is potentially dangerous if you do not know what you are doing. I have done a significant amount of work with AC mains voltage.

I think you want a variable autotransformer and an isolation transformer. But those two together would probably be a few hundred dollars.

1 Like