diff options
-rw-r--r-- | Examples/Analysis_Of_Digital_IC/74LS04-test/74LS04.pro | 7 | ||||
-rw-r--r-- | Examples/Clampercircuit/D.lib | 2 | ||||
-rw-r--r-- | Examples/Clippercircuit/D.lib | 2 | ||||
-rw-r--r-- | Examples/Diode_characteristics/D.lib | 2 | ||||
-rw-r--r-- | library/SubcircuitLibrary/74LS04/74LS04.pro | 7 | ||||
-rw-r--r-- | library/deviceModelLibrary/Diode/D.lib | 2 | ||||
-rw-r--r-- | library/deviceModelLibrary/Transistor/NPN.lib | 6 | ||||
-rw-r--r-- | library/ngspicetoModelica/Mapping.json | 72 | ||||
-rw-r--r-- | src/ngspicetoModelica/ModelicaUI.py | 26 | ||||
-rw-r--r-- | src/ngspicetoModelica/NgspicetoModelica.py | 64 |
10 files changed, 112 insertions, 78 deletions
diff --git a/Examples/Analysis_Of_Digital_IC/74LS04-test/74LS04.pro b/Examples/Analysis_Of_Digital_IC/74LS04-test/74LS04.pro index 38d194c6..a75a7de6 100644 --- a/Examples/Analysis_Of_Digital_IC/74LS04-test/74LS04.pro +++ b/Examples/Analysis_Of_Digital_IC/74LS04-test/74LS04.pro @@ -52,10 +52,10 @@ LibName18=opto LibName19=atmel LibName20=contrib LibName21=power -LibName22=device +LibName22=eSim_User LibName23=transistors LibName24=conn -LibName25=linear +LibName25=eSim_Plot LibName26=regul LibName27=74xx LibName28=cmos4000 @@ -67,6 +67,3 @@ LibName33=eSim_Miscellaneous LibName34=eSim_Power LibName35=eSim_Sources LibName36=eSim_Subckt -LibName37=eSim_User -LibName38=eSim_Plot -LibName39=eSim_PSpice diff --git a/Examples/Clampercircuit/D.lib b/Examples/Clampercircuit/D.lib index 8a7fb4da..f53bf3e0 100644 --- a/Examples/Clampercircuit/D.lib +++ b/Examples/Clampercircuit/D.lib @@ -1,2 +1,2 @@ -.model 1n4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04) +.model 1N4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04) diff --git a/Examples/Clippercircuit/D.lib b/Examples/Clippercircuit/D.lib index 8a7fb4da..f53bf3e0 100644 --- a/Examples/Clippercircuit/D.lib +++ b/Examples/Clippercircuit/D.lib @@ -1,2 +1,2 @@ -.model 1n4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04) +.model 1N4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04) diff --git a/Examples/Diode_characteristics/D.lib b/Examples/Diode_characteristics/D.lib index 8a7fb4da..f53bf3e0 100644 --- a/Examples/Diode_characteristics/D.lib +++ b/Examples/Diode_characteristics/D.lib @@ -1,2 +1,2 @@ -.model 1n4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04) +.model 1N4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04) diff --git a/library/SubcircuitLibrary/74LS04/74LS04.pro b/library/SubcircuitLibrary/74LS04/74LS04.pro index 38d194c6..f63b751e 100644 --- a/library/SubcircuitLibrary/74LS04/74LS04.pro +++ b/library/SubcircuitLibrary/74LS04/74LS04.pro @@ -52,10 +52,10 @@ LibName18=opto LibName19=atmel LibName20=contrib LibName21=power -LibName22=device +LibName22=eSim_Plot LibName23=transistors LibName24=conn -LibName25=linear +LibName25=eSim_User LibName26=regul LibName27=74xx LibName28=cmos4000 @@ -67,6 +67,3 @@ LibName33=eSim_Miscellaneous LibName34=eSim_Power LibName35=eSim_Sources LibName36=eSim_Subckt -LibName37=eSim_User -LibName38=eSim_Plot -LibName39=eSim_PSpice diff --git a/library/deviceModelLibrary/Diode/D.lib b/library/deviceModelLibrary/Diode/D.lib index 8a7fb4da..f53bf3e0 100644 --- a/library/deviceModelLibrary/Diode/D.lib +++ b/library/deviceModelLibrary/Diode/D.lib @@ -1,2 +1,2 @@ -.model 1n4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04) +.model 1N4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04) diff --git a/library/deviceModelLibrary/Transistor/NPN.lib b/library/deviceModelLibrary/Transistor/NPN.lib index 6509fe7a..be5f3073 100644 --- a/library/deviceModelLibrary/Transistor/NPN.lib +++ b/library/deviceModelLibrary/Transistor/NPN.lib @@ -1,4 +1,4 @@ .model Q2N2222 NPN( Is=14.34f Xti=3 Eg=1.11 Vaf=74.03 Bf=400 Ne=1.307 -+ Ise=14.34f Ikf=.2847 Xtb=1.5 Br=6.092 Nc=2 Isc=0 Ikr=0 Rc=1 Cjc=7.306p -+ Mjc=.3416 Vjc=.75 Fc=.5 Cje=22.01p Mje=.377 Vje=.75 Tr=46.91n Tf=411.1p -+ Itf=.6 Vtf=1.7 Xtf=3 Rb=10) ++ Ise=14.34f Ikf=0.2847 Xtb=1.5 Br=6.092 Nc=2 Isc=0 Ikr=0 Rc=1 Cjc=7.306p ++ Mjc=0.3416 Vjc=0.75 Fc=0.5 Cje=22.01p Mje=0.377 Vje=0.75 Tr=46.91n Tf=411.1p ++ Itf=0.6 Vtf=1.7 Xtf=3 Rb=10) diff --git a/library/ngspicetoModelica/Mapping.json b/library/ngspicetoModelica/Mapping.json index e254d66a..d0c4fb1c 100644 --- a/library/ngspicetoModelica/Mapping.json +++ b/library/ngspicetoModelica/Mapping.json @@ -13,10 +13,11 @@ }, "Sources":{ "v":{ - "pulse":"Analog.Sources.TrapezoidVoltage", - "sine":"Analog.Sources.SineVoltage", + "pulse" : "Analog.Sources.TrapezoidVoltage", + "sine" : "Analog.Sources.SineVoltage", "pwl" : "Analog.Sources.TableVoltage", - "dc" : "Analog.Sources.ConstantVoltage" + "dc" : "Analog.Sources.ConstantVoltage", + "ac" : "Analog.Sources.ConstantVoltage" }, "i":{ @@ -26,22 +27,55 @@ }, "Devices":{ "d":{ - "import":"Analog.Semiconductors.Diode", + "import":"Spice3.Internal.DIODE", + "modelcard":"Spice3.Semiconductors.ModelcardDIODE", "mapping":{ - "is":"Ids" + "is":"IS", + "rs":"RS", + "n":"N", + "tt":"TT", + "cjo":"CJO", + "vj":"VJ", + "m":"M", + "eg":"EG", + "xti":"XTI", + "fc":"FC", + "bv":"BV", + "ibv":"IBV", + "tnom":"TNOM", + "kf":"KF", + "af":"AF", + "g":"G" + }, + "default":{ - "Ids":"880.5e-18", - "Vt":"0.025", - "R":"1e12" - } + "IS":"1e-14", + "RS":"0.0", + "N":"1.0", + "TT":"0.0", + "CJO":"0.0", + "VJ":"1.0", + "M":"0.5", + "EG":"1.11", + "XTI":"3.0", + "FC":"0.5", + "BV":"-1e40", + "IBV":"1e-3", + "TNOM":"27", + "KF":"0.0", + "AF":"1.0", + "G":"0" + + } }, "m":{ "import":"BondLib.Electrical.Analog.Spice", "mapping":{ + "tnom":"Tnom", "vto":"VT0", "gamma":"GAMMA", @@ -60,8 +94,8 @@ "cgbo":"CGB0", "cgso":"CGS0" - }, + "default":{ "Tnom":"300", "VT0":"0", @@ -81,13 +115,13 @@ "CGB0":"0", "CGS0":"0" - } - }, + "q":{ "import":"Analog.Semiconductors", "mapping":{ + "bf":"Bf", "br":"Br", "is":"Is", @@ -101,8 +135,11 @@ "mje":"Me", "vjc":"Phic", "mjc":"Mc" + }, + "default":{ + "Bf":"50", "Br":"0.1", "Is":"1e-16", @@ -118,12 +155,13 @@ "Mc":"0.333" } - }, - "j":{ + "j":{ + "import":"Spice3.Internal.JFET", "mapping":{ + "kf":"KF", "rs":"RS", "is":"IS", @@ -141,6 +179,7 @@ }, "default":{ + "KF":"0", "RS":"0", "IS":"1e-14", @@ -155,13 +194,10 @@ "LAMBDA":"0", "B":"1" - } } - - }, + }, - "Models":{ "zener":{ "import":"Analog.Semiconductors.ZDiode", diff --git a/src/ngspicetoModelica/ModelicaUI.py b/src/ngspicetoModelica/ModelicaUI.py index aa7cb330..cd5cf03b 100644 --- a/src/ngspicetoModelica/ModelicaUI.py +++ b/src/ngspicetoModelica/ModelicaUI.py @@ -1,4 +1,5 @@ import os +import traceback from PyQt4 import QtGui, QtCore from configuration.Appconfig import Appconfig from projManagement import Worker @@ -45,7 +46,7 @@ class OpenModelicaEditor(QtGui.QWidget): def browseFile(self): self.ngspiceNetlist = QtGui.QFileDialog.getOpenFileName( - self, 'Open Ngspice file', BROWSE_LOCATION) + self, 'Open Ngspice Netlist', BROWSE_LOCATION) self.FileEdit.setText(self.ngspiceNetlist) def callConverter(self): @@ -158,9 +159,11 @@ class OpenModelicaEditor(QtGui.QWidget): ) # Adding 'numNodesSub' by Fahim # Creating Final Output file - newfile = self.ngspiceNetlist.split('.') - newfilename = newfile[0] + fileDir = os.path.dirname(self.ngspiceNetlist) + newfile = os.path.basename(self.ngspiceNetlist) + newfilename = os.path.join(fileDir, newfile.split('.')[0]) outfile = newfilename + ".mo" + out = open(outfile, "w") out.writelines('model ' + os.path.basename(newfilename)) out.writelines('\n') @@ -207,24 +210,25 @@ class OpenModelicaEditor(QtGui.QWidget): self.msg = QtGui.QMessageBox() self.msg.setText( - "Ngspice netlist successfully converted to OpenModelica" + + "Ngspice netlist successfully converted to OpenModelica " + "netlist" ) self.obj_appconfig.print_info( - "Ngspice netlist successfully converted to OpenModelica" + + "Ngspice netlist successfully converted to OpenModelica " + "netlist" ) self.msg.exec_() - except Exception as e: + except BaseException as e: + traceback.print_exc() + print("================") self.msg = QtGui.QErrorMessage() self.msg.setModal(True) - self.msg.setWindowTitle("Ngspice to Modelica conversion error") + self.msg.setWindowTitle("Conversion Error") self.msg.showMessage( - 'Unable to convert NgSpice netlist to Modelica netlist.' + - 'Check the netlist :' + - str(e)) - self.msg.setWindowTitle("Ngspice to Modelica conversion error") + 'Unable to convert Ngspice netlist to Modelica netlist. ' + + 'Check the netlist : ' + repr(e) + ) def callOMEdit(self): diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index a78bad1b..83df42a4 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -365,9 +365,9 @@ class NgMoConverter: stat = stat + \ self.getUnitVal(words[i - 1]) + ',' + \ self.getUnitVal(words[i]) + ';' - stat = stat + ']);' + stat = stat[:-1] + ']);' modelicaCompInit.append(stat) - if typ[0] == words[3] and typ[0] != "dc": + if typ[0] == words[3] and typ[0] != "dc" and typ[0] != "ac": # It is DC constant but no dc keyword val_temp = typ[0].split('v') stat = self.mappingData["Sources"][sourceType]["dc"] + \ @@ -382,10 +382,17 @@ class NgMoConverter: '(V = ' + \ self.getUnitVal(words[4]) + ');' # check this modelicaCompInit.append(stat) + elif typ[0] == words[3] and typ[0] == "ac": + stat = self.mappingData["Sources"][sourceType][typ[0]] + \ + ' ' + \ + compName + \ + '(V = ' + \ + self.getUnitVal((words[4])) + ');' + modelicaCompInit.append(stat) elif sourceType == 'i': stat = self.mappingData["Sources"][sourceType]["dc"] + \ - ' ' + compName + '(I=' + self.getUnitVal(words[3]) + ');' + ' ' + compName + '(I=' + self.getUnitVal(words[4]) + ');' modelicaCompInit.append(stat) # Now empty the source list as it may be used by subcircuit @@ -399,18 +406,10 @@ class NgMoConverter: deviceName = eachline[0].lower() if deviceName == 'd': if len(words) > 3: - if 'n' in modelInfo[words[3]]: - n = float(modelInfo[words[3]]['n']) - else: - n = 1.0 - vt = str(float(0.025 * n)) - ''' - stat = self.mappingData["Devices"][deviceName]["import"]+\ - ' '+words[0] + '(Ids = ' + modelInfo[words[3]]['is']+\ - ', Vt = ' + vt + ', R = 1e12' +');' - ''' - start = self.mappingData["Devices"][deviceName]["import"] - stat = start + " " + words[0] + "(" + start = "\nparameter " + start += \ + self.mappingData["Devices"][deviceName]["modelcard"] + stat = start + " card" + words[0] + "(" tempstatList = [] userDeviceParamList = [] refName = words[-1] @@ -425,17 +424,14 @@ class NgMoConverter: ) tempstatList.append( actualModelicaParam + - "=" + - self.getUnitVal( - modelInfo[refName][key]) + - " ") + " = " + + self.getUnitVal(modelInfo[refName][key]) + ) userDeviceParamList.append( str(actualModelicaParam)) except BaseException: pass - # Adding Vt and R - userDeviceParamList.append("Vt") - tempstatList.append("Vt=" + vt) + # Running loop over default parameter of OpenModelica for default in (self.mappingData ["Devices"] @@ -452,11 +448,14 @@ class NgMoConverter: [default] ) tempstatList.append( - default + "=" + - self.getUnitVal(defaultValue) + " ") - - stat += ",".join(str(item) for item in tempstatList) + ");" - + default + " = " + + self.getUnitVal(defaultValue)) + + stat += ", ".join(str(item) for item in tempstatList) + stat += ");" + "\n\n" + stat += self.mappingData["Devices"][deviceName]["import"] + stat += " " + words[0] + "(modelcarddiode=card" + words[0] + stat += ");" else: stat = (self.mappingData ["Devices"] @@ -935,8 +934,8 @@ class NgMoConverter: # Replace hyphen '-' from node for i in nodeTemp: + i = i.replace("-", "") if i not in node: - i = i.replace("-", "") node.append(i) for i in range(0, len(node), 1): @@ -969,10 +968,11 @@ class NgMoConverter: pinInit = pinInit + nodeDic[protectedNode[i]] pinInit = pinInit + ';' pinProtectedInit = pinProtectedInit + ';' - # print "Node---->",node - # print "nodeDic----->",nodeDic - # print "PinInit----->",pinInit - # print "pinProtectedinit--->",pinProtectedInit + # print ("Node---->",node) + # print ("nodeDic----->",nodeDic) + # print ("PinInit----->",pinInit) + # print ("pinProtectedinit--->",pinProtectedInit) + return node, nodeDic, pinInit, pinProtectedInit def connectInfo(self, compInfo, node, nodeDic, numNodesSub, subcktName): |