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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
May I know if it is available to change the resistor value in transient simulation?
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
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
Where is that fix?
Holger
I've only a very dim remembrance of that.
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.
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
Yes it is too simplistic. a carefull investigation of
is wanted. In the second commit is a testcase which needs to be
extended as well.
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
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
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
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
--all for all branches, -G for a specific regexp to search for.
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
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,
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:
I am using the official released V-27:
Last edit: 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.
CHK,
this testcase:
prints :
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.
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
Holger, CHK,
the bug Holger is talking about, is fixed in commit:
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:
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.