You can use the Verilog-AMS function in the analog context (in an analog block) and in the digital context (such as in an initial or an always block) with wreal independent variables.
Using the $table_model function in your functional and timing simulation, you can replace transistor circuitry with a table model, where the table model operates on real number sweep data that you measure. For example, consider the following Verilog-AMS module, which measures input and output voltage values and saves the data into an ASCII text file as a two-dimensional table that we can reuse in a $table_model function:
`include "disciplines.vams"
`timescale 1ns/100ps
module probe2table ( a, b, clk );
input a, b, clk;
electrical a, b;
parameter lsb=1u;
real previous_b_value=0;
integer fptr;
integer index=1;
initial begin
fptr = $fopen("table2d.dat", "w");
if( !fptr ) $stop;
$display(" >> Open the file for writing" );
previous_b_value = V(b);
end
always @( posedge(clk)) begin
if (V(b) - previous_b_value > lsb ) begin
$fwrite(fptr, "%d %1.9f %1.9f\n", index, V(a), V(b) );
$display(">> Write the data t=%-6d ns V(a)=%1.9f V(b)=%1.9f ",$time,V(a),V(b));
previous_b_value = V(b);
index = index +1;
end
end
endmodule
You can reuse the table model in the resulting table2d.dat file in a $table_model function that has a wreal as the independent variable as follows:
`define TABLE_FILE_NAME "table2d.dat" `timescale 1ns / 100ps module inv_table ( a, y ); output y; wreal y; parameter real td=10p; input a; wreal a; real y_reg; real delay_ns= td / 1.0e9; initial begin y_reg =$table_model(a,`TABLE_FILE_NAME,"I,1L"); end always @(a) begin #delay_ns y_reg =$table_model(a,`TABLE_FILE_NAME,"I,1L"); end assign y = y_reg; endmodule
In the initial and always blocks, you assign the interpolated data to a real variable, y_reg. The value of the td (real) parameter--which represents the propagation delay of an inverter gate--determines when to assign the value of y_reg to the wreal output value, y.
The software interpolates and extrapolates, using the control string you specify, to estimate each value from the known set of values. The first part of the control string (in this case, I) controls the numerical aspects of the interpolation process. For this example, the I causes the software to ignore the corresponding dimension (column) in the data file. The number (1) is the degree of the interpolation splines. The last part of the control string (in this case, L) specifies the extrapolation method: how the simulator evaluates a point that is outside the region of sample points included in the data file. The letter L indicates linear extrapolation.
You can use an environment variable to specify the location of the table file in the $table_model function in digital context (such as initial or always block). For example:
initial begin
out1 = $table_model(wb,"$WORKAREA/$FILENAME", "");
end
In addition, you can use real array as a table model data source in a digital block. For example:
real tvar1[0:50];
real ftyp[0:50];
always @ (en) begin
test_out_real = $table_model(w_t_in , tvar1, ftyp,"3CC");
end
