Could it be possible to incorporate the resistor current into the behavioral function? I am getting an error using the resistor current in the function.
The convention in SPICE simulators is that current can only be sensed in circuit elements that are modeled in Thévenin equivalent, specifically V-, L-, E-, or H- devices. SPICE simulators that allow sensed Resistor currents in behavior sources do so quasistaticly, meaning the current is off by one time step and convergence issues if used in a feedback with that behavioral source.
I might implement correct(not quasistatic) current sensing for behavioral sources at some time in the future, because it is possible to implement it correctly even though I’ve not seen it done yet.
Meanwhile, you can replace the sense resistor with a voltage source, give that source a series resistance of the sense resistor, and sense that in the behavioral source:
–Mike