//------------------------------------------------------------------------------
// Name   : adcflash_ref_ladder
// View   : verilogams
// Purpose: Model the reference ladder portion of an AD converter
// Author : Cadence Design Foundry
// Date   : March 2003
// Copyright: Cadence Design Systems
//
//------------------------------------------------------------------------------
`include "constants.vams"
`include "disciplines.vams"

module adcflash_ref_ladder ( ref0, ref1, ref2, ref3, ref4, ref5, ref6, ref7,
    ref8, ref9, ref10, INM, INP, SIDDQ, VDD, VSS, ibias50 );

output ref0, ref1, ref2, ref3, ref4, ref5;	// Ladder Reference Outputs
output ref6, ref7, ref8, ref9, ref10;		// Ladder Reference Outputs

input	INP, INM;				// Sampled Voltage
input	VDD, VSS;				// Power & Ground
input	ibias50;				// Reference Current
input	SIDDQ;					// IDDQ Test Signal

electrical ref0, ref1, ref2, ref3, ref4, ref5;	// Ladder Reference Outputs
electrical ref6, ref7, ref8, ref9, ref10;	// Ladder Reference Outputs
electrical INP, INM;
electrical VDD, VSS;
electrical ibias50;

logic	SIDDQ;

parameter voffset  = 0.0;			// Default Voltage offset
parameter r_ladder = 1000;			// Values of R (ohms) in ladder
parameter vcm      = 1.365;			// common mode voltage

// Create Internal Nodes
real	vin;					// Input Voltage
real	vref5;					// Reference ladder mid-point
real	Iref;					// Current reference

analog begin
	@(initial_step) vref5 = vcm;
	if (SIDDQ) begin			// Ground the reference ladder
		Iref  = 0.0;
		vref5 = 0.0;
	end
	else begin
	  vin	= (V(INP)+V(INM))/2.0;		// Input to Opamp
	  vref5 = vin + voffset;		// Input Reference to Opamp
	  Iref  = I(ref10);			// Reference Current
	end
	
	V(ref10) <+ vref5 + 5*r_ladder*Iref;	// Ladder top top
	V(ref9)  <+ vref5 + 4*r_ladder*Iref;	// Ladder reference
	V(ref8)  <+ vref5 + 3*r_ladder*Iref;    // Ladder reference
	V(ref7)  <+ vref5 + 2*r_ladder*Iref;    // Ladder reference
	V(ref6)  <+ vref5 + 1*r_ladder*Iref;    // Ladder reference
	V(ref5)  <+ vref5;			// Ladder reference
	V(ref4)  <+ vref5 - 1*r_ladder*Iref;    // Ladder reference
	V(ref3)  <+ vref5 - 2*r_ladder*Iref;    // Ladder reference
	V(ref2)  <+ vref5 - 3*r_ladder*Iref;    // Ladder reference
	V(ref1)  <+ vref5 - 4*r_ladder*Iref;    // Ladder reference
	V(ref0)  <+ vref5 - 5*r_ladder*Iref;    // Ladder bottom tap
end
endmodule
