| 1 |
2 |
panda_emc |
-----------------------------------------------------------------------------------------------
|
| 2 |
|
|
--
|
| 3 |
|
|
-- Copyright (C) 2011 Peter Lemmens, PANDA collaboration
|
| 4 |
|
|
-- p.j.j.lemmens@rug.nl
|
| 5 |
|
|
-- http://www-panda.gsi.de
|
| 6 |
|
|
--
|
| 7 |
|
|
-- As a reference, please use:
|
| 8 |
|
|
-- E. Guliyev, M. Kavatsyuk, P.J.J. Lemmens, G. Tambave, H. Loehner,
|
| 9 |
|
|
-- "VHDL Implementation of Feature-Extraction Algorithm for the PANDA Electromagnetic Calorimeter"
|
| 10 |
|
|
-- Nuclear Inst. and Methods in Physics Research, A ....
|
| 11 |
|
|
--
|
| 12 |
|
|
--
|
| 13 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
| 14 |
|
|
-- it under the terms of the GNU Lesser General Public License as published by
|
| 15 |
|
|
-- the Free Software Foundation; either version 3 of the License, or
|
| 16 |
|
|
-- (at your option) any later version.
|
| 17 |
|
|
--
|
| 18 |
|
|
-- This program is distributed in the hope that it will be useful,
|
| 19 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
|
|
-- GNU Lesser General Public License for more details.
|
| 22 |
|
|
--
|
| 23 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 24 |
|
|
-- along with this program; if not, write to the Free Software
|
| 25 |
|
|
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
|
| 26 |
|
|
--
|
| 27 |
|
|
-----------------------------------------------------------------------------------------------
|
| 28 |
|
|
-----------------------------------------------------------------------------------------------
|
| 29 |
|
|
-- Company : KVI (Kernfysisch Versneller Instituut -- Groningen, The Netherlands
|
| 30 |
|
|
-- Author : P.J.J. Lemmens
|
| 31 |
|
|
-- Design Name : Feature Extraction
|
| 32 |
|
|
-- Module Name : window_diff.vhd
|
| 33 |
|
|
-- Description : Somewhat obsolete module; Originally used to calculate the difference
|
| 34 |
|
|
-- between two samples at a fixed interval. That is still what it does,
|
| 35 |
|
|
-- only: the interval = 1 (where it used to be set by Generics)
|
| 36 |
|
|
-- Data delays were introduced to overcome event-detection latency
|
| 37 |
|
|
--
|
| 38 |
|
|
-----------------------------------------------------------------------------------------------
|
| 39 |
|
|
library IEEE;
|
| 40 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 41 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
| 42 |
|
|
use IEEE.STD_LOGIC_SIGNED.ALL;
|
| 43 |
|
|
|
| 44 |
|
|
entity window_diff is
|
| 45 |
|
|
Port ( rst : in STD_LOGIC;
|
| 46 |
|
|
clk : in STD_LOGIC;
|
| 47 |
|
|
enable : in STD_LOGIC;
|
| 48 |
|
|
trigger : in STD_LOGIC;
|
| 49 |
|
|
data_in : in STD_LOGIC_VECTOR;
|
| 50 |
|
|
base_out : out STD_LOGIC_VECTOR;
|
| 51 |
|
|
diff_out : out STD_LOGIC_VECTOR
|
| 52 |
|
|
);
|
| 53 |
|
|
end window_diff;
|
| 54 |
|
|
|
| 55 |
|
|
architecture Behavioral of window_diff is
|
| 56 |
|
|
|
| 57 |
|
|
constant WIDTH : natural := data_in'length;
|
| 58 |
|
|
|
| 59 |
|
|
signal rst_S : std_logic := '1';
|
| 60 |
|
|
signal clk_S : std_logic := '0';
|
| 61 |
|
|
signal enable_S : std_logic := '0';
|
| 62 |
|
|
signal trigger_S : std_logic := '0';
|
| 63 |
|
|
signal data_in_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 64 |
|
|
signal del1_data_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 65 |
|
|
signal del2_data_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 66 |
|
|
signal del3_data_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 67 |
|
|
signal del4_data_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 68 |
|
|
signal del5_data_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 69 |
|
|
signal base_data_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 70 |
|
|
signal diff_out_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 71 |
|
|
signal base_val_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
| 72 |
|
|
--------------------------------------------------------------------------------------------------
|
| 73 |
|
|
|
| 74 |
|
|
begin
|
| 75 |
|
|
|
| 76 |
|
|
trigger_delay_proc : process(rst_S, clk_S, enable_S, data_in_S)
|
| 77 |
|
|
begin
|
| 78 |
|
|
if (clk_S'event and clk_S = '1') then
|
| 79 |
|
|
if (rst_S = '1') then
|
| 80 |
|
|
del1_data_S <= (others => '0');
|
| 81 |
|
|
del2_data_S <= (others => '0');
|
| 82 |
|
|
del3_data_S <= (others => '0');
|
| 83 |
|
|
del4_data_S <= (others => '0');
|
| 84 |
|
|
else
|
| 85 |
|
|
if (enable_S = '1') then
|
| 86 |
|
|
del1_data_S <= data_in_S;
|
| 87 |
|
|
del2_data_S <= del1_data_S;
|
| 88 |
|
|
del3_data_S <= del2_data_S;
|
| 89 |
|
|
del4_data_S <= del3_data_S;
|
| 90 |
|
|
end if;
|
| 91 |
|
|
end if;
|
| 92 |
|
|
end if;
|
| 93 |
|
|
end process;
|
| 94 |
|
|
|
| 95 |
|
|
|
| 96 |
|
|
zerox_win_proc : process(rst_S, clk_S, enable_S, del4_data_S)
|
| 97 |
|
|
begin
|
| 98 |
|
|
if (clk_S'event and clk_S = '1') then
|
| 99 |
|
|
if (rst_S = '1') then
|
| 100 |
|
|
del5_data_S <= (others => '0');
|
| 101 |
|
|
else
|
| 102 |
|
|
if (enable_S = '1') then
|
| 103 |
|
|
del5_data_S <= del4_data_S;
|
| 104 |
|
|
base_data_S <= del5_data_S;
|
| 105 |
|
|
end if;
|
| 106 |
|
|
end if;
|
| 107 |
|
|
end if;
|
| 108 |
|
|
end process;
|
| 109 |
|
|
|
| 110 |
|
|
rst_S <= rst;
|
| 111 |
|
|
clk_S <= clk;
|
| 112 |
|
|
enable_S <= enable;
|
| 113 |
|
|
trigger_S <= trigger;
|
| 114 |
|
|
data_in_S <= data_in;
|
| 115 |
|
|
|
| 116 |
|
|
base_out <= base_val_S;
|
| 117 |
|
|
diff_out <= diff_out_S;
|
| 118 |
|
|
|
| 119 |
|
|
pipe_proc : process(rst_S, clk_S, enable_S, trigger_S, del5_data_S, base_data_S)
|
| 120 |
|
|
begin
|
| 121 |
|
|
if (clk_S'event and clk_S = '1') then
|
| 122 |
|
|
if (rst_S = '1') then
|
| 123 |
|
|
diff_out_S <= (others => '0');
|
| 124 |
|
|
base_val_S <= (others => '0');
|
| 125 |
|
|
else
|
| 126 |
|
|
if (enable_S = '1') then
|
| 127 |
|
|
if (trigger_S = '1') then -- below was: "del3_data_S - base_data_S".... don't know why
|
| 128 |
|
|
diff_out_S <= conv_std_logic_vector(conv_integer(signed(del5_data_S)) - conv_integer(signed(base_data_S)), WIDTH);
|
| 129 |
|
|
base_val_S <= base_data_S;
|
| 130 |
|
|
end if;
|
| 131 |
|
|
end if;
|
| 132 |
|
|
end if;
|
| 133 |
|
|
end if;
|
| 134 |
|
|
end process;
|
| 135 |
|
|
|
| 136 |
|
|
end Behavioral;
|