Go Back   Home > Forums > Design & Build > Software Tools

Software Tools SPICE, PCB CAD, speaker design and measurement software, calculators

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 12th September 2007, 09:15 PM   #251
PB2 is offline PB2  United States
diyAudio Member
 
PB2's Avatar
 
Join Date: Sep 2004
Location: North East
Blog Entries: 1
Quote:
Originally posted by andy_c
Pete, your point about the debugger gave me an idea. The EKV manual spells out a sequential algorithm with no looping and a standard mathematical - not programming - notation. This would be the perfect thing for MathCad. I could format the equations such that MathCad would display them identically to the equations in the EKV manual. Then I could look at each intermediate result in MathCad and compare it with the values in the VBA debugger. This would rule out any possibility that I might have misplaced some parentheses or some stupid error like that in my VBA code.

So that will be the next step - then the VHDL translation.

I've done some VB coding also, so if you'd like to have another set of eyes look at your code I'd be happy to take a look. Might save you some time.

Pete B.
  Reply With Quote
Old 12th September 2007, 09:55 PM   #252
andy_c is offline andy_c  United States
Banned
 
Join Date: Apr 2003
Quote:
Originally posted by PB2
I've done some VB coding also, so if you'd like to have another set of eyes look at your code I'd be happy to take a look. Might save you some time.
Wow, thanks man! Here is the spreadsheet and an LTSpice sim. Alt-F11 is the shortcut to the VBA editor.

This is my first foray into VBA. This EKV version is the one I transcribed directly from the manual. The one I translated from Verilog-A is much messier. They both give the same answer. I have assumed that the simulation temperature is the same as the temperature at which the device parameters were extracted.
Attached Files
File Type: zip ekv_model.zip (20.4 KB, 40 views)
  Reply With Quote
Old 12th September 2007, 11:50 PM   #253
PB2 is offline PB2  United States
diyAudio Member
 
PB2's Avatar
 
Join Date: Sep 2004
Location: North East
Blog Entries: 1
Quote:
Originally posted by andy_c


Wow, thanks man! Here is the spreadsheet and an LTSpice sim. Alt-F11 is the shortcut to the VBA editor.

This is my first foray into VBA. This EKV version is the one I transcribed directly from the manual. The one I translated from Verilog-A is much messier. They both give the same answer. I have assumed that the simulation temperature is the same as the temperature at which the device parameters were extracted.

OK, got it Andy, the LTSpice sim works, forgot to mention that I have OpenOffice, not going to buy MS Office *again* until I absolutely need it, LOL! I can read the code and will at least do a quick check of the equations.

Oh, so you've coded it twice and get the same answer? That sure seems to support the idea that you've got it right, or that it is a VBA issue. Wouldn't we want the VBA temp to match the LTSpice temp?

Pete B.
  Reply With Quote
Old 13th September 2007, 12:09 AM   #254
PB2 is offline PB2  United States
diyAudio Member
 
PB2's Avatar
 
Join Date: Sep 2004
Location: North East
Blog Entries: 1
OK temp looks good: 27 deg C for SPICE, 300.15 K for VBA.
  Reply With Quote
Old 13th September 2007, 12:19 AM   #255
andy_c is offline andy_c  United States
Banned
 
Join Date: Apr 2003
Quote:
Originally posted by PB2
OK, got it Andy, the LTSpice sim works, forgot to mention that I have OpenOffice, not going to buy MS Office *again* until I absolutely need it, LOL! I can read the code and will at least do a quick check of the equations.
Great! Thanks a bunch.

Quote:
Oh, so you've coded it twice and get the same answer? That sure seems to support the idea that you've got it right, or that it is a VBA issue. Wouldn't we want the VBA temp to match the LTSpice temp?
The thing that concerns me is that the C code of LTSpice and Micro-Cap might have some "tweaks" or updates that aren't present in the Verilog-A that I have, or documented in the EKV reference manual. Some things changed between the EKV reference manual and the Verilog-A. For example, you'll see the dielectric constants of silicon and the oxide layer are slightly different between the two. Also, I just tried the interpolation function from the VHDL code, and that fixed the problem that caused me to add in the "On Error" VBA code to InterpFunc(). So it looks like the VHDL is more up to date than the Verilog-A code that I got from the Silvaco site.

The temperatures should be the same between VBA and LTSpice at 27 deg C. The temp in Kelvin is 300.15 deg in the VBA code. I never saw that ".15" in the conversion before, but I did verify it on a unit conversion site I visited. Looking at the LTSpice MOSFET model docs, Tnom (parameter measurement temp) defaults to 27 C. In the docs for .OPTIONS, temp (device simulation temp when not specified) is also 27 C. So I think this all matches up.

Again, I really appreciate your double-checking this for me. Checking other people's code is not fun.

Edit: Oops, looks like you posted right before I did.
  Reply With Quote
Old 13th September 2007, 12:43 AM   #256
PB2 is offline PB2  United States
diyAudio Member
 
PB2's Avatar
 
Join Date: Sep 2004
Location: North East
Blog Entries: 1
Yes, revision level came to mind. I notice that the ekv manual is V262, so who knows about further updates. All it takes is a typo in the manual or a missed update as I'm sure you know.

I considered comparing to the VHDL, but started with the ekv manual since you numbered everything and made it so easy. Given that your two versions agree and you think the VHDL is newer, I should probably check against that instead. On equation 54 so I might as well finish, perfect so far, as I expected! Your code is so easy to read, it's really not a chore at all. I'll do it again with the VHDL if it's easy enough to read.

You've been very generous Andy so I'm happy to try and help out here.
  Reply With Quote
Old 13th September 2007, 02:21 AM   #257
PB2 is offline PB2  United States
diyAudio Member
 
PB2's Avatar
 
Join Date: Sep 2004
Location: North East
Blog Entries: 1
OK here's something. Equation 58 in the manual is KPa, the code is KP. I've not dug into the theory to really understand this, I figure you'll know off the top of your head.
Similarly with GAMMAa in equation 60, and I probably missed VTOa.

There seems to be a KP, AKP, and KPa, in the manual.

KPa is given in terms of KP in equation 28. Oh, I see that they're only related to short distance matching, so I'd assume we're taking them to be equal with a perfect match? Or ....?

Also checked all the input data and model parameters, all looks fine. I did notice the differences in the dielectric constants as you mentioned.

I'd say it all looks fine. Best guess is a revision level difference. I'll try to get to the VHDL soon.

As far as precision goes, I'd expect that SPICE uses doubles internally, anyone have any details about this?

This is from one of Intusoft's newsletters concerning the Pentium divide bug, which is not the issue however they get different answers with different math modes:
"As a test we ran two simulations of Chua’s circuit on a Pentium and a 486; one using the coprocessor and one using coprocessor emulation. (ISSPICE4 contains a coprocessor emulation mode.) If the results from the two 486 runs were the same, but different on the Pentium, the bug might be the cause. Unfortunately, all four answers were different. Revealing that the math libraries used to compile ISSPICE4 had just as much effect on the initial conditions as the platform."

Still I understand that math libraries and precision should not cause such a large error. But if truncation to zero causes an entire term in an equation to drop out, very unlikely, then larger errors might be seen.

Much more likely a revision difference.

Pete B.
  Reply With Quote
Old 13th September 2007, 02:38 AM   #258
andy_c is offline andy_c  United States
Banned
 
Join Date: Apr 2003
Quote:
Originally posted by PB2
There seems to be a KP, AKP, and KPa, in the manual.

KPa is given in terms of KP in equation 28. Oh, I see that they're only related to short distance matching, so I'd assume we're taking them to be equal with a perfect match?
Yes, you'll see that the "sub a" terms are equal to the terms without "sub a" when perfect matching is assumed. According to the docs, "These model equations are only applicable in Monte-Carlo and sensitivity simulations". So I didn't change the variable names to the "sub a" ones. I just kept the original names.

The VHDL looks messy, so I've given it a rest until tomorrow, when I'll do a third try. Third time is a charm?

Edit: All the C math functions take double arguments and return double, so pretty much all numerical C code is written using double.

Another weird thing I noticed was in the VBA docs, when they talked about min and max double values. It's clear that the doubles in VBA are not IEEE-754 compliant. Compliant implementations all have the same min and max representable values for a 64-bit implementation. But I think the tolerance on f(x)=0 in nonlinear equation solving would swamp out precision issues with double between C and VBA.
  Reply With Quote
Old 13th September 2007, 03:17 AM   #259
PB2 is offline PB2  United States
diyAudio Member
 
PB2's Avatar
 
Join Date: Sep 2004
Location: North East
Blog Entries: 1
Quote:
Originally posted by andy_c


Yes, you'll see that the "sub a" terms are equal to the terms without "sub a" when perfect matching is assumed. According to the docs, "These model equations are only applicable in Monte-Carlo and sensitivity simulations". So I didn't change the variable names to the "sub a" ones. I just kept the original names.

The VHDL looks messy, so I've given it a rest until tomorrow, when I'll do a third try. Third time is a charm?

Edit: All the C math functions take double arguments and return double, so pretty much all numerical C code is written using double.

Another weird thing I noticed was in the VBA docs, when they talked about min and max double values. It's clear that the doubles in VBA are not IEEE-754 compliant. Compliant implementations all have the same min and max representable values for a 64-bit implementation. But I think the tolerance on f(x)=0 in nonlinear equation solving would swamp out precision issues with double between C and VBA.

I'll also probably look at the VHDL tomorrow.

Much of my digital design and microcode work involved floating point math hardware for both IEEE-754 and IBM-370 formats. I believe that there were often some mode settings in hardware implementations to optimize for speed. This link claims that denorms can be disabled in Pentium 4 making it much faster but not exactly IEEE-754 compliant. Probably fine for graphics transformations, not for numerical calculations:
http://www.cygnus-software.com/paper...dinfinity.html

I agree that if double precision is used throughout that these considerations should be insignificant.

That's funny about VBA, maybe they use BCD arithmetic, LOL! I think the 8087 would actually do BCD math on variable length strings, LOL!
  Reply With Quote
Old 13th September 2007, 03:35 AM   #260
andy_c is offline andy_c  United States
Banned
 
Join Date: Apr 2003
Quote:
Originally posted by PB2
Much of my digital design and microcode work involved floating point math hardware for both IEEE-754 and IBM-370 formats.
Sounds like you've done some heavy duty stuff.

My only brush with IEEE-754 was when porting a large application from Borland C++ to MS Visual C++. At the time, Visual C++ was at version 6, and sacrificed IEEE-754 compliance for speed, while the Borland compiler was compliant, but produced slower code. There were some strange floating-point bugs I had to fix in the port. These were mostly in loops that erroneously used floating-point conditions to control loop execution. These loops would execute a different number of times in the code of the two compilers. But of course, this only happened in obscure cases .
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with Spice simulation overmind Everything Else 4 23rd December 2002 04:58 PM


New To Site? Need Help?

All times are GMT. The time now is 01:29 AM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright ©1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2