------------------------------------------------------------------------------- -- Copyright (c) 2003 Mentor Graphics Corporation -- -- This model is a component of the Mentor Graphics VHDL-AMS educational open -- source model library, and is covered by this license agreement. This model, -- including any updates, modifications, revisions, copies, and documentation -- are copyrighted works of Mentor Graphics. USE OF THIS MODEL INDICATES YOUR -- COMPLETE AND UNCONDITIONAL ACCEPTANCE OF THE TERMS AND CONDITIONS SET FORTH -- IN THIS LICENSE AGREEMENT. Mentor Graphics grants you a non-exclusive -- license to use, reproduce, modify and distribute this model, provided that: -- (a) no fee or other consideration is charged for any distribution except -- compilations distributed in accordance with Section (d) of this license -- agreement; (b) the comment text embedded in this model is included verbatim -- in each copy of this model made or distributed by you, whether or not such -- version is modified; (c) any modified version must include a conspicuous -- notice that this model has been modified and the date of modification; and -- (d) any compilations sold by you that include this model must include a -- conspicuous notice that this model is available from Mentor Graphics in its -- original form at no charge. -- -- THIS MODEL IS LICENSED TO YOU "AS IS" AND WITH NO WARRANTIES, EXPRESS OR -- IMPLIED. MENTOR GRAPHICS SPECIFICALLY DISCLAIMS ALL IMPLIED WARRANTIES OF -- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. MENTOR GRAPHICS SHALL -- HAVE NO RESPONSIBILITY FOR ANY DAMAGES WHATSOEVER. ------------------------------------------------------------------------------- -- File : qPWL_src.vhd -- Author : Mentor Graphics -- Created : 2003-04-09 -- Last update: 2003-05-20 ------------------------------------------------------------------------------- -- Description: Piecewise linear real quantity source ------------------------------------------------------------------------------- -- Revisions : -- Date Version Author Description -- 2003-04-09 1.0 Mentor Graphics Created -- 2003-04-18 1.1 Mentor Graphics Added AC analysis code ------------------------------------------------------------------------------- library IEEE; use IEEE.math_real.all; -- The MGC_AMS library contains a "conversion" package that includes the -- time2real_vector conversion function along with the time_vector type -- definition (time_vector type is pending IEEE approval). -- The source file (mgc_ams_additions.vhd) is located in the SystemVision -- install tree. library MGC_AMS; use MGC_AMS.conversion.all; entity qPWL_src is generic ( -- default voltage and time data values qdata : real_vector := (0.0, 0.0, 10.0, 10.0, 5.0, 5.0, 0.0); timedata : time_vector := (0 ms, 1 ms, 1.1 ms, 2 ms, 2.1 ms, 3 ms, 3.1 ms); ac_mag : real := 1.0; -- AC magnitude ac_phase : real := 0.0); -- AC phase [Degrees] port ( quantity output : out real ); end entity qPWL_src; architecture ideal of qPWL_src is -- Declare quantity in frequency domain for AC analysis quantity ac_spec : real spectrum ac_mag, math_2_pi*ac_phase/360.0; -- Convert time_vector to real_vector for use in get_slope function constant n : integer := timedata'LENGTH; constant tdata : real_vector(0 to n-1) := time2real_vector(timedata); signal last_q : real := qdata(0); signal last_time : real := 0.0; signal m : real := 0.0; ------------------------------------------------------------------------------- -- function to progressively calculate slope from voltage and time -- data (both are real_vectors) function get_slope (tdata : in real_vector; qdata : in real_vector; count : in integer) return real is variable m : real; begin if count >= tdata'right then m := 0.0; else assert (tdata(count + 1) /= tdata(count)) report "get_slope: tdata vector has repeated values" severity error; m := (qdata(count + 1) - qdata(count))/(tdata(count + 1) - tdata(count)); end if; return m; end function get_slope; ------------------------------------------------------------------------------- begin -- process to keep track of current time and qantity pair to use in -- slope calculation time_slice : process is variable count : integer := 0; begin wait until domain = time_domain; while count < tdata'right loop m <= get_slope(tdata, qdata, count); -- send real_vectors to get_slope -- function last_q <= qdata(count); -- mark last quantity last_time <= tdata(count); -- mark last time point wait for (timedata(count + 1) - timedata(count)); -- time_vector req'd -- for wait statement count := count + 1; end loop; m <= 0.0; -- flat extrapolation beyond qdata, tdata range last_q <= qdata(qdata'right); -- don't need to assign last_time here as it's not used, since m = 0.0. wait; -- forever end process time_slice; break on last_q; -- force analog time step if domain = quiescent_domain or domain = time_domain use output == m*(NOW - last_time) + last_q; -- slope-intercept equation y=mx+b else output == ac_spec; -- used for Frequency (AC) analysis end use; end architecture ideal; ------------------------------------------------------------------------------- -- Copyright (c) 2003 Mentor Graphics Corporation -------------------------------------------------------------------------------