In addition to Eugene's points about cross, there is something rather suspect about the logic in your code.
In order to change the value of "res", the current flowing through the resistor has to be between 3.6mA and 4.4mA.
However, you have an if out the resistor itself, which means that it has a constant value resistor unless the current is between 1mA and 3mA. You're going to have all sorts of discontinuous (and rather strange) behaviour at the very least.
For debugging, I removed the final if, and put a $debug statement in to look at the values - see below. I'm sure that if you do this and think carefully about what you're doing you can get it to do what you want (whatever that might be!).
Code:`include "constants.h"
`include "discipline.h"
module spinres2(inp,inn,outp,outn);
inout inp,inn,outp,outn;
electrical inp,inn,outp,outn;
real res;
real res_1 ;
real res_0 ;
parameter real cellres = 80 from (1:inf);
parameter real GMR_change = 3 from (1:inf);
analog begin
res_1 = cellres + ((GMR_change/100) * (cellres));
res_0 = cellres - ((GMR_change/100) * (cellres));
begin
@(cross ((I(inp,inn)-27m))) begin
if ((I(outp,outn) >= 3.6m) && (I(outp,outn) <= 4.4m))
res = res_1;
else res = res;
end
@(cross ((I(inn,inp)-27m))) begin
if ((I(outp,outn) >= 3.6m) && (I(outp,outn) <= 4.4m))
res = res_0;
else res = res;
end
end
$debug("res is %g, I(inp,inn) is %g,res_1 is %g, res_0 is %g\n",res,I(inp,inn),res_1, res_0);
// if ((I(inp,inn) <= -13.5m) && (I(inp,inn) >= -16.5m) && (I(outp,outn) >= 1m) && (I(outp,outn) <= 3m))
V(outp,outn) <+ res*I(outp,outn);
// else V(outp,outn) <+ cellres * I(outp,outn);
end
endmodule
By the way, here's the little netlist I used for testing the above:
Code://
r1 (1 0 2 0) spinres2
i2 (2 0) isource dc=-4m
i1 (1 0) isource type=sine ampl=30m freq=1M
ahdl_include "desguide.va"
tran tran stop=1u
Regards,
Andrew.