ROD firmware  1.0.5
ATLAS l1-calo - ROD_eFEX and ROD_jFEX firmware for the L1Calo ROD board

Back to ROD documentation
tob_timeout.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 16.01.2021 14:07:05
6 -- Design Name:
7 -- Module Name: tob_timeout - RTL
8 -- Project Name:
9 -- Target Devices:
10 -- Tool Versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.01 - File Created
17 -- Additional Comments:
18 --
19 ----------------------------------------------------------------------------------
20 
21 
22 library IEEE;
23 use IEEE.STD_LOGIC_1164.ALL;
24 use IEEE.STD_LOGIC_UNSIGNED.ALL;
25 -- Uncomment the following library declaration if using
26 -- arithmetic functions with Signed or Unsigned values
27 --use IEEE.NUMERIC_STD.ALL;
28 
29 -- Uncomment the following library declaration if instantiating
30 -- any Xilinx leaf cells in this code.
31 --library UNISIM;
32 --use UNISIM.VComponents.all;
33 
34 --This block is used in the TOB processor. After an L1A is received,
35 -->This block takes in a programmable time from a register (time_set).
36 -->The timer is started counting from zero by a 1 cycle pulse on the "start" input.
37 -->The timer is stopped, set to zero, and timeout set to 0 by a 1 cycle pulse on the "stop" input or reset.
38 -->If the counter reaches the set_time value, timeout is set to '1' and the counter is stopped.
39 
40 -->when the timer reaches the programmed time
41 
42 --> The counter has now been extended to 18-bits in order to give it twice the available time.
43 --The external connections are still 16 bits, giving the impression that it is counting at 1/2
44 --the previous rate (pp_clock/2 = 100MHz)
45 
46 entity tob_timeout is
47  generic (
48  counter_width : integer := 19;
49  msb : integer := (counter_width - 1);
50  lsb : integer := (counter_width - 16)
51  );
52 
53  Port ( clock : in STD_LOGIC;
54  reset : in STD_LOGIC;
55  start_timer : in STD_LOGIC;
56  stop_timer : in STD_LOGIC;
57  set_time_1 : in STD_LOGIC_VECTOR(15 downto 0);
58  set_time_n : in STD_LOGIC_VECTOR(15 downto 0);
59  timeout_1 : out STD_LOGIC;
60  timeout_n : out STD_LOGIC;
61  counter_out : out STD_LOGIC_VECTOR(15 downto 0);
62  run_out : out STD_LOGIC
63  );
64 end tob_timeout;
65 
66 architecture RTL of tob_timeout is
67 
68 signal counter : std_logic_vector(msb downto 0) := (others => '0');
69 signal run : std_logic := '0';
70 signal timeout_1_i : STD_LOGIC;
71 signal timeout_n_i : STD_LOGIC;
72 
73 begin
74 
75 
76 process (clock) begin
77  if rising_edge (clock) then
78  if (reset = '1') or (stop_timer = '1') then
79  counter <= (others => '0');
80  run <= '0';
81  elsif (start_timer = '1') then
82  run <= '1';
83  counter <= (others => '0');
84  elsif (counter(msb downto lsb) >= set_time_1) and (counter(msb downto lsb) >= set_time_n) then
85  counter <= counter;
86  run <= '0';
87  elsif (run = '1') then
88  counter <= counter +1;
89  else
90  counter <= counter;
91  end if;
92  end if;
93 end process;
94 
95 process (clock) begin
96  if rising_edge (clock) then
97  if (reset = '1') or (stop_timer = '1') or (start_timer = '1') then
98  timeout_1_i <= '0';
99  timeout_n_i <= '0';
100  elsif counter(msb downto lsb) >= set_time_1 then
101  timeout_1_i <= '1';
102  elsif counter(msb downto lsb) >= set_time_n then
103  timeout_n_i <= '1';
104  else
105  timeout_1_i <= timeout_1_i;
106  timeout_n_i <= timeout_n_i;
107  end if;
108  end if;
109 end process;
110 
111  timeout_1 <= timeout_1_i;
112  timeout_n <= timeout_n_i;
113  counter_out <= counter(msb downto lsb);
114  run_out <= run;
115 
116 end RTL;