Menu

Loading User defined code model.

Help
Fahim
2012-05-22
2013-06-12
1 2 > >> (Page 1 of 2)
  • Fahim

    Fahim - 2012-05-22

    Hi,
    I am new to the Ngspice/Xspice.

    I am trying to create the new code model. I have created the interface and model file.

    Can anyone please tell me the steps to load the new code model. he code is as below please let me know if the usage of new code model is proper or not

    Small Signal Amplifier
    *
    *This circuit simulates a small signal amplifier
    *with a diode limiter.
    *
    .dc Vin -1 1 .05
    *
    Vin       Input common             DC 0
    R_source Input Amp_In         100
    *
    D_Neg 0   Amp_In              1n4148
    D_Pos     Amp_In common            1n4148
    *
    C1        Amp_In common            1uF
    A1        Amp_In common Amp_Out    Amp
    R_Load    Amp_Out common           1000
    *
    .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 Amp Amplifier (gain = -10 in_offset = 1e-3
    +                     rin = 1e6 rout = 1e1)
    *
    .end

    Regards
    Fahim

     
  • Fahim

    Fahim - 2012-05-22

    The new code model is Amplifier. Thanks

     
  • Holger Vogt

    Holger Vogt - 2012-05-22

    Fahim,

    please have a look at the actual manual
    http://ngspice.sourceforge.net/docs/ngspice-manual.pdf
    chapters 25.3 and  27.2 ff

    Regards

    Holger

     
  • Fahim

    Fahim - 2012-05-23

    Hi Holger,

    I have follow the same steps to create the model but its still not working and giving above error.

    Could please let me know if there is any error in the code given above.

    Regards,
    Fahim

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    Fahim,

    you have to be more specific:

    What error message?

    Correctness of usage depends on your new code model!
    What are the new interface specifications?

    Holger

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    Fahim,

    please also have a look at the manual, chapter 2.1 on the gnd node!

    Holger

     
  • Fahim

    Fahim - 2012-05-23

    Hi Holger,

    I am getting the below error.

    Error on line 15 : a1 amp_in common amp_out amp
    MIF-ERROR - unable to find definition of model amp
    Model issue on line 22 : .model amp amplifier (gain=-10 in_offset=1e-3 rin=1e6 ro …
    Unknown model type amplifier - ignored

    Regards,
    Fahim

     
  • Fahim

    Fahim - 2012-05-23

    Regarding the ground model I have one common branch in my model which act as ground.

    To check whether this causing the problem I deleted the port in the interface file and use it as gnd.

    But still its giving me error.

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    Fahim,

    you have to replace 'common' by 'gnd'.

    The error message however tells you that your new code model has not been recongnized by ngspice.

    The only way to help you may be that you decribe what you did 'step by step'.

    Holger

     
  • Fahim

    Fahim - 2012-05-23

    Hi,

    I have changed the common with gnd also but still getting same error.

    I had follow the below steps.

    Step1: Created the new directory under ngspice/src/xspice/icm/xtradev as Amplifier.
    Step2 : Copied interface and cmodel file in it.
    Step3: did the necessary changes in it.
    Step4: Added name of code model in the modpath.lst file.
    Step5: Now to load the codemodel I created the release directory under the ngspice directory.
    step6:  cd release
    step7:  ../configure -enable-xspice -disable-debug -with-readline=yes
    Step8: make
    Step9 : sudo make install

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    as a short test, replace
    .model Amp Amplifier (gain = -10 in_offset = 1e-3  rin = 1e6 rout = 1e1)
    by

    .model Amp gain(gain = -10 in_offset = 1e-3)

    Holger

     
  • Fahim

    Fahim - 2012-05-23

    I had use the existing model gain and it was running without any error.

    Regards,
    Fahim

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    next test:
    to see if codemodel has been made, goto :
    ngspice/release/src/xspice/icm/xtradev/amplifier
    Is there a cfunc.c, cfunc.o, ifspec.c ifspec.o ?

    Holger

     
  • Fahim

    Fahim - 2012-05-23

    Yes its there.

    Should I uninstall ngspice and then install it again?

    Fahim

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    yes
    try a
    make clean
    first. You may then do
    make 2>&1 | tee make.log
    instead of
    make
    , which gives you a make.log file in dir ngspice for analysis.

    Holger

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    make uninstall

    will remove the installed files.

    Holger

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    correction:

    make.log to be found in ngspice/release

    Holger

     
  • Fahim

    Fahim - 2012-05-23

    I checked the log in release but no error for creating .c and .o file.
    make uninstall will uninstall the ngspice correct?

    Fahim

     
  • Holger Vogt

    Holger Vogt - 2012-05-23

    just another idea:

    ngspice internally sets all command lines to lower case letters before execution.
    Please rename your code model accordingly:
    Amplifier --> amplifier
    and try again.

    Holger

     
  • Fahim

    Fahim - 2012-05-24

    I try it but still not working

    Fahim

     
  • Holger Vogt

    Holger Vogt - 2012-05-25

    next step:

    Could you please list your input files:
    cfunc.mod and ifspec.ifs.

    I will cheeck if there is something irregular.

    I have easily been able to generate a XSPICE model 'amplifier' using the procedure described.

    Regards

    Holger

     
  • Fahim

    Fahim - 2012-05-25

    /*ifspec.ifs*/

    NAME_TABLE:

    C_Function_Name:       ucm_amplifier
    Spice_Model_Name:      amplifier
    Description:           "A simple gain block"

    PORT_TABLE:

    Port_Name:             amp_in            amp_out
    Description:           "input"           "output"
    Direction:             in                out
    Default_Type:          v                 v
    Allowed_Types:          
    Vector:                 no               no
    Vector_Bounds:          -                -
    Null_Allowed:          no                no

    PARAMETER_TABLE:

    Parameter_Name:     in_offset           gain        rin                 rout
    Description:        "input offset"      "gain"      "input resistance"  "Output resistance"
    Data_Type:          real                real        real real
    Default_Value:      0.0                 1.0         0.0                 0.0
    Limits:             -                   -           -                   -
    Vector:              no                  no         no                  no
    Vector_Bounds:       -                   -          -                   - 
    Null_Allowed:       yes                 yes         yes                 yes   

     
  • Fahim

    Fahim - 2012-05-25

    /*cfund.mod*/

    /*=== UCM_AMPLIFIER ROUTINE ===*/
                                                      

    void ucm_amplifier(ARGS)   /* structure holding parms, inputs, outputs, etc.     */
    {
        Mif_Complex_t ac_gain;

        if(ANALYSIS != MIF_AC) {
            OUTPUT(amp_out) =  PARAM(gain) *((PARAM(rout))*(PARAM(rin)) + PARAM(in_offset));
            PARTIAL(amp_out,amp_in) = PARAM(gain);
        }
        else {
            ac_gain.real = PARAM(gain);
            ac_gain.imag= 0.0;
            AC_GAIN(amp_out,amp_in) = ac_gain;
        }

    }

     
  • Holger Vogt

    Holger Vogt - 2012-05-25

    Hi,

    I did not detect a princple bug, was able do generate a new code model 'amplifier' according to (MS Windows, MINGW compiler):

    Step1: Created the new directory under ngspice/src/xspice/icm/xtradev as Amplifier.
    Step2 : Copied interface and cmodel file in it.
    Step3: did the necessary changes in it.
    Step4: Added name of code model in the modpath.lst file.
    Step5: cd 'ngspice directory'
    step6: cd release
    step7: ../configure -enable-xspice -disable-debug -with-readline=yes
    Step8: make clean
    Step9 : make
    step 10: make install

    However I changed line
    OUTPUT(amp_out) = PARAM(gain) *((PARAM(rout))*(PARAM(rin)) + PARAM(in_offset));
    (not input, gain multipled by resistance?) back to
    OUTPUT(amp_out) =  PARAM(gain) *(INPUT(amp_in) + PARAM(in_offset));
    all common to gnd in the input file,
    and everything works well!

    Holger

     
  • Fahim

    Fahim - 2012-05-28

    Hi Holger,

    I think there should not be problem with above statement because it is creating the .c and .o file without any error.

    However I changed the cmod file but still it is not working. Could you please share the files.

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.