The condition must be voltage independent.
I agree that localparam could be used to handle some conditions:
localparam do_rd = (TNOIMOD != 0 || RDSMOD != 0
|| ($param_given(NRD) && NRD > 0 && RSH > 0)
|| (!$param_given(NRD) && RGEOMOD != 0) );
(I would hope that compilers accept $param_given(nrd) in the
localparam expression.)
I don't know about the RGEOMOD equations, and whether it's
reasonable to require them to return a non-zero value when
RGEOMOD != 0.
I don't understand your concern about error reporting. I'd want the
error message to cite the line of the if() statement, and the only
difference I see between our two proposals is in the text of the message:
*ERROR*, line 999: switch branch depends on bias-dependent variable
versus
*ERROR*, line 999: switch branch depends on variable (not parameter)
I wouldn't read too much into this -- it was actually the IEEE 1364
(digital) Verilog people who added localparam to the language.
In (digital) Verilog, parameters (and hence localparams) are constants
set at elaboration time, and there is no concept of a "dc sweep" --
parameters cannot be changed during a simulation at all!
-Geoffrey
I'm not convinced that this is sufficient an argument for imposing
the burden on all model writers, that they conform their style to
using localparam.
Are all simulators able to accept the syntax below? (Note the use
of $param_given, $temperature, and $simparam in the localparam lines.)
(I found one commercial simulator that did not like $param_given
in the default expression.)
I suspect we have come to a place where we need to take a
straw poll.
I'm also interested to know if there are any other issues we
should be considering. It's not much of a "set of recommendations"
if we have only one thing to say, on switch branches.
-Geoffrey
module resform(a,b);
inout a, b;
electrical a, b;
parameter real rsh = 0 from [0:inf);
parameter real nsq = 0 from [0:inf);
parameter real value = 0 from [0:inf);
localparam real r = ($param_given(nsq) && rsh > 0) ? nsq * rsh : value;
localparam rtemp = r * (1 + 0.1 * $temperature);
localparam reff = (rtemp > $simparam("minr", 1m)) ? rtemp : 0;
analog begin
if( reff > 0) begin
I(a,b) <+ V(a,b) * reff;
I(a,b) <+ white_noise(4.0*`P_K*$temperature * reff, "thermal");
end else
V(a,b) <+ 0;
end
endmodule