About Model Development in Verilog-A
About Model Development in Verilog-A
1. `include "disciplines.vams"
2. module R(p,n);
3. electrical p,n;
4. parameter real R=50.0;
5. analog V(p,n) <+ R * I(p,n);
6. endmodule
Line 1 instructs the compiler to insert the contents of the file disciplines.vams into the text. This file contains the definitions that make the Verilog-A specific
for electrical modeling.
Line 2 and line 6 declares the module block, within which the model behavior will be defined. The model is named R and has two ports, named "p" and "n".
Ports provide connections to other modules.
Line 3 declares that the ports p and n have the nature of those declared in the electrical discipline, as defined in the disciplines.vams header file. Natures and
disciplines provide a way to map the general flows and potentials to particular domains, like electrical, thermal, or mechanical.
Line 4 declares one parameter, called R, and assigns it a default value of 50.0. The default value is set if the simulator is not passed an assignment in the
netlist. In this case, the parameter is explicitly declared as real. However, if this attribute (which could also be integer ) is not provided, the language infers
the type from the default value. In this case, 50.0 would indicate a real type, whereas 50 would indicate an integer. The parameter declaration also
includes a simple method to restrict the range values. This is described in #Using Parameter Ranges to Restrict Verilog-A Parameter Values Parameter
values cannot be modified by the Verilog-A code. If the value needs to be modified, it should be assigned to an intermediate variable.
The keyword analog in line 5 declares the analog block. In this case, it is a single statement. However, statements can be grouped together using begin
/end keywords to denote blocks which, in turn, can be named to allow local declarations. The simple, single statement includes several key aspects of the
language. On the right hand side, the access function I(p,n) returns the current flowing from node p to n. This is multiplied by the value of the parameter R
. The "<+" in line 5 is called the contribution operator and in this example contributes the value of the evaluated right hand side expression as the voltage
from p to n.
whereas in the Verilog-A code, the value is used as `P_K . The temperature of the circuit is a value that can be changed outside of the model and so must
be dynamically accessed. Verilog-A models use system functions to retrieve information that the simulator can change. The temperature environment
parameter function is $temperature and returns the circuit's ambient temperature in Kelvin.
The actual contribution of the noise is made with the white_noise() operator, which takes the noise contribution as an argument. Noise functions also
allow for an optional string to label the noise contribution. Some simulators can sort the noise according to the labels.
1. `include "disciplines.vams"
2. `include "constants.vams"
3. module R(p,n);
4. electrical p,n;
5. parameter real R=50.0;
6. analog V(p,n) <+ R * I(p,n) + white_noise(4 * `P_K * $temperature / R, "thermal");
7. endmodule
Note that line 6 of the example code above shows the added noise.
I = C * dV / dt
In this case, the contribution is a current through the branch. The right hand side includes a derivative with respect to time. This is implemented with the dd
t() operator. The model then becomes,
This example also illustrates one use of the range functions in the parameter declaration. The " from [0:inf) " addition restricts the value of C from 0
up to, but not including, infinity.
Similarly, the inductor relationship is,
V = L * dI/dt
I = Is * (exp(V/Vth - Rs * I) - 1)
The more complicated behavior requires more complicated code. Comments are added to help clarify the source. Verilog-A supports two types of
comment characters. Text to the right of // and text between /* and */ blocks will be ignored.
The analog block is extended from a single line to multiple lines using the begin and end keywords to indicate a compound expression. Intermediate
variables are declared to make the code more readable. These variables are declared in the module but outside the analog block.
A new system function, $vt , is used. This function returns the thermal voltage calculated at an optional temperature. If no arguments are passed, the
ambient circuit temperature is used. The mathematical operators exp() and pow() are also used. Verilog-A includes a wide range of mathematical
functions.
By default, parameters can range from -infinity to infinity. To restrict a range either the exclusive from ( : ) can be used, or the inclusive from [ : ] or a
combination of the two. For example,
from (0 : 10]
will restrict the parameter from 0 to 10, excluding the value of 0 but including the value of 10.
except 5
If a simulator supports sweeping of parameters, the model developer will have to be aware of issues related to sweeping through ranges.
The mathematical constant for PI is available as M_PI from the constants.vams header file. Note that the multiple parameter declarations were combined on
one line as an alternative to declaring each on its own line.
The system function $bound_step() restricts the simulator's transient steps to the size 0.05/freq . This allows the model to define the resolution of the
signal to be controlled.
An additional use of defining sources in Verilog-A is to create test bench circuits as part of the model source file. This test module would provide sources
with appropriate values and sweep ranges to allow the validation of the model to be contained within the code definition. This is a useful method of
providing portable tests when distributing models among different simulators.
The Phase-Locked Loop (PLL) is a good example of a circuit that can be represented in behavioral blocks.
The Verilog-A source code below demonstrates a PLL circuit. The PLL consists of a phase detector, an amplifier, and a voltage controlled oscillator. In this
example, a swept sine source is used to test the circuit.
The modules use the keyword inout to declare that the ports are both input and output. Some simulators will check consistency of connection of ports
(useful when ports are declared input or output only). ADS will not.
The phaseDetector makes use of an analog function definition of chopper to simplify the code. Analog functions can be thought of a sub-routines that
can take many values but return one value. This is in contrast to macros, which should be thought of as in-line text substitutions.
The modules are connected in a circuit (using appropriate AEL and symbol definitions) and a transient simulation is run.
To use a hierarchy, the model developer creates textual definitions of individual modules in the usual fashion. Each module definition is independent, that
is, the definitions can not be nested. Special statements within the module definitions instantiate copies of the other modules. Parameter values can be
passed or modified by the hierarchical modules, providing a way to customize the behavior of instantiated modules.
For example, the previous definitions of R, L, and C can be used with a new module called RLC to create a simple filter.
The RLC module creates a series R-L-C from the input port in to the output port out , using two internal nodes, n1 and n2. The RLC module's parameter
values of RR, LL, and CC are passed to the modules R, L, and C's parameters R, L, and C via #(.R(RR)), #(.L(LL)), and #(.C(CC)).
A unique advantage of the Compiled Model Library file is that the Verilog-A source is effectively hidden from end users. This, coupled with Verilog-A's
hierarchical structure, gives model developers a simple way to distribute intellectual property without exposing proprietary information.