| 1 | --
|
|---|
| 2 | -- VHDL Architecture FACT_FAD_lib.REFCLK_counter.behavior
|
|---|
| 3 | --
|
|---|
| 4 | -- Created:
|
|---|
| 5 | -- by - dneise.UNKNOWN (E5B-LABOR6)
|
|---|
| 6 | -- at - 12:10:57 28.01.2011
|
|---|
| 7 | --
|
|---|
| 8 | -- using Mentor Graphics HDL Designer(TM) 2009.2 (Build 10)
|
|---|
| 9 | --
|
|---|
| 10 | LIBRARY ieee;
|
|---|
| 11 | USE ieee.std_logic_1164.all;
|
|---|
| 12 | use IEEE.NUMERIC_STD.ALL;
|
|---|
| 13 |
|
|---|
| 14 | library FACT_FAD_lib;
|
|---|
| 15 | use FACT_FAD_lib.fad_definitions.all;
|
|---|
| 16 |
|
|---|
| 17 | -- REFCLK counter counts rising edges on asynch REFCLK signal
|
|---|
| 18 | -- every ms a new value is returned.
|
|---|
| 19 | -- expected REFCLK frequency: up to 3.3MHz --> 12bit should be enough
|
|---|
| 20 | -- if the REFCLK id too low or too high, alarm outputs are generated
|
|---|
| 21 |
|
|---|
| 22 | ENTITY REFCLK_counter IS
|
|---|
| 23 | PORT (
|
|---|
| 24 | clk : in std_logic; -- 50MHz!
|
|---|
| 25 | refclk_in : in std_logic; -- asychronous signal
|
|---|
| 26 | counter_result : out std_logic_vector(11 downto 0) := (others => '0');
|
|---|
| 27 |
|
|---|
| 28 | alarm_refclk_too_high : out std_logic := '1';
|
|---|
| 29 | alarm_refclk_too_low : out std_logic := '1'
|
|---|
| 30 | );
|
|---|
| 31 | END ENTITY REFCLK_counter;
|
|---|
| 32 |
|
|---|
| 33 | --
|
|---|
| 34 | ARCHITECTURE behavior OF REFCLK_counter IS
|
|---|
| 35 | constant FREQ_UPPER_LIMIT : integer := 3000;
|
|---|
| 36 | constant FREQ_LOWER_LIMIT : integer := 300;
|
|---|
| 37 | constant TIMER_MAX : integer := 100000;
|
|---|
| 38 |
|
|---|
| 39 | signal refclk_in_sr : std_logic_vector(1 downto 0) := "00";
|
|---|
| 40 | signal gate_sr : std_logic_vector(1 downto 0) := "00";
|
|---|
| 41 |
|
|---|
| 42 | signal gate : std_logic := '0';
|
|---|
| 43 | signal time_sig : integer range 0 to TIMER_MAX-1; --2ms clock
|
|---|
| 44 |
|
|---|
| 45 | signal counter : integer range 0 to 4095 :=0 ;
|
|---|
| 46 | BEGIN
|
|---|
| 47 |
|
|---|
| 48 | process (clk)
|
|---|
| 49 | begin
|
|---|
| 50 | if rising_edge( clk ) then
|
|---|
| 51 | refclk_in_sr <= refclk_in_sr(0) & refclk_in; -- synchronize REFCLK in
|
|---|
| 52 | gate_sr <= gate_sr(0) & gate;
|
|---|
| 53 | case gate_sr is
|
|---|
| 54 | when "00" =>
|
|---|
| 55 | when "01" => --rising edge
|
|---|
| 56 | counter <= 0;
|
|---|
| 57 | when "10" =>
|
|---|
| 58 | counter_result <= std_logic_vector( to_unsigned(counter,12) );
|
|---|
| 59 | if (counter < FREQ_LOWER_LIMIT ) then
|
|---|
| 60 | alarm_refclk_too_low <= '1';
|
|---|
| 61 | else
|
|---|
| 62 | alarm_refclk_too_low <= '0';
|
|---|
| 63 | end if;
|
|---|
| 64 | if (counter > FREQ_UPPER_LIMIT ) then
|
|---|
| 65 | alarm_refclk_too_high <= '1';
|
|---|
| 66 | else
|
|---|
| 67 | alarm_refclk_too_high <= '0';
|
|---|
| 68 | end if;
|
|---|
| 69 | when "11" =>
|
|---|
| 70 | if (refclk_in_sr = "01") then
|
|---|
| 71 | counter <= counter +1;
|
|---|
| 72 | end if;
|
|---|
| 73 | WHEN OTHERS =>
|
|---|
| 74 | end case;
|
|---|
| 75 | end if;
|
|---|
| 76 | end process;
|
|---|
| 77 |
|
|---|
| 78 | -- timer proc; generates 1ms gate
|
|---|
| 79 | gate_timer : process (clk)
|
|---|
| 80 |
|
|---|
| 81 | begin
|
|---|
| 82 | if rising_edge(clk) then
|
|---|
| 83 | if (time_sig < TIMER_MAX-1) then
|
|---|
| 84 | time_sig <= time_sig + 1;
|
|---|
| 85 | else
|
|---|
| 86 | time_sig <= 0;
|
|---|
| 87 | end if;
|
|---|
| 88 |
|
|---|
| 89 | if (time_sig = 0) then
|
|---|
| 90 | gate <= '1';
|
|---|
| 91 | end if;
|
|---|
| 92 | if (time_sig = (TIMER_MAX/2)-1) then
|
|---|
| 93 | gate <= '0';
|
|---|
| 94 | end if;
|
|---|
| 95 | end if;
|
|---|
| 96 | end process gate_timer;
|
|---|
| 97 |
|
|---|
| 98 | END ARCHITECTURE behavior;
|
|---|
| 99 |
|
|---|