signal output_i : std_logic_vector(OUTPUTS-1 downto 0) := (others => '0');
signal out_reg : std_logic_vector(OUTPUTS-1 downto 0) := (others => '0');
+signal got_any_stretch : std_logic_vector(OUTPUTS-1 downto 0) := (others => '0');
+signal got_any_edge : std_logic_vector(OUTPUTS-1 downto 0) := (others => '0');
signal got_coincidence : std_logic;
signal got_simplecoin : std_logic;
signal coin_enable : std_logic := '0';
signal current_multiplicity, set_multiplicity : unsigned(7 downto 0);
signal multiplicity_trigger : std_logic := '0';
signal multiplicity_enable : std_logic_vector(31 downto 0);
+signal mult_gated : std_logic_vector(31 downto 0);
signal set_output_coin, set_output_mult, set_output_simplecoin : std_logic_vector(7 downto 0);
signal edge_enable : std_logic_vector(7 downto 0) := (others => '0');
-- Outputs
----------------------------
gen_outs : for i in 0 to OUTPUTS-1 generate
- output_i(i) <= (or_all(inp_long and stretch_inp(INPUTS-1 downto 0) and enable(i)(INPUTS-1 downto 0)) and not edge_enable(i))
+ output_i(i) <= (got_any_stretch(i) and not edge_enable(i))
or (or_all(inp_inv(INPUTS-1 downto 0) and not stretch_inp(INPUTS-1 downto 0) and enable(i)(INPUTS-1 downto 0)) and not edge_enable(i))
- or (or_all(inp_edge(INPUTS-1 downto 0) and enable(i)(INPUTS-1 downto 0)) and edge_enable(i))
+ or (got_any_edge(i) and edge_enable(i))
or (got_simplecoin and set_output_simplecoin(i))
or (multiplicity_trigger and set_output_mult(i))
or (got_coincidence and set_output_coin(i))
;
+got_any_edge(i) <= or_all(inp_edge(INPUTS-1 downto 0) and enable(i)(INPUTS-1 downto 0)) when rising_edge(CLK);
+got_any_stretch(i) <= or_all(inp_long and stretch_inp(INPUTS-1 downto 0) and enable(i)(INPUTS-1 downto 0)) when rising_edge(CLK);
+
end generate;
+
out_reg <= output_i when rising_edge(CLK);
OUTPUT <= output_i;
-- gen_mult : if OUTPUTS >= 2 generate
PROC_MULT : process
variable m : integer range 0 to INPUTS-1;
+ variable numchan : integer range 0 to 31;
begin
wait until rising_edge(CLK);
+ numchan := minimum(INPUTS-1,31);
+
+ mult_gated(numchan downto 0) <= inp_verylong(numchan downto 0) and multiplicity_enable(numchan downto 0);
+
m := 0;
- for i in 0 to minimum(INPUTS-1,31) loop --was INPUTS-1 @ 09.17
- if inp_verylong(i) = '1' and multiplicity_enable(i) = '1' then
+ for i in 0 to numchan loop --was INPUTS-1 @ 09.17
+ if mult_gated(i) = '1' then
m := m + 1;
end if;
end loop;