`include "discipline.h"
`include "constants.h"
// $Date: 1997/08/28 05:54:32 $
// $Revision: 1.1 $
//
//
// Based on the OVI Verilog-A Language Reference Manual, version 1.0 1996
//
//
//--------------------
// ADC_12_bit
//
// - Ideal 12 bit analog to digital converter
//
// vin: [V,A]
// vclk: [V,A]
// vd0..vd11: data output terminals [V,A]
//
// INSTANCE parameters
// tdel, trise, tfall = {usual}
// vlogic_high = [V]
// vlogic_low = [V]
// vtrans_clk = clk high to low transition voltage [V]
// vref = voltage that voltage is done with respect to [V]
//
// MODEL parameters
// {none}
//
// This model is ideal in the sense that there is no mismatch modeled.
//
module ADC_12_bit(vd11, vd10, vd9, vd8, vd7, vd6, vd5, vd4, vd3, vd2, vd1, vd0, vin, vclk);
electrical vd11, vd10, vd9, vd8, vd7, vd6, vd5, vd4, vd3, vd2, vd1, vd0, vin, vclk;
parameter real trise = 0 from [0:inf);
parameter real tfall = 0 from [0:inf);
parameter real tdel = 0 from [0:inf);
parameter real vlogic_high = 5;
parameter real vlogic_low = 0;
parameter real vtrans_clk = 2.5;
parameter real vref = 5.0;
`define NUM_ADC_BITS 12
real unconverted;
real halfref;
real vd[0:`NUM_ADC_BITS-1];
integer i;
analog begin
@ ( initial_step ) begin
halfref = vref / 2;
end
@ (cross(V(vclk) - vtrans_clk, 1)) begin
unconverted = V(vin);
for (i = (`NUM_ADC_BITS-1); i >= 0 ; i = i - 1) begin
vd = 0;
if (unconverted > halfref) begin
vd = vlogic_high;
unconverted = unconverted - halfref;
end else begin
vd = vlogic_low;
end
unconverted = unconverted * 2;
end
end
//
// assign the outputs
//
V(vd11) <+ transition( vd[11], tdel, trise, tfall );
V(vd10) <+ transition( vd[10], tdel, trise, tfall );
V(vd9) <+ transition( vd[9], tdel, trise, tfall );
V(vd8) <+ transition( vd[8], tdel, trise, tfall );
V(vd7) <+ transition( vd[7], tdel, trise, tfall );
V(vd6) <+ transition( vd[6], tdel, trise, tfall );
V(vd5) <+ transition( vd[5], tdel, trise, tfall );
V(vd4) <+ transition( vd[4], tdel, trise, tfall );
V(vd3) <+ transition( vd[3], tdel, trise, tfall );
V(vd2) <+ transition( vd[2], tdel, trise, tfall );
V(vd1) <+ transition( vd[1], tdel, trise, tfall );
V(vd0) <+ transition( vd[0], tdel, trise, tfall );
`undef NUM_ADC_BITS
end
endmodule