Belle II KLM Scint Firmware  1
timing_ctrl.vhd
1 --**********************************************************************************
2 -- Indiana University Cyclotron Facility (IUCF)
3 --
4 -- Project: Belle-II
5 --
6 -- Author: Brandon Kunkler
7 --
8 -- Date: 02/25/2014
9 --
10 --**********************************************************************************
11 -- Description:
12 -- Timing and control signals for logic that sends and receive data at
13 -- rates other than the clock frequency. Generate clock enables and strobes
14 -- from a free running counter.
15 --**********************************************************************************
16 library ieee;
17  use ieee.std_logic_1164.all;
18  use ieee.std_logic_unsigned.all;
19 library work;
20  use work.timing_ctrl_pkg.all;
21 
22 entity timing_ctrl is
23  port(
24  clk : in std_logic;
25  clk2x : in std_logic;
26  tdc_sync : in std_logic;
27  runreset : in std_logic;
28  tdcrst : out std_logic_vector(1 to 3);--vector so we can distribute to meet timing
29  runreset2x : out std_logic_vector(1 to 3);--vector so we can distribute to meet timing
30  tdcce_2x : out std_logic_vector(1 to 5)); -- _Nx is N times clock period
31 end timing_ctrl;
32 
33 
34 architecture behave of timing_ctrl is
35 
36  --------------------------------------------------------------------------
37  -- Signal declarations.
38  --------------------------------------------------------------------------
39  --signal tdcrst_shift : std_logic_vector(39 downto 0) := (others => '1');
40  signal tdcrst_shift : std_logic_vector(1 downto 0) := (others => '1');
41  signal tdcrst_i : std_logic_vector(tdcrst'length downto 0) := (others => '1');
42 
43  signal runreset_q0 : std_logic;
44  signal runreset_q1 : std_logic_vector(1 to 3);
45 
46  signal tce_cnt : std_logic_vector(TC_CCNT_WIDTH-1 downto 0):= (others => '0');
47  signal tce_2x_d : std_logic;
48  signal tce_2x_q0 : std_logic := '0';
49  signal tce_2x_r : std_logic := '1';
50  signal tce_2x_i : std_logic_vector(tdcce_2x'length-1 downto 0):= (others => '0');
51 
52  attribute ASYNC_REG : string;
53  attribute ASYNC_REG of tdcrst_shift : signal is "TRUE";
54  attribute ASYNC_REG of runreset_q0 : signal is "TRUE";
55  attribute ASYNC_REG of runreset_q1 : signal is "TRUE";
56 
57 begin
58 
59 
60 
61 ------------------------------------------------------------------------------------------------
62 -- Concurrent statements
63 ------------------------------------------------------------------------------------------------
64  --------------------------------------------------------
65  -- Map signals out of the port
66  --------------------------------------------------------
67  tdcrst <= tdcrst_i(tdcrst_i'length-2 downto 0);
68  runreset2x <= runreset_q1;
69  tdcce_2x <= tce_2x_i;
70 
71  --------------------------------------------------------
72  -- Combinational logic
73  --------------------------------------------------------
74 
75  -- detect a rising edge counter bit to generate clock enable
76  tce_2x_d <= tce_cnt(TC_2X_BIT) and (not tce_2x_r);
77 
78  ------------------------------------------------------------------
79  -- Assert reset for shift length clock cycles and cross clock domain.
82  -- The initial delay is 39 clock cycles.
83  ------------------------------------------------------------------
84  --trst_proc : process(runreset,clk2x)
85  trst_proc : process(tdc_sync,clk2x)
86  begin
87  -- must use asynch reset
88  if tdc_sync = '1' then
89  -- assert reset for shift length
90  tdcrst_shift <= (others => '1');
91  else
92  if (clk2x'event and clk2x='1') then
93  -- de-assert after shift length
94  tdcrst_shift <= '0' & tdcrst_shift(tdcrst_shift'length-1 downto 1);
95  end if;
96  end if;
97  end process;
98 
99  -----------------------------------------------------------------
100  -- Re-time the runreset signal
101  -----------------------------------------------------------------
102  rrst_proc : process(clk2x)
103  begin
104  if (clk2x'event and clk2x='1') then
105  runreset_q0 <= runreset;
106  runreset_q1 <= (others => runreset_q0);
107  end if;
108  end process;
109 
110  ------------------------------------------------------------------
111  -- Free running counter for generating clock enables at
112  -- different rates.
113  ------------------------------------------------------------------
114  tce_proc : process(clk2x)
115  begin
116  if (clk2x'event and clk2x='1') then
117  if tdcrst_i(tdcrst_i'length-1) = '1' then
118  tce_cnt <= (others => '0');
119  else
120  tce_cnt <= tce_cnt - 1;
121  end if;
122  tce_2x_r <= tce_cnt(TC_2X_BIT);
123  end if;
124  end process;
125 
126  ------------------------------------------------------------------
127  -- Register outputs to improve timing and align the signal edges
128  ------------------------------------------------------------------
129  tdly_proc : process(clk2x)
130  begin
131  if (clk2x'event and clk2x='1') then
132  tce_2x_q0 <= tce_2x_d;
133  tce_2x_i <= (others => tce_2x_q0);
134  tdcrst_i <= (others => tdcrst_shift(0));
135  end if;
136  end process;
137 
138 end behave;