The Btrend's saying is right.The fellow is my ideal 10bit DAC with Verilog-A language.
`include "discipline.h"
`include "constants.h"
`define NUM_DAC_BITS 10
module d2a_ideal_1 (clk, din, vout);
input [`NUM_DAC_BITS-1:0] din;
voltage [`NUM_DAC_BITS-1:0] din;
input clk;
voltage clk;
output vout;
voltage vout;
parameter real vmax = 5;
parameter real vmin = 0;
parameter real vth = 1.25;
parameter real trise = 4.0p from (0:inf);
parameter real tfall = 4.0p from (0:inf);
parameter real tconv = 2.0p from [0:inf);
parameter real slack = 10.0p from (0:inf);
parameter integer traceflag = 0;
real lsb, voffset, new_vout;
integer decimal_value;
analog begin
@(initial_step or initial_step("dc","ac","tran","xf")) begin
if (vmin < 0.0 ) voffset = vmin; else voffset = 0.0;
decimal_value = 0;
lsb = (vmax - vmin) / (1 << `NUM_DAC_BITS) ;
if (traceflag) begin
$display("%M DAC range ( %g v ) / %d bits = lsb %g volts.\n",
vmax - vmin, `NUM_DAC_BITS, lsb );
$display(" offset %g volts.\n", voffset );
end
end
@(cross ( V(clk)-vth, 1, slack, clk.potential.abstol)) begin
decimal_value=0;
generate i (`NUM_DAC_BITS-1, 0) begin
decimal_value = decimal_value + (( V(din) > vth ) ? 1 << i : 0 );
end
new_vout = decimal_value * lsb + voffset;
if(traceflag)
$strobe("%M at %g sec. digital in: %d vout: %g",
$realtime, decimal_value, (decimal_value * lsb) + voffset );
end
V(vout) <+ transition ( new_vout, tconv, trise, tfall );
end
endmodule
`undef NUM_DAC_BITS