A Resistor

In this example we define a simple resistor. A resistor is a device whose current is proportional to the voltage difference between its terminals. This is defined in Verilog-A using a branch contribution as follows:

I(p,n) <+ V(p,n)/resistance ;

This defines the current/voltage relationship that the simulator must maintain on the nodes p and n. I(p,n) represents the current flowing from port p to port n and V(p,n) represents the potential difference measured between nodes p and n.

Here is the full definition:

'include "disciplines.vams"

(* symbol="res" *)module va_resistor(p,n) ;

parameter real resistance = 1000.0 from (0.0:inf] ;
electrical p, n ;

analog
I(p,n) <+ V(p,n)/resistance ;

endmodule

In the above the resistance parameter has been given value range limits to prevent resistance value of zero or below. A resistance of zero would lead to a divide-by-zero error.

Instead of blocking resistors with a value of zero, we could instead implement a zero resistance using a zero voltage contribution. This is how:

'include "disciplines.vams"

(* symbol="res" *)module va_resistor(p,n) ;

parameter real resistance = 1000.0 ;
electrical p, n ;

analog
begin
if (resistance!=0.0)
I(p,n) <+ V(p,n)/resistance ;
else
V(p,n) <+ 0.0 ;
end

endmodule

Note the conditional statement starting if (resistance!=0.0). Notice also, that the analog block is now enclosed with the keywords begin and end. These are not actually necessary in this case, but are necessary where there is more than one statement in the analog block.

Finally the module statement is prefixed with the text:

(* symbol="res" *)

This is known as an attribute. Verilog-A attributes are name-value pairs that can be specific to an implementation. The symbol attribute is specific to SIMetrix and defines the library symbol to be used with the module. "res" is the symbol for a box-shape resistor. If you prefer a z-shaped resistor, you can change this to "resz". For more information see Specify Library Symbol. When you select the menu Verilog-A > Construct Verilog-A Symbol, the resistor symbol will be offered instead of the generic auto-generated symbol.