-- Copyright Mentor Graphics Corporation 2001 -- Confidential Information Provided Under License Agreement for Internal Use Only -- Analog to Digital Converter (Successive Aproximation Register) model with sar architecture (a2d_nbit.vhd) --DESCRIPTION: -- --This is a VHDL-AMS model of a simple analog to digital converter. The model --describes the general behavior of A/D converters for system level design and --verification. --The format of the digital output is binary coding. -- --N.B, dout(n-1) is the MSB while dout(0) is the LSB. -- -- Use IEEE natures and packages library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.electrical_systems.all; entity a2d_nbit is generic ( Vmax: REAL := 4.8 ; -- ADC's maximum range Nbits: INTEGER := 10 ; -- number bits in ADC's output delay: TIME := 10 us -- ADC's conversion time ); port ( signal start: in std_logic ; -- Start signal signal clk: in std_logic ; -- Strobe clock signal oe: in std_logic ; -- Output enable terminal ain: ELECTRICAL ; -- ADC's analog input terminal signal eoc: out std_logic := '0' ; -- End Of Conversion pin signal dout: out std_logic_vector(0 to (Nbits-1))); -- ADC's digital output signal end entity a2d_nbit; architecture sar of a2d_nbit is type states is (input, convert, output) ; -- Three states of A2D Conversion constant bit_range : INTEGER := Nbits-1 ; -- Bit range for dtmp and dout quantity Vin across Iin through ain to electrical_ref; -- ADC's input branch begin sa_adc: process variable thresh: REAL := Vmax ; -- Threshold to test input voltage against variable Vtmp: REAL; -- Snapshot of input voltage when conversion starts variable dtmp: std_logic_vector(0 to (Nbits-1)); -- Temp. output data variable status: states := input ; -- Begin with "input" CASE variable bit_cnt: integer := Nbits -1 ; begin CASE status is when input => -- Read input voltages when start goes high wait on start until start = '1' or start = 'H' ; thresh := Vmax ; Vtmp := Vin ; eoc <= '0' ; status := convert ; -- Go to convert state when convert => -- Begin successive approximation conversion thresh := thresh / 2.0 ; -- Get value of MSB wait on clk until clk = '1' OR clk = 'H'; if Vtmp > thresh then dtmp(bit_cnt) := '1' ; Vtmp := Vtmp - thresh ; else dtmp(bit_cnt) := '0' ; end if ; if bit_cnt < 1 then status := output ; -- Go to output state end if; bit_cnt := bit_cnt - 1 ; when output => -- Wait for output enable, then put data on output pins eoc <= '1' after delay ; wait on oe until oe = '1' OR oe = 'H' ; dout <= dtmp ; wait on oe until oe = '0' OR oe = 'L' ; -- Hi Z when OE is low dout <= (others => 'Z') ; bit_cnt := bit_range ; status := input ; -- Set up for next conversion END CASE ; end process sa_adc ; Iin == 0.0 ; -- Ideal input draws no current end architecture sar ;