⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 altera_mf.vhd

📁 The GRLIB IP Library is an integrated set of reusable IP cores, designed for system-on-chip (SOC) de
💻 VHD
📖 第 1 页 / 共 5 页
字号:
    if (m4 < t6) then m5 := m4; else m5 := t6; end if;    if (m5 < t7) then m6 := m5; else m6 := t7; end if;    if (m6 < t8) then m7 := m6; else m7 := t8; end if;    if (m7 < t9) then m8 := m7; else m8 := t9; end if;    if (m8 < t10) then m9 := m8; else m9 := t10; end if;    if (m9 < 0) then return (0 - m9); else return 0; end if;end;-- adjust the phase (tap_phase) with the largest negative number (ph_base)function ph_adjust (tap_phase: integer; ph_base : integer) return integer isbegin    return (tap_phase + ph_base);end;-- find the time delay for each PLL counterfunction counter_time_delay (clk_time_delay: integer;                             m_time_delay: integer; n_time_delay: integer)         return integer isvariable R: integer := 0;begin    R := clk_time_delay + m_time_delay - n_time_delay;    return R;end;-- calculate the given phase shift (in ps) in terms of degreesfunction get_phase_degree (phase_shift: integer; clk_period: integer)         return integer isvariable result: integer := 0;begin    result := ( phase_shift * 360 ) / clk_period;    -- to round up the calculation result    if (result > 0) then        result := result + 1;    elsif (result < 0) then        result := result - 1;    else        result := 0;    end if;    return result;end;-- find the number of VCO clock cycles to wait initially before the first rising-- edge of the output clockfunction counter_initial (tap_phase: integer; m: integer; n: integer)                         return integer isvariable R: integer;variable R1: real;begin        R1 := (real(abs(tap_phase)) * real(m))/(360.0 * real(n)) + 0.5;        -- Note NCSim VHDL had problem in rounding up for 0.5 - 0.99.         -- This checking will ensure that the rounding up is done.        if (R1 >= 0.5) and (R1 <= 1.0) then           R1 := 1.0;        end if;        R := integer(R1);        return R;end;-- find which VCO phase tap (0 to 7) to align the rising edge of the output clock tofunction counter_ph (tap_phase: integer; m: integer; n: integer) return integer isvariable R: integer := 0;begin    -- 0.5 is added for proper rounding of the tap_phase.    R := (integer(real(tap_phase * m / n)+ 0.5) REM 360)/45;    return R;end;-- convert given string to length 6 by padding with spacesfunction translate_string (mode : string) return string isvariable new_mode : string (1 to 6) := "      ";begin    if (mode = "bypass") then        new_mode := "bypass";    elsif (mode = "even") then        new_mode := "  even";    elsif (mode = "odd") then        new_mode := "   odd";    end if;    return new_mode;end;-- convert integer to stringfunction int2str( value : integer ) return string isvariable ivalue : integer := 0;variable index : integer := 1;variable digit : integer := 0;variable temp: string(10 downto 1) := "0000000000";begin    ivalue := value;    index := 1;    while (ivalue > 0) loop        digit := ivalue mod 10;        ivalue := ivalue/10;        case digit is            when 0 =>    temp(index) := '0';            when 1 =>    temp(index) := '1';            when 2 =>    temp(index) := '2';            when 3 =>    temp(index) := '3';            when 4 =>    temp(index) := '4';            when 5 =>    temp(index) := '5';            when 6 =>    temp(index) := '6';            when 7 =>    temp(index) := '7';            when 8 =>    temp(index) := '8';            when 9 =>    temp(index) := '9';            when others => ASSERT FALSE                           REPORT "Illegal number!"                           SEVERITY ERROR;        end case;        index := index + 1;    end loop;    if (value < 0) then        return ('-'& temp(index downto 1));    else        return temp(index downto 1);    end if;end int2str;-- convert string to integerfunction str2int (s : string) return integer isvariable len : integer := s'length;variable newdigit : integer := 0;variable sign : integer := 1;variable digit : integer := 0;begin    for i in 1 to len loop        case s(i) is            when '-' =>                if i = 1 then                    sign := -1;                else                    ASSERT FALSE                    REPORT "Illegal Character "&  s(i) & "i n string parameter! "                    SEVERITY ERROR;                end if;             when '0' => digit := 0;             when '1' => digit := 1;             when '2' => digit := 2;             when '3' => digit := 3;             when '4' => digit := 4;             when '5' => digit := 5;             when '6' => digit := 6;             when '7' => digit := 7;             when '8' => digit := 8;             when '9' => digit := 9;             when others =>                 ASSERT FALSE                 REPORT "Illegal Character "&  s(i) & "in string parameter! "                 SEVERITY ERROR;        end case;        newdigit := newdigit * 10 + digit;    end loop;    return (sign*newdigit);end;end pllpack;-- END OF PACKAGE pllpacklibrary ieee;use ieee.std_logic_1164.all;-- DFFPentity DFFP isport(    CLK : in std_logic;    ENA : in std_logic := '1';    D : in std_logic;    CLRN : in std_logic := '1';    PRN : in std_logic := '1';    Q : out std_logic);end DFFP;architecture behave of DFFP isbeginprocess (CLK, PRN, CLRN)    begin        if (PRN = '0') then Q <= '1';        elsif (CLRN = '0') then Q <= '0';        elsif (CLK'event and (ENA = '1')) then Q <= D;        end if;    end process;end behave;--///////////////////////////////////////////////////////////////////////////---- Entity Name : MF_mn_cntr---- Description : Simulation model for the M and N counter. This is a--               common model for the input counter and the loop feedback--               counter of the Stratix PLL and Stratix II PLL.----///////////////////////////////////////////////////////////////////////////library ieee;use IEEE.std_logic_1164.all;entity MF_mn_cntr isport (    clk           : IN std_logic;    reset         : IN std_logic := '0';    cout          : OUT std_logic;    initial_value : IN integer := 1;    modulus       : IN integer := 1;    time_delay    : IN integer := 0;    ph            : IN integer := 0);end MF_mn_cntr;architecture behave of MF_mn_cntr isbegin    process (clk, reset)    variable count : integer := 1;    variable first_rising_edge : boolean := true;    variable tmp_cout : std_logic;    begin        if (reset = '1') then            count := 1;            tmp_cout := '0';            first_rising_edge := true;        elsif (clk'event and clk = '1' and first_rising_edge) then            first_rising_edge := false;            tmp_cout := clk;        elsif (not first_rising_edge) then            if (count < modulus) then                count := count + 1;            else                count := 1;                tmp_cout := not tmp_cout;            end if;        end if;        cout <= transport tmp_cout after time_delay * 1 ps;    end process;end behave;--/////////////////////////////////////////////////////////////////////////////---- Entity Name : stx_scale_cntr---- Description : Simulation model for the output scale-down counters.--               This is a common model for the L0, L1, G0, G1, G2, G3, E0,--               E1, E2 and E3 output counters of the Stratix PLL.----/////////////////////////////////////////////////////////////////////////////library ieee;use IEEE.std_logic_1164.all;entity stx_scale_cntr isport (    clk            : IN std_logic;    reset          : IN std_logic := '0';    initial        : IN integer := 1;    high           : IN integer := 1;    low            : IN integer := 1;    mode           : IN string := "bypass";    time_delay     : IN integer := 0;    ph_tap         : IN natural := 0;    cout           : OUT std_logic);end stx_scale_cntr;architecture behave of stx_scale_cntr isbegin    process (clk, reset)    variable tmp_cout : std_logic := '0';    variable count : integer := 1;    variable output_shift_count : integer := 0;    variable first_rising_edge : boolean := false;    variable high_reg : integer := 0;    variable low_reg : integer := 0;    variable init : boolean := true;    begin        if (reset = '1') then            count := 1;            output_shift_count := 0;            tmp_cout := '0';            first_rising_edge := false;        elsif (clk'event) then            if (init) then                init := false;                high_reg := high;                low_reg := low;            end if;            if (mode = "   off") then                tmp_cout := '0';            elsif (mode = "bypass") then                tmp_cout := clk;            elsif (not first_rising_edge) then                if (clk = '1') then                    output_shift_count := output_shift_count + 1;                    if (output_shift_count = initial) then                        tmp_cout := clk;                        first_rising_edge := true;                    end if;                end if;            elsif (output_shift_count < initial) then                if (clk = '1') then                    output_shift_count := output_shift_count + 1;                end if;            else                count := count + 1;                if (mode = "  even" and (count = (high_reg*2) + 1)) then                    tmp_cout := '0';                    low_reg := low;                elsif (mode = "   odd" and (count = high_reg*2)) then                    tmp_cout := '0';                    low_reg := low;                elsif (count = (high_reg + low_reg)*2 + 1) then                    tmp_cout := '1';                    count := 1;  -- reset count                    high_reg := high;                end if;            end if;        end if;        cout <= transport tmp_cout after time_delay * 1 ps;    end process;end behave;--/////////////////////////////////////////////////////////////////////////////---- Entity Name : arm_scale_cntr---- Description : Simulation model for the output scale-down counters.--               This is a common model for the C0, C1, C2, C3, C4 and C5--               output counters of the Stratix II PLL.----/////////////////////////////////////////////////////////////////////////////library ieee;use IEEE.std_logic_1164.all;entity arm_scale_cntr is    port ( clk            : IN std_logic;           reset          : IN std_logic := '0';           initial        : IN integer := 1;           high           : IN integer := 1;           low            : IN integer := 1;           mode           : IN string := "bypass";           ph_tap         : IN integer := 0;           cout           : OUT std_logic         );end arm_scale_cntr;architecture behave of arm_scale_cntr isbegin    process (clk, reset)    variable tmp_cout : std_logic := '0';    variable count : integer := 1;    variable output_shift_count : integer := 1;    variable first_rising_edge : boolean := false;    begin        if (reset = '1') then            count := 1;            output_shift_count := 1;            tmp_cout := '0';            first_rising_edge := false;        elsif (clk'event) then            if (mode = "   off") then                tmp_cout := '0';            elsif (mode = "bypass") then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -