Menu

alter resistor value

An Zou
2017-09-29
2017-12-26
  • An Zou

    An Zou - 2017-09-29

    Hi,

    I met a small problem.
    I need to use alter to change the value of a resistor in the circuit, but it sees that this the "alter" command does not work but no error reported.

    For example,
    The .cir file

    *change_res
    test change res

    VIN 100 0 DC 1
    r1 100 200 1
    r2 200 0 1

    .control
    stop when time = 0.5US
    .endc
    .option trtol=1
    .tran 14PS 1US
    .END**

    The command I used,
    ngspice 417 -> alter r2 = 0.01

    The but the value of r2 are not changed.

     
  • An Zou

    An Zou - 2017-09-29

    May I know if it is available to change the resistor value in transient simulation?

     
  • Holger Vogt

    Holger Vogt - 2017-09-29

    This is a bug!
    An ancient bug you have detected. Thanks for that!
    The resistance change is in fact aknowledged (here->RESresist is changed in resparam.c). However the circuit evaluation is done with its inverse (here->RESconduct in resload.c). here->RESconduct is not changed by the alter command and not recalculated after the change in here->RESresist. We have to check for some details (temperature dependence) and then will upload a fix.

    Holger

     
    • marcel hendrix

      marcel hendrix - 2017-09-30

      I think that bug was noticed and fixed by Robert 1 or 2 years ago.
      The ngspice-27 master code in resparam.c is different from that fix
      (essentially it simultaneously changes resistance and conductance
      in the case RES_RESIST: case).

      -marcel

       
      • Holger Vogt

        Holger Vogt - 2017-09-30

        Where is that fix?

        Holger

         
        • Robert Larice

          Robert Larice - 2017-09-30

          I've only a very dim remembrance of that.

            git log --all -G RESconduct
          

          unveiled two commits, but strangely only on my local repository.
          I've just pushed those two, without introspection.
          They must be somewhere else too, otherwise Marcel could not have
          ever seen them.

           
          • Holger Vogt

            Holger Vogt - 2017-09-30

            I have thought about that already, but it is probably a bit too simplistic.

            When we have TCs on the instance line, we have to aknowledge them as well, or a user changes the tc or the temp.

            Maybe we should add a function to the end of the RESparam() that does a re-calculation of RESconduct as it is done in restemp.c.

            Holger

             
            • Robert Larice

              Robert Larice - 2017-09-30

              Yes it is too simplistic. a carefull investigation of

                git --no-pager grep -nH -e 'RESconduct\|RESresist'
              

              is wanted. In the second commit is a testcase which needs to be
              extended as well.

               
              • Holger Vogt

                Holger Vogt - 2017-09-30

                I have added a new branch fixme-alter-resistor-2 with an upgrade to the RESparam() function. It recalculates the conductance after any parameter change. The test case is not modified yet (and not entered into makefile.am).

                Holger

                 
                • Robert Larice

                  Robert Larice - 2017-10-01

                  I rewrote your branch to fixme-alter-resistor-3.
                  There is a change in user visible behaviour.
                  @r[resistance] now
                  returns the given parameter value (on the instance line)
                  contrary to the given parameter value divided by "m"
                  but @r[conductance] does show the effective conductance
                  (including tc1, tc2, etc)
                  (same for acresistance and acconductance)
                  This might be worth to be mentioned in the manual.
                  Further a resistance sweep should now honour tc1, tc2, tce etc..
                  i think that was ignored in the original code.
                  I didn't actually test the resistance sweep so far.
                  The model code usage of RESconduct and RESm has been cleaned up.
                  There is a third test case now, for a resume after altering tc1

                   
        • marcel hendrix

          marcel hendrix - 2017-09-30

          That is beyond my current Git knowledge (git-blame only seems to show the checked-out branch). It was certainly after 2013-05-09, best guess around 2015-5-14, but as the current master is not in historical order, I have no idea which branches to search. I am certain it was discussed in the fora, but I can't find it there, either.

          -marcel

           

          Last edit: marcel hendrix 2017-09-30
          • Robert Larice

            Robert Larice - 2017-09-30

            just for the git usage:

            git blame is meant to annotate every single line of a specific file to expose
            when / by whom / in which commit that line was changed.
            Indeed this question makes only sense down the history of a specifc commit,
            by default the current HEAD.

            With git log you can search all commits in all branches for a specific change

             git log --all -G regexp
            

            --all for all branches, -G for a specific regexp to search for.

             
  • An Zou

    An Zou - 2017-10-05

    Hi,

    I am sorry for the late reply. Thank you so much for your help, Holger Vogt, marcel hendrix, Robert Larice.

    I will try it now.

    Best,

    An

     
  • Robert Larice

    Robert Larice - 2017-10-21

    A fix for the issue reported by An Zou is now on the master branch. The "short" and "narrow" parameters have been fixed too.

    Thank You for the bug report,

     
  • CHK

    CHK - 2017-12-24

    Hi, is this expected to be fixed in ngspice-27 official release?

    As i am just trying to change a resistor (i am using the ngspicelib) but it has no effect. Code see below:

        sprintf(command,"alter rpa = %g", Rpa);  // PA resistor
        ((int * (*)(char*)) ngSpice_Command_handle)(command);
    

    I am using the official released V-27:

    stdout ******
    stdout ** ngspice-27 shared library
    stdout ** Creation Date: Thu Dec 21 19:42:17 CET 2017
    stdout ******
    
     

    Last edit: CHK 2017-12-24
  • CHK

    CHK - 2017-12-24

    By the way i had this problem also since some years, the workaround i am using:
    Two serial connected voltage sources, one CCVS and a standard 0V source. The standard voltage source provides the current for the CCVS and the gain of the CCVS is the resistance. Changing the gain of a CCVS is working using "alter" command.

        sprintf(command,"alter h1 gain = %g", Rpa);  // use CCVS to adjust PA resistor
        ((int * (*)(char*)) ngSpice_Command_handle)(command);
    
     
  • Robert Larice

    Robert Larice - 2017-12-25

    CHK,
    this testcase:

    *
    * (compile "src/ngspice tmp.cir")
    v1 1 0 dc=1
    r1 1 0 2k
    
    .control
    op
    print i(v1) @r1[resistance]
    
    alter r1 1k
    op
    print i(v1) @r1[resistance]
    
    .endc
    

    prints :

    Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
    
    No. of Data Rows : 1
    i(v1) = -5.00000e-04
    @r1[resistance] = 2.000000e+03
    Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
    
    No. of Data Rows : 1
    i(v1) = -1.00000e-03
    @r1[resistance] = 1.000000e+03
    

    on the "official" ngspice-27 release.
    Thus altering a resistor seems to work.
    By the way I'm not aware of an unofficial ngspice-27.

     
    • Holger Vogt

      Holger Vogt - 2017-12-26

      Robert,

      if you resort to the test case given above by An Zou (see below), you will see the difference e.g. between ngspice-27 and the actual ngspice master. This is somewhat repeating the discussions and solution we have found above.

      ngspice-27 has this bug, the new release will have fixed it.

      The tip given by CHK may be useful in the meantime (but of course lacks TC and other enhancements).

      Holger

      test change_res, transient simulation
      
      VIN 100 0 DC 1
      
      * voltage divider
      r1 100 200 1
      r2 200 0 1
      
      * another voltage divider
      * resistor replacement for alter command
      h1 100 21 Vmeas 1
      Vmeas 21 20 0 
      r12 20 0 1
      
      .control
      stop when time = 0.5US
      run
      alter r1 = 2
      alter h1 gain = 2
      resume
      plot v(20) v(200) v(200)-v(20)
      .endc
      
      .tran 14PS 1US
      .END
      
       
  • Robert Larice

    Robert Larice - 2017-12-26

    Holger, CHK,

    the bug Holger is talking about, is fixed in commit:

    cffab98 * devices/res/resparam.c, bug fix, alter resistance not honoured when resuming a transient simulation

    which is on the "master" branch, and is after the ngspice-27 tag.
    Thus you need to checkout the "master" branch to have the fix.

    there was another related bug, which is fixed in commit:

    6172412 * res/restemp.c, bug fix, need to update RESresist' inREStemp()'

    which has been fixed a long time before ngspice-27
    your very short and incomplete example made me think you talk about the
    other one.

     

Log in to post a comment.