// This is -*- Verilog-A -*-

// ============================================================================
//
// (c) Copyright 2005, All Rights Reserved, Philips Electronics N.V.
//
//
// Version: August 22, 2005
//
// ============================================================================

// Spice primitives
// Verilog-AMS LRM 2.0 Annex E "SPICE compatibility"

`include "disciplines.vams"
`include "constants.vams"

`ifdef RESISTOR_VA
`else
`define RESISTOR_VA 1

`ifdef TNOM
`else
`define TNOM 25
`endif

/**
 * @brief linear resistor with 2nd order temperature dependency.
 *
 * A linear resistor is defined by the constituent relationship V = I*R,
 * also known as Ohm's law. For Verilog-A implementation the current
 * related version (I = V/R) is used as that is more efficient in most
 * simulators using a modified nodal analysis structure in their matrices.
 *
 * The temperature dependency of the resistor is determined before applying
 * Ohm's law.
 *
 * If the temperature-corrected resistance is 0, the resistor resolves to a
 * short.
 *
 * @param r		resistance in [Ohm].
 * @param tc1		first order temperature coefficient in [Ohm/K].
 * @param tc2		second order temperature coefficient in [Ohm/K^2].
 */

module Resistor (p, n);
inout p, n;
electrical p, n;
parameter r = 1k;
parameter tc1 = 0.0;
parameter tc2 = 0.0;

real rt, dta, tnom;

analog begin

  @(initial_step) begin
    tnom = `P_CELSIUS0 + `TNOM;
  end

  dta = $temperature - tnom;
  rt = r * (1 + tc1 * dta + tc2 * dta * dta);

  if (rt != 0)
    I(p, n) <+ V(p, n) / rt;
  else
    V(p, n) <+ 0;

end

endmodule // Resistor

`endif
