Implementing the EKV MOSFET model for DC in Visual Basic (long)

Hi all,

You may be wondering why anyone would want to implement the EKV MOSFET model in Visual Basic. I'm working on audio power amplifier design, and to accurately simulate crossover distortion of a MOSFET class AB output stage, it's necessary to take into account MOSFET subthreshold conduction. The EKV model seems to be the simplest MOSFET model that does subthreshold conduction. Also, in the past I've had good luck with DC model parameter fitting using the Excel solver. Using a freeware called the Engauge Digitizer, it's possible to capture datasheet graphs of drain current into .csv files containing graph data that can be imported into Excel. Then one implements the DC equations of the device model in Excel Visual Basic for Applications (VBA). One defines a cell that represents, say, the sum of squares of the errors between measured and simulated drain currents, and some other cells containing model parameter values. Then you just tell the Excel solver to adjust the model parameters to minimize the value of the cell containing the aggregate error. The solver works pretty nicely as an optimizer in this way - surprisingly well, actually.

Of course, these are vertical MOSFETs, so there are other issues like simulating the nonlinear gate-drain capacitance. I won't get into that here.

Anyway, I downloaded the EKV model manual from the EKV web site. That manual is here:

formatting link

I implemented the DC equations in a big VBA function. This function takes gate, drain and source voltages, along with about 20 EKV parameters as arguments and spits out a drain current. Once it's implemented, it can be called from Excel just like a built-in Excel function.

The problem is, I can't get the predicted drain current to be dead-on equal to what a simulation of the same circuit in LTSpice gives me. The example I tried was from the EKV chapter of the book called "Device Modeling for Analog and RF CMOS Circuit Design" by Ytterdal, Cheng and Fjeldly (Chapter

7). The model parameters are as follows:

.model ekv_test nmos level=12 cox=3.45m xj=0.15u

  • vto=0.6 gamma=0.71 phi=0.97 kp=150u e0=88e6
  • ucrit=4.5e6 dl=-0.05u dw=-0.02u lambda=0.23
  • ibn=1.0 iba=200e6 ibb=350e6
  • weta=0.05 q0=280u lk=0.5u
  • leta=0.28

The Level 12 thing for EKV is LTSpice-specific. In Micro-Cap it's level 44 and varies with other simulators. The circuit I used is a simple DC bias circuit with Source = Body = ground, gate = 0.7 Volts (just above threshold) and drain = 5 Volts. LTSpice gives me a drain current of 10.794 uA. My function gives 10.297 uA. A friend with Micro-Cap simulated this and got 10.795 uA, almost exactly matching LTSpice. I'm trying to figure out how to get my function to be this accurate. I am currently about 4.6 percent off.

Here's what I've tried so far. In the EKV model, there's the weak inversion region (subthreshold conduction) where the drain current looks like an exponential function of Vgs. Then there's strong inversion, where it's a square law relationship. There is an interpolation function, not specified in the EKV model manual, that joins the two regions together in a continuous way. Another paper on EKV specifies the interpolation function as i = (ln(1+exp(v/2))^2, where i = normalized current and v = normalized voltage. When I use this function, the current in the VBA code is way off from the SPICE simulation - about 20 percent. The EKV web site says the full Verilog-A code of the model (version 2.6) is available on request, so I sent a request for it. Unfortunately, I haven't heard back from them. In the meantime, I found the Verilog-A EKV 2.6 source code available for download at the Silvaco web site. So I downloaded and translated it into VBA and got data much closer to the simulation. Here is the Verilog-A code for the interpolation function:

// Normalized forward current is iff (equations 43-44 in the EKV manual) // Normalized forward voltage is fv fv=(VP-VS)/$vt; if (fv >= -0.35) z0=2.0/(1.3 + fv - ln(fv+1.6)); if (fv>=-15 && fv -15.0) y=(1.0 + fv + ln(z1)) / (2.0 + z1); else y= 1.0 / (2.0 + exp(-fv)); iff = y*(1.0 + y);

When I translated this code into VBA and used it for my interpolation function, I went from 20 percent error to 4.6 percent. However, this code is suspect. If the first "if" statement evaluates to true, z0 gets assigned. But then it will just get reassigned in the "else" branch of the next "if" statement. Unfortunately though, fixing the first "if" statement to put an "else if" in there doesn't help beyond the improvements I got by replacing the interpolation function I was using before (the one with logs and exponentials). So I'm still at 4.6 percent error. I'd like to get as close as the two simulators from two different vendors are. The friend who tried the sim with Micro-Cap also tried it with the option to use the interpolation function with exponentials and logs. When I use that same interpolation function in my VBA code, I still get errors from his result on the order of 5 percent. So it's not just the interpolation function that's causing the problem.

I've also noticed other discrepancies and tried other things. For example, the EKV manual states the dielectric constants of the silicon and the oxide as:

EKV manual: eps_si 1.045e-10 eps_ox = 3.45e-11

but the EKV Verilog-A code says this:

Verilog-A code: eps_si = 1.0359e-10 eps_ox = 3.453143E-11

Anybody know which should be used? I actually get closer to the SPICE simulation by using the values from the EKV manual, not the Verilog-A code.

At one point I figured that if I just translated the entire Verilog-A code line-by-line into VBA I'd be able to get agreement. I did so, and the result is the exact same as the code created when I followed the algorithm specified in the EKV manual, before I had access to the Verilog-A code. This required changing the interpolation function and the dielectric constants to match the Verolog-A code.

So I am absolutely stumped. One thing I thought of was that SPICE is taking into account extrinsic elements of the model, such as a MOS diode from drain to body. The equations in the EKV manual are for the intrinsic device only. If this were the cause of the 0.5 uA discrepancy though, you'd think it would show up in the body current. But the computed body current in my code is extremely close to what LTSpice reports. This current is only about 0.25 uA or so, or about half of the discrepancy I'm seeing. Another thing I thought of is that the EKV equations in the manual don't take into account the extrinsic resistances. But my code gives drain current that's low for this example, and extrinsic resistances would reduce the current still further, and require iterative solution as well.

Is there anybody out there (Mike E. maybe?) that has implemented this thing and might provide some hints? Is the Verilog-A code on the Silvaco site up to date? Is there something undocumented I'm not taking into account? I'm starting to run out of ideas.

Any help appreciated, Andy C

Reply to
Andy C
Loading thread data ...

[snip]

PSpice Level=7 (which I think is the same as HSpice Level=49) BSIM3 supports modeling the sub-threshold region.

Awhile back I did a rudimentary cut at some of Win's data to show that it could be done.

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
 Click to see the full signature
Reply to
Jim Thompson

Hi Jim,

I'm aware that the BSIM models support subthreshold conduction. But I found after studying them that they were quite complex. Check out the manual for BSIM3v3 here:

formatting link

Contrast this with the simpler and clearer EKV docs here:

formatting link

I know which one I'd rather code up :-). Also, it appears that the EKV model does quite well considering that it has far fewer parameters than BSIM3. Check out this comparison by a guy from LSI Logic:

formatting link

At any rate, the problem is solved. The manual linked above is for 2.62 - their latest documentation. It appears that the simulators out there are implementing a later version. On the EKV web site, there is VHDL-AMS code for the model. It is here:

formatting link

When I ported the VHDL-AMS to Visual Basic, the currents of the test circuit and the VB implementation matched up. So I am a happy camper :-).

Reply to
Andy C

I'll have to try that. PSpice supports the EKV model, so I'll have to try fitting some data... just for fun ;-)

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
 Click to see the full signature
Reply to
Jim Thompson

Well, here's an update. I transcribed the VHDL-AMS code from the EKV web site, listed here:

formatting link

from the VHDL-AMS to VBA. This code *mostly* gives answers that compare very closely with commercial simulators. However, there's still some corner cases that have problems. One such case that I've found relates to the parameter PHI. The EKV 2.6 manual, available here:

formatting link

states that PHI can be as low as 0.1. However, the VHDL-AMS code linked above limits PHI to a minimum value of 0.2. Checking LTSpice, it clearly allows PHI down to 0.1. Also, I've found several cases where the VHDL code allows a condition for legal device parameter sets where the square root of a negative number is taken, resulting in errors. The VHDL-AMS code, even though it is a more recent revision than the EKV 2.6 manual, is still not the same as what current simulators implement.

So I've pretty much exhausted my possibilities here. Repeated attempts to contact the EKV developers to simply have the latest source code sent to me (in whatever language is available) have resulted in no reponse whatsoever. They claim on their web site that they support their models, but they don't even answer their emails.

Reply to
Andy C

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.