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: mux_sre.vhd
|
33 |
|
|
-- Description: fixed length (=2) MWD module to reshape slopes of MWD-pulses
|
34 |
|
|
--
|
35 |
|
|
-----------------------------------------------------------------------------------------------
|
36 |
|
|
|
37 |
|
|
library IEEE;
|
38 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
39 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
40 |
|
|
use IEEE.STD_LOGIC_SIGNED.ALL;
|
41 |
|
|
|
42 |
|
|
entity shaper is
|
43 |
|
|
Port (rst : in STD_LOGIC;
|
44 |
|
|
clk : in STD_LOGIC;
|
45 |
|
|
enable : in STD_LOGIC;
|
46 |
|
|
program : in std_logic;
|
47 |
|
|
data_in : in STD_LOGIC_VECTOR;
|
48 |
|
|
correction_in : in STD_LOGIC_VECTOR;
|
49 |
|
|
data_out : out STD_LOGIC_VECTOR
|
50 |
|
|
);
|
51 |
|
|
end shaper;
|
52 |
|
|
|
53 |
|
|
architecture Behavioral of shaper is
|
54 |
|
|
|
55 |
|
|
constant WIDTH : natural := data_in'length;
|
56 |
|
|
constant M_WIDTH : natural := 18; -- Multiplier width ; xilinx MULT18x18_SIO
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
component SISO_add_a
|
60 |
|
|
-- generic( WIDTH : natural);
|
61 |
|
|
port (
|
62 |
|
|
dataa : IN STD_LOGIC_VECTOR;
|
63 |
|
|
datab : IN STD_LOGIC_VECTOR;
|
64 |
|
|
result : OUT STD_LOGIC_VECTOR
|
65 |
|
|
);
|
66 |
|
|
end component;
|
67 |
|
|
|
68 |
|
|
component SISO_sub_a
|
69 |
|
|
generic( --WIDTH : natural;
|
70 |
|
|
A_MINUS_B : boolean
|
71 |
|
|
);
|
72 |
|
|
port (
|
73 |
|
|
dataa : IN STD_LOGIC_VECTOR;
|
74 |
|
|
datab : IN STD_LOGIC_VECTOR;
|
75 |
|
|
result : OUT STD_LOGIC_VECTOR
|
76 |
|
|
);
|
77 |
|
|
end component;
|
78 |
|
|
|
79 |
|
|
component dff_re
|
80 |
|
|
port (rst : in STD_LOGIC;
|
81 |
|
|
clk : in STD_LOGIC;
|
82 |
|
|
enable : IN STD_LOGIC := '1';
|
83 |
|
|
d : in STD_LOGIC_VECTOR;
|
84 |
|
|
q : out STD_LOGIC_VECTOR
|
85 |
|
|
);
|
86 |
|
|
end component;
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
signal rst_S : std_logic := '1';
|
90 |
|
|
signal rst_delay_s : std_logic := '1';
|
91 |
|
|
signal rst_change_S : std_logic := '1';
|
92 |
|
|
signal rst_sum_S : std_logic := '1';
|
93 |
|
|
signal clk_S : std_logic := '0';
|
94 |
|
|
signal enable_S : std_logic := '0';
|
95 |
|
|
signal data_in_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
96 |
|
|
signal program_S : std_logic := '0';
|
97 |
|
|
signal del1_data_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
98 |
|
|
signal del2_data_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
99 |
|
|
signal win_diff_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
100 |
|
|
-- signal del_win_diff_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
101 |
|
|
signal sub_result_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
102 |
|
|
signal change_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
103 |
|
|
signal wide_change_S : std_logic_vector(M_WIDTH - 1 downto 0) := (others => '0');
|
104 |
|
|
signal add_result_S : std_logic_vector(M_WIDTH - 1 downto 0) := (others => '0');
|
105 |
|
|
signal decay_corr_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
106 |
|
|
signal mult_sum_S : std_logic_vector(M_WIDTH - 1 downto 0) := (others => '0');
|
107 |
|
|
signal factor_S : std_logic_vector(M_WIDTH - 1 downto 0) := conv_std_logic_vector(37213, M_WIDTH);
|
108 |
|
|
signal product36 : std_logic_vector(35 downto 0) := (others => '0');
|
109 |
|
|
signal data_out_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
110 |
|
|
|
111 |
|
|
-----------------------------------------------------------------------
|
112 |
|
|
|
113 |
|
|
begin
|
114 |
|
|
|
115 |
|
|
rst_S <= rst;
|
116 |
|
|
clk_S <= clk;
|
117 |
|
|
enable_S <= enable;
|
118 |
|
|
data_in_S <= data_in;
|
119 |
|
|
data_out <= data_out_S;
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
program_proc : process (clk_S, rst_S)
|
123 |
|
|
begin
|
124 |
|
|
if rising_edge(clk_S) then
|
125 |
|
|
program_S <= program;
|
126 |
|
|
if (rst_S = '1') then
|
127 |
|
|
factor_S <= (others => '0');
|
128 |
|
|
else
|
129 |
|
|
program_S <= program;
|
130 |
|
|
if (program = '1') and (program_S = '0') then
|
131 |
|
|
factor_S <= conv_std_logic_vector(conv_integer(correction_in), factor_S'length);
|
132 |
|
|
end if;
|
133 |
|
|
end if;
|
134 |
|
|
end if;
|
135 |
|
|
end process;
|
136 |
|
|
|
137 |
|
|
diff_proc : process(clk_S, rst_delay_s)
|
138 |
|
|
begin
|
139 |
|
|
if rising_edge(clk_S) then
|
140 |
|
|
if (rst_S = '1') then
|
141 |
|
|
del1_data_S <= (others => '0');
|
142 |
|
|
del2_data_S <= (others => '0');
|
143 |
|
|
-- win_diff_S <= (others => '0');
|
144 |
|
|
else
|
145 |
|
|
del1_data_S <= data_in_S;
|
146 |
|
|
del2_data_S <= del1_data_S;
|
147 |
|
|
-- win_diff_S <= conv_std_logic_vector((conv_integer(signed(data_in_S)) - conv_integer(signed(del2_data_S))), WIDTH);
|
148 |
|
|
-- del_win_diff_S <= win_diff_S;
|
149 |
|
|
end if;
|
150 |
|
|
end if;
|
151 |
|
|
end process;
|
152 |
|
|
|
153 |
|
|
-------------------------------------------------------------------------------------------------------------------------------------
|
154 |
|
|
-------------------------------------------------------------------------------------------------------------------------------------
|
155 |
|
|
-- below is the 2-stage moving average
|
156 |
|
|
-------------------------------------------------------------------------------------------------------------------------------------
|
157 |
|
|
-------------------------------------------------------------------------------------------------------------------------------------
|
158 |
|
|
|
159 |
|
|
reset_proc : process(clk_S)
|
160 |
|
|
begin
|
161 |
|
|
if (clk_S'event and clk_S = '1') then
|
162 |
|
|
if (rst_S = '1') then
|
163 |
|
|
rst_delay_s <= '1';
|
164 |
|
|
rst_change_S <= '1';
|
165 |
|
|
rst_sum_S <= '1';
|
166 |
|
|
else
|
167 |
|
|
rst_delay_s <= rst_S;
|
168 |
|
|
rst_change_S <= rst_delay_s;
|
169 |
|
|
rst_sum_S <= rst_change_S;
|
170 |
|
|
end if;
|
171 |
|
|
end if;
|
172 |
|
|
end process;
|
173 |
|
|
|
174 |
|
|
-- SUB = (a - b) !!
|
175 |
|
|
sub_Msum : SISO_sub_a
|
176 |
|
|
GENERIC MAP(--WIDTH =>WIDTH,
|
177 |
|
|
A_MINUS_B => true)
|
178 |
|
|
PORT MAP(dataa => data_in_S,
|
179 |
|
|
datab => del2_data_S,
|
180 |
|
|
result => sub_result_S
|
181 |
|
|
);
|
182 |
|
|
|
183 |
|
|
change_reg : dff_re
|
184 |
|
|
PORT MAP(rst => rst_change_S,
|
185 |
|
|
clk => clk_S,
|
186 |
|
|
enable => enable_S,
|
187 |
|
|
d => sub_result_S,
|
188 |
|
|
q => change_S
|
189 |
|
|
);
|
190 |
|
|
|
191 |
|
|
delay_reg : dff_re -- saving code (and resources ??)
|
192 |
|
|
PORT MAP(rst => rst_change_S,
|
193 |
|
|
clk => clk_S,
|
194 |
|
|
enable => enable_S,
|
195 |
|
|
d => change_S,
|
196 |
|
|
q => win_diff_S
|
197 |
|
|
);
|
198 |
|
|
|
199 |
|
|
wide_change_S <= conv_std_logic_vector(conv_integer(change_S), M_WIDTH);
|
200 |
|
|
|
201 |
|
|
add_Msum : SISO_add_a
|
202 |
|
|
-- GENERIC MAP (WIDTH => M_WIDTH)
|
203 |
|
|
PORT MAP(dataa => wide_change_S,
|
204 |
|
|
datab => mult_sum_S,
|
205 |
|
|
result => add_result_S
|
206 |
|
|
);
|
207 |
|
|
|
208 |
|
|
msum_reg : dff_re
|
209 |
|
|
PORT MAP(rst => rst_sum_S,
|
210 |
|
|
clk => clk_S,
|
211 |
|
|
enable => enable_S,
|
212 |
|
|
d => add_result_S,
|
213 |
|
|
q => mult_sum_S
|
214 |
|
|
);
|
215 |
|
|
-- NOTE !! below product is effectively divided by 4
|
216 |
|
|
decay_corr_S(16 downto 0) <= product36(33 downto 17);
|
217 |
|
|
|
218 |
|
|
-- tau = 3.2ns ! dus ln2/(3.2E-9 * 50E6) = 0.693 / 0.16 = 4.332, MWD_size=2 => MWD_PWR=1
|
219 |
|
|
decay_correction_proc : process(clk_S, rst_S)
|
220 |
|
|
begin
|
221 |
|
|
if (clk_S'event and clk_S = '1') then
|
222 |
|
|
if (rst_S = '1') then
|
223 |
|
|
product36 <= (others => '0');
|
224 |
|
|
data_out_S <= (others => '0');
|
225 |
|
|
else
|
226 |
|
|
if (enable_S = '1') then
|
227 |
|
|
-- NOTE !! below factor and product are effectively divided by 4, to be restored in decay_correction
|
228 |
|
|
product36 <= mult_sum_S * ('0' & '0' & factor_S(17 downto 2));
|
229 |
|
|
-- data_out_S <= win_diff_S + decay_corr_S;
|
230 |
|
|
data_out_S <= conv_std_logic_vector((conv_integer(signed(win_diff_S)) + conv_integer(signed(decay_corr_S))), WIDTH);
|
231 |
|
|
end if;
|
232 |
|
|
end if;
|
233 |
|
|
end if;
|
234 |
|
|
end process;
|
235 |
|
|
|
236 |
|
|
end Behavioral;
|
237 |
|
|
|