sharpie7 / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
2.31k stars 635 forks source link

MOSFET capacitance #333

Open SusiKette opened 5 years ago

SusiKette commented 5 years ago

I noticed that the simulator doesn't simulate capacitance for MOSFETs. This would be very useful feature in my opinion. Building a capacitor mess around the MOSFET (similar to what "CMOS Inverter (w/capacitance)" example circuit uses) just to simulate capacitance takes additional time and looks a bit messy especially if you have more than two MOSFETs. I also noticed that in some cases N-type MOSFETs seem to let current through even though the gate isn't powered at all (similar bug sometimes seems to happen with some switches as well when they are open).

pfalstad commented 5 years ago

Re the second part with the MOSFETs and switches letting current through, can you post an example? use File->Export as Text or Export as Link. Thanks

SusiKette commented 5 years ago

The easiest way of seeing what I mean is to just change "Write" to 1 and "Read" will change to 1 too, regardless of X/SB begin 0.

Link: http://tinyurl.com/y6ajaxem

This is also one circuit that would benefit from MOSFETs having capacitance built into them.

pfalstad commented 5 years ago

Right, I've seen that before. Not sure how to fix that. When a MOSFET is off, we don't treat it as completely off, we instead treat it as a large resistor (10Meg). If we didn't do that, we'd get a singular matrix error, because there would be no way to calculate the voltage of the "Read" node... It's floating.

Since the "Read" node is connected to the other side of the MOSFET by a large resistor which has no current across it, both sides have the same voltage. And the logic output senses voltage without requiring any current.

So to get around this, you need a pulldown resistor at the Read node (to force the node to ground unless there's actual current), or a capacitor to ground (so the voltage of the node can't change without current).

Exaeta commented 5 years ago

@pfalstad I think what he is getting at is the "gate charge" i.e. C_OSS C_ISS etc.

For example, IRF540N has 1220pF C_ISS at 25V.

First you have the "off region", which is straight up, a near flat "turning on" region, and another linear "on" region. Setting the threshold turn on charge, off capacitance, turn-on capacitance, and on capacitance might model this approximately?

Exaeta commented 5 years ago

Maybe something similar to this would be a slight improvement though, if not going for the realistic version:

http://tinyurl.com/y69w2dkv

SusiKette commented 5 years ago

Right, I've seen that before. Not sure how to fix that. When a MOSFET is off, we don't treat it as completely off, we instead treat it as a large resistor (10Meg). If we didn't do that, we'd get a singular matrix error, because there would be no way to calculate the voltage of the "Read" node... It's floating.

Begin able to simulate a floating state probably should be included. There are circuits that rely on it. As far as I know, the voltage of a floating section is based on the charge. Since the capacitance is not simulated for MOSFETs there is no charge to discharge when a section is left floating and then there is no way to calculate the voltage.

A good example is the bus lines in 6502 CPU. It is a line that is not directly connected to a power source or ground. All connections are done with pre-charge, drain or pass MOSFETs. Pre-charge MOSFETs first charge all lines and then a pass MOSFET opens a path to a register, which selectively pulls down the bit lines to get the bus value to match the register's. The 6502 has plenty of examples where capacitance and floating state are useful.

gsuberland commented 2 years ago

Adding my support for this feature. I've been manually simulating the capacitance along with gate resistance and inductance, but it's time consuming to set up and detracts from the clarity of the circuit. I don't know enough Java to implement it myself, otherwise I'd contribute it in a PR. I'd be happy to see it added either as a tickbox option to the MOSFET itself, or in a cloned version of the MOSFET in the same way that ideal and real opamps are delineated.

ormaaj commented 2 years ago

The MOSFET model needs complete replacement really as has been discussed elsewhere. Not much point in changing this one because you can't really derive the geometry-dependent MOSFET gate and junction capacitances. They depend on the type of MOSFET. E.g. VDMOS VDS dependent capacitance can be added with an explicit nonlinear capacitor as in this example https://seventransistorlabs.com/Modeling/SPICE/C_CJO.ckt

To add caps to the current model a subcircuit is the solution. Subcircuits just can't be mapped to another symbol yet and there is no way to pass parameters other than through pin currents and voltages. Those would be the requisite things to fix.