You can use the Verilog-AMS $table_model function known from analog Verilog-A , Verilog-AMS blocks and digital context (such as in an initial or an always block) with wreal independent variables.
The following is an example illustrating how to use the $table_model function and the different options to the function.
`include "disciplines.vams"`timescale 1ns / 1ps
module top(); wreal s, vdd; logic out; real r; vco f1 (out, vdd, s);
initial begin #10 r = 1.234; #10 r = 5; #10 r = 0.45; #10 r = 23; #10 r = 4.2; #1 $stop; end assign s = r; assign vdd = 1.1;
endmodule
module vco(out, vdd, vctrl); output out; logic out; input vdd, vctrl; wreal vdd, vctrl; reg osc = 1'b0; real tableFreq, halfper;
always @(vdd, vctrl) begin tableFreq = $table_model(vdd, vctrl,"./vcoFreq.tbl", "3CC,1EL"); halfper = 1/(2*tableFreq); end
always begin #halfper osc = !osc; end
assign out = osc;endmodule
The example above calculates the VCO output frequency according to the table in the text file vcoFrep.tbl. This file is shown below:
#VDD VCNTL Freq/GHz1 0 9.811 0.4 1.051 0.8 1.411.1 0 9.881.1 0.45 1.291.1 0.9 1.521.2 0 9.951.2 0.5 1.371.2 1 1.69
Assuming that the VDD=1.1 and VCNTRL=0.45, the output frequency would be 1.29 GHz. For values between the definition points (for example, VCNTRL=0.687), a linear or third-order spline interpolation is used.
Also, you can use the $table_model function to model the behavior of a design by interpolating between and extrapolating outside of data points. The syntax of the table model file, as shown in the example below, is identical to the $table_model function
The following example uses the control string ""3CC,1EL"", which specifies a 3rd order spline interpolation of the vdd variable, while the vctrl variable entries in the table are interpolated in a linear method. Input values for vdd below 1.0 or above 1.2 are clamped to 1.0 and 1.2 respectively. Input values below 0.0 for vctrl results in an error, while larger value than 1.0 is extrapolated linearly.
table_model_declaration ::= $table_model(variables , table_source [ , ctrl_string ] )
sub_ctrl_string ::= I | D | [ degree_char ] [ extrap_char [ extrap_char ]]
degree_char ::= 1 | 2 | 3
extrap_char ::= C | L | S | E
where:
ctrl_string: Controls the numerical aspects of the interpolation process. It consists of sub-control strings for each dimension.I(ignore): Ignores the corresponding dimension (column) in the data file. You might use this setting to skip over-index numbers. For example, when you associate the I (ignore) value with a dimension, you must not specify a corresponding variable for that dimension.D(discrete): Ignore interpolation for this dimension. If the software cannot find the exact value for the dimension in the corresponding dimension in the data file, it issues an error message and the simulation stops.degree_char: Specifies the degree of the splines used for interpolation. Important values for the degree are 1 and 3. The default value is 1, which results in a linear interpolation between data points. 3 specifies a 3rd order spline interpolation.extrap_char: Controls how the simulator evaluates a point that is outside the region of sample points included in the data file. You can specify the extrapolation method to be used for each end of the sample point region.C(clamp): Uses a horizontal line that passes through the nearest sample point, also called the end point, to extend the model evaluation.L(linear): Models the extrapolation through a tangent line at the end point. This is the default method,S(spline): Uses the polynomial for the nearest segment (the segment at the end) to evaluate a point beyond the interpolation area.E(error): Issues a warning when the point to be evaluated is beyond the interpolation area.
When you do not specify anextrap_charvalue, the linear extrapolation method is used for both ends. When you specify only oneextrap_charvalue, the specified extrapolation method is used for both ends. When you specify twoextrap_charvalues, the first character specifies the extrapolation method for the end with the smaller coordinate value, and the second character specifies the method for the end with the larger coordinate value.
Related Topics:
- The "Interpolating with Table Models" section in the Cadence Verilog-AMS Language Reference guide
