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

Back to ROD documentation
threshold_counter.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 15.04.2019 13:30:11
6 -- Design Name:
7 -- Module Name: threshold_counter - RTL
8 -- Project Name:
9 -- Target Devices:
10 -- Tool Versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.2 - 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 
26 --This is an "above threshold counter" for the input fifos. When the fifo level is above the set threshold, the counter increments
27 --until it saturates at all ones. The counter is clocked at 40MHz
28 
30  Port (
31  clock : in STD_LOGIC;
32  reset : in STD_LOGIC; --async reset (ipb_clock sync from reg)
33 -- time_count : in STD_LOGIC;
34  threshold : in STD_LOGIC_VECTOR(15 downto 0); --synchronous to ipb_clock, but not a risk because counter reset should follow writing
35  level : in STD_LOGIC_VECTOR(15 downto 0); --synchronous to pp_clock from the slave side o fthe fifo
36  above_count : out STD_LOGIC_VECTOR(31 downto 0);
37 
38  busy : out STD_LOGIC
39 
40  );
42 
43 architecture RTL of threshold_counter is
44 
45 signal above_counter : std_logic_vector(31 downto 0);
46 signal busy_i : std_logic;
47 
48 begin
49 
50 process(clock, reset)
51  begin
52  if reset = '1' then -- async (p)reset -> put 'reset in sensitivity list
53  above_counter <= (others => '0');
54  elsif rising_edge(clock) then
55  if (level > threshold) and (above_counter < x"ffff_ffff") then
56  above_counter <= (above_counter + 1);
57  else
58  above_counter <= above_counter;
59  end if;
60  end if;
61  end process;
62 
63  above_count(31 downto 0) <= above_counter(31 downto 0); --two lsb's are ignored because the clock is 160MHz and the count rate is 40MHz
64 
65 
66  ---busy generation with hysterisis ------
67 
68 
69 
70  process(clock, reset)
71  begin
72  if reset = '1' then -- async (p)reset -> put 'reset in sensitivity list
73  busy_i <= '0';
74  elsif rising_edge(clock) then
75  if busy_i = '0' then
76  if (level > threshold) then --formerly threshold + 2
77  busy_i <= '1';
78  else busy_i <= busy_i;
79  end if;
80  elsif busy_i = '1' then
81  if (level < threshold - 16) then --formerly threshold - 2
82  busy_i <= '0';
83  else busy_i <= busy_i;
84  end if;
85  end if;
86  else busy_i <= busy_i;
87  -- end if;
88  end if;
89  end process;
90 
91  busy <= busy_i;
92 
93 end RTL;
94 
95