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: MWD_CF_process.vhd
|
33 |
|
|
-- Description: - Moving Window Deconvolution ("MWD_programmable")
|
34 |
|
|
-- - Pulse Reshape module ("shaper")
|
35 |
|
|
-- - switch/multiplexer ("mux_sre")
|
36 |
|
|
-- - Constant Fraction pulse-detection ("CF_process")
|
37 |
|
|
-----------------------------------------------------------------------------------------------
|
38 |
|
|
library IEEE;
|
39 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
40 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
41 |
|
|
use IEEE.STD_LOGIC_SIGNED.ALL;
|
42 |
|
|
|
43 |
|
|
entity MWD_CF_process is
|
44 |
|
|
generic( WIDTH : natural := 1;
|
45 |
|
|
MAX_MWD_PWR : natural := 1;
|
46 |
|
|
MAX_CF_PWR : natural := 1;
|
47 |
|
|
MAX_BASELINE_PWR : natural := 1;
|
48 |
|
|
ZEROX_WINDOW_PWR : natural := 1;
|
49 |
|
|
ZEROX_THRESHOLD_PWR : natural := 1;
|
50 |
|
|
INTERP_CYCLES : natural := 1
|
51 |
|
|
);
|
52 |
|
|
Port ( rst : in STD_LOGIC;
|
53 |
|
|
clk : in STD_LOGIC;
|
54 |
|
|
enable : in STD_LOGIC;
|
55 |
|
|
program : in STD_LOGIC;
|
56 |
|
|
baseline_enable : in STD_LOGIC;
|
57 |
|
|
double_CF_in : in STD_LOGIC;
|
58 |
|
|
bypass_mwd : in STD_LOGIC;
|
59 |
|
|
bypass_reshape : in STD_LOGIC;
|
60 |
|
|
data_in : in STD_LOGIC_VECTOR (WIDTH - 1 downto 0);
|
61 |
|
|
invert_data_in : in STD_LOGIC;
|
62 |
|
|
decay_correction_in : in STD_LOGIC_VECTOR;
|
63 |
|
|
reshape_correction_in : in STD_LOGIC_VECTOR;
|
64 |
|
|
threshold_in : in STD_LOGIC_VECTOR;
|
65 |
|
|
mwd_pwr_in : in std_logic_vector(7 downto 0); -- power of 2 for mwd-windowsize
|
66 |
|
|
cf_pwr_in : in std_logic_vector(7 downto 0); -- power of 2 for cf-delay
|
67 |
|
|
cf_integral_pwr_in : in std_logic_vector(7 downto 0); -- power of 2 for CF integral
|
68 |
|
|
baseline_pwr_in : in STD_LOGIC_VECTOR(7 downto 0);
|
69 |
|
|
baseline_inhibit_cnt_in : in std_logic_vector(7 downto 0); -- baseline data-collect inhibition after event
|
70 |
|
|
event_inhibit_cnt_in : in std_logic_vector(7 downto 0); -- event detect inhibition after event
|
71 |
|
|
mwd_switch_out : out STD_LOGIC_VECTOR;
|
72 |
|
|
baseline_out : out STD_LOGIC_VECTOR;
|
73 |
|
|
clamped_out : out STD_LOGIC_VECTOR;
|
74 |
|
|
del_clamp_out : out STD_LOGIC_VECTOR;
|
75 |
|
|
CFdev_clamp_out : out STD_LOGIC_VECTOR;
|
76 |
|
|
cf_trace_out : out STD_LOGIC_VECTOR;
|
77 |
|
|
integral : out STD_LOGIC_VECTOR;
|
78 |
|
|
sample_nr : out STD_LOGIC_VECTOR;
|
79 |
|
|
zeroX_out : out STD_LOGIC;
|
80 |
|
|
event_detect_out : out STD_LOGIC;
|
81 |
|
|
bl_gate_out : out STD_LOGIC;
|
82 |
|
|
ed_gate_out : out STD_LOGIC;
|
83 |
|
|
eventdata_valid : out STD_LOGIC;
|
84 |
|
|
eventnr_out : out STD_LOGIC_VECTOR;
|
85 |
|
|
fraction : out STD_LOGIC_VECTOR;
|
86 |
|
|
energy : out STD_LOGIC_VECTOR
|
87 |
|
|
);
|
88 |
|
|
end MWD_CF_process;
|
89 |
|
|
|
90 |
|
|
architecture Behavioral of MWD_CF_process is
|
91 |
|
|
|
92 |
|
|
constant SIGNED_WIDTH : natural := WIDTH + 1;
|
93 |
|
|
constant FRACTION_SIZE : natural := INTERP_CYCLES;-- - ZEROX_WINDOW_PWR; --all interp bits are fraction now !! interp between 2 samples
|
94 |
|
|
constant MAX_RESHAPE_PWR : natural := 2;
|
95 |
|
|
|
96 |
|
|
component MWD_programmable
|
97 |
|
|
generic( MAX_MWD_PWR : natural);
|
98 |
|
|
Port (rst : in STD_LOGIC;
|
99 |
|
|
clk : in STD_LOGIC;
|
100 |
|
|
enable : in STD_LOGIC;
|
101 |
|
|
program : in std_logic;
|
102 |
|
|
mwd_pwr_in : in std_logic_vector(7 downto 0);
|
103 |
|
|
data_in : in STD_LOGIC_VECTOR;
|
104 |
|
|
correction_in : in STD_LOGIC_VECTOR;
|
105 |
|
|
data_out : out STD_LOGIC_VECTOR
|
106 |
|
|
);
|
107 |
|
|
end component;
|
108 |
|
|
|
109 |
|
|
component shaper
|
110 |
|
|
Port (rst : in STD_LOGIC;
|
111 |
|
|
clk : in STD_LOGIC;
|
112 |
|
|
enable : in STD_LOGIC;
|
113 |
|
|
program : in std_logic;
|
114 |
|
|
data_in : in STD_LOGIC_VECTOR;
|
115 |
|
|
correction_in : in STD_LOGIC_VECTOR;
|
116 |
|
|
data_out : out STD_LOGIC_VECTOR
|
117 |
|
|
);
|
118 |
|
|
end component;
|
119 |
|
|
|
120 |
|
|
component mux_sre
|
121 |
|
|
Port (rst : in STD_LOGIC;
|
122 |
|
|
clk : in STD_LOGIC;
|
123 |
|
|
enable : in STD_LOGIC;
|
124 |
|
|
selectB : in STD_LOGIC;
|
125 |
|
|
a : in STD_LOGIC_VECTOR;
|
126 |
|
|
b : in STD_LOGIC_VECTOR;
|
127 |
|
|
data_valid : out STD_LOGIC;
|
128 |
|
|
q : out STD_LOGIC_VECTOR
|
129 |
|
|
);
|
130 |
|
|
end component;
|
131 |
|
|
|
132 |
|
|
COMPONENT CF_process
|
133 |
|
|
generic( WIDTH : natural := 1;
|
134 |
|
|
MAX_CF_PWR : natural := 1;
|
135 |
|
|
MAX_BASELINE_PWR : natural := 1;
|
136 |
|
|
ZEROX_WINDOW_PWR : natural := 1;
|
137 |
|
|
ZEROX_THRESHOLD_PWR : natural := 1;-- INTEGRAL_PWR : natural := 1;
|
138 |
|
|
INTERP_CYCLES : natural := 1
|
139 |
|
|
);
|
140 |
|
|
Port ( rst : in STD_LOGIC;
|
141 |
|
|
clk : in STD_LOGIC;
|
142 |
|
|
enable : in STD_LOGIC;
|
143 |
|
|
program : in STD_LOGIC;
|
144 |
|
|
baseline_enable : in STD_LOGIC;
|
145 |
|
|
double_CF_in : in STD_LOGIC;
|
146 |
|
|
data_in : in STD_LOGIC_VECTOR (WIDTH - 1 downto 0);
|
147 |
|
|
threshold_in : in STD_LOGIC_VECTOR;
|
148 |
|
|
cf_pwr_in : in STD_LOGIC_VECTOR;
|
149 |
|
|
cf_integral_pwr_in : in STD_LOGIC_VECTOR;
|
150 |
|
|
baseline_pwr_in : in STD_LOGIC_VECTOR;
|
151 |
|
|
baseline_inhibit_cnt_in : in STD_LOGIC_VECTOR;
|
152 |
|
|
event_inhibit_cnt_in : in STD_LOGIC_VECTOR;
|
153 |
|
|
baseline_out : out STD_LOGIC_VECTOR;
|
154 |
|
|
clamped_out : out STD_LOGIC_VECTOR;
|
155 |
|
|
del_clamp_out : out STD_LOGIC_VECTOR;
|
156 |
|
|
CFdev_clamp_out : out STD_LOGIC_VECTOR;
|
157 |
|
|
cf_trace_out : out STD_LOGIC_VECTOR;
|
158 |
|
|
integral : out STD_LOGIC_VECTOR;
|
159 |
|
|
sample_nr : out STD_LOGIC_VECTOR;
|
160 |
|
|
zeroX_out : out STD_LOGIC;
|
161 |
|
|
event_detect_out : out STD_LOGIC;
|
162 |
|
|
bl_gate_out : out STD_LOGIC;
|
163 |
|
|
ed_gate_out : out STD_LOGIC;
|
164 |
|
|
eventdata_valid : out STD_LOGIC;
|
165 |
|
|
eventnr_out : out STD_LOGIC_VECTOR;
|
166 |
|
|
fraction : out STD_LOGIC_VECTOR;
|
167 |
|
|
energy : out STD_LOGIC_VECTOR
|
168 |
|
|
);
|
169 |
|
|
END COMPONENT;
|
170 |
|
|
|
171 |
|
|
-----------------------------------------------------------------------
|
172 |
|
|
|
173 |
|
|
signal rst_S : std_logic := '1';
|
174 |
|
|
signal clk_S : std_logic := '0';
|
175 |
|
|
signal enable_S : std_logic := '0';
|
176 |
|
|
signal program_S : std_logic := '0';
|
177 |
|
|
signal baseline_enable_S : std_logic := '0';
|
178 |
|
|
signal double_CF_S : std_logic := '0';
|
179 |
|
|
signal bypass_mwd_S : std_logic := '0';
|
180 |
|
|
signal bypass_reshape_S : std_logic := '0';
|
181 |
|
|
signal udata_in_S : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
|
182 |
|
|
signal invert_data_in_S : std_logic := '0';
|
183 |
|
|
signal data_in_S : std_logic_vector(WIDTH downto 0) := (others => '0');
|
184 |
|
|
signal decay_correction_S : std_logic_vector(decay_correction_in'high downto 0) := (others => '0');
|
185 |
|
|
signal reshape_correction_S : std_logic_vector(reshape_correction_in'high downto 0) := (others => '0');
|
186 |
|
|
signal threshold_S : STD_LOGIC_VECTOR(WIDTH downto 0) := (others => '0');
|
187 |
|
|
signal mwd_pwr_S : STD_LOGIC_VECTOR(7 downto 0) := conv_std_logic_vector(5, 8); -- original default value
|
188 |
|
|
signal cf_pwr_S : STD_LOGIC_VECTOR(7 downto 0) := conv_std_logic_vector(4, 8); -- original default value
|
189 |
|
|
signal cf_integral_pwr_S : STD_LOGIC_VECTOR(7 downto 0) := conv_std_logic_vector(4, 8); -- original default value = (mwd_power - 1)
|
190 |
|
|
signal baseline_pwr_S : STD_LOGIC_VECTOR (7 downto 0) := (others => '0');
|
191 |
|
|
signal baseline_inhibit_cnt_S : STD_LOGIC_VECTOR(7 downto 0) := conv_std_logic_vector(32, 8); -- original default value
|
192 |
|
|
signal event_inhibit_cnt_S : STD_LOGIC_VECTOR(7 downto 0) := conv_std_logic_vector(16, 8); -- original default value
|
193 |
|
|
|
194 |
|
|
signal short_S : std_logic_vector(WIDTH downto 0) := (others => '0');
|
195 |
|
|
signal reshaped_S : std_logic_vector(WIDTH downto 0) := (others => '0');
|
196 |
|
|
signal mwd_switch_out_S : std_logic_vector(WIDTH downto 0) := (others => '0');
|
197 |
|
|
signal mwd_switch_data_valid_S : std_logic := '0';
|
198 |
|
|
signal reshape_switch_out_S : std_logic_vector(WIDTH downto 0) := (others => '0');
|
199 |
|
|
signal reshape_switch_data_valid_S : std_logic := '0';
|
200 |
|
|
signal baseline_S : STD_LOGIC_VECTOR(WIDTH downto 0) := (others => '0');
|
201 |
|
|
signal clamped_S : STD_LOGIC_VECTOR(WIDTH downto 0) := (others => '0');
|
202 |
|
|
signal CFdev_clamp_S : STD_LOGIC_VECTOR(WIDTH downto 0) := (others => '0');
|
203 |
|
|
signal del_clamp_S : STD_LOGIC_VECTOR(WIDTH downto 0) := (others => '0');
|
204 |
|
|
signal cf_trace_S : STD_LOGIC_VECTOR(WIDTH downto 0) := (others => '0');
|
205 |
|
|
signal integral_S : STD_LOGIC_VECTOR(WIDTH downto 0) := (others => '0');
|
206 |
|
|
signal event_detect_S : std_logic := '0';
|
207 |
|
|
signal zeroX_S : STD_LOGIC := '0';
|
208 |
|
|
signal bl_gate_S : STD_LOGIC := '0';
|
209 |
|
|
signal ed_gate_S : STD_LOGIC := '0';
|
210 |
|
|
signal sample_nr_S : STD_LOGIC_VECTOR(63 downto 0) := (others => '0');
|
211 |
|
|
signal eventnr_S : STD_LOGIC_VECTOR(63 downto 0) := (others => '0');
|
212 |
|
|
signal fraction_S : STD_LOGIC_VECTOR(FRACTION_SIZE - 1 downto 0) := (others => '0');
|
213 |
|
|
signal energy_S : STD_LOGIC_VECTOR(WIDTH downto 0) := (others => '0');
|
214 |
|
|
signal eventdata_valid_S : STD_LOGIC := '0';
|
215 |
|
|
-----------------------------------------------------------------------
|
216 |
|
|
|
217 |
|
|
begin
|
218 |
|
|
|
219 |
|
|
mwd : MWD_programmable
|
220 |
|
|
generic map(MAX_MWD_PWR => MAX_MWD_PWR)
|
221 |
|
|
port map(rst => rst_S,
|
222 |
|
|
clk => clk_S,
|
223 |
|
|
enable => enable_S,
|
224 |
|
|
program => program_S,
|
225 |
|
|
mwd_pwr_in => mwd_pwr_S,
|
226 |
|
|
data_in => data_in_S,
|
227 |
|
|
correction_in => decay_correction_S,
|
228 |
|
|
data_out => short_S
|
229 |
|
|
);
|
230 |
|
|
|
231 |
|
|
mwd_switch : mux_sre
|
232 |
|
|
port map(rst => rst_S,
|
233 |
|
|
clk => clk_S,
|
234 |
|
|
enable => enable_S,
|
235 |
|
|
selectb => bypass_mwd_S,
|
236 |
|
|
a => short_S,
|
237 |
|
|
b => data_in_S,
|
238 |
|
|
data_valid => mwd_switch_data_valid_S,
|
239 |
|
|
q => mwd_switch_out_S
|
240 |
|
|
);
|
241 |
|
|
|
242 |
|
|
reshape : shaper
|
243 |
|
|
port map(rst => rst_S,
|
244 |
|
|
clk => clk_S,
|
245 |
|
|
enable => mwd_switch_data_valid_S,
|
246 |
|
|
program => program_S,
|
247 |
|
|
data_in => mwd_switch_out_S,
|
248 |
|
|
correction_in => reshape_correction_S,
|
249 |
|
|
data_out => reshaped_S
|
250 |
|
|
);
|
251 |
|
|
|
252 |
|
|
reshape_switch : mux_sre
|
253 |
|
|
port map(rst => rst_S,
|
254 |
|
|
clk => clk_S,
|
255 |
|
|
enable => mwd_switch_data_valid_S,
|
256 |
|
|
selectb => bypass_reshape_S,
|
257 |
|
|
a => reshaped_S,
|
258 |
|
|
b => mwd_switch_out_S,
|
259 |
|
|
data_valid => reshape_switch_data_valid_S,
|
260 |
|
|
q => reshape_switch_out_S
|
261 |
|
|
);
|
262 |
|
|
|
263 |
|
|
CF : CF_process
|
264 |
|
|
generic map(WIDTH => SIGNED_WIDTH,
|
265 |
|
|
MAX_CF_PWR => MAX_CF_PWR,
|
266 |
|
|
MAX_BASELINE_PWR => MAX_BASELINE_PWR,
|
267 |
|
|
ZEROX_WINDOW_PWR => ZEROX_WINDOW_PWR,
|
268 |
|
|
ZEROX_THRESHOLD_PWR => ZEROX_THRESHOLD_PWR,
|
269 |
|
|
INTERP_CYCLES => INTERP_CYCLES
|
270 |
|
|
)
|
271 |
|
|
PORT MAP( rst => rst_S,
|
272 |
|
|
clk => clk_S,
|
273 |
|
|
enable => reshape_switch_data_valid_S,
|
274 |
|
|
program => program_S,
|
275 |
|
|
baseline_enable => baseline_enable_S,
|
276 |
|
|
double_CF_in => double_CF_S,
|
277 |
|
|
data_in => reshape_switch_out_S,
|
278 |
|
|
threshold_in => threshold_S,
|
279 |
|
|
cf_pwr_in => cf_pwr_S,
|
280 |
|
|
cf_integral_pwr_in => cf_integral_pwr_S,
|
281 |
|
|
baseline_pwr_in => baseline_pwr_S,
|
282 |
|
|
baseline_inhibit_cnt_in => baseline_inhibit_cnt_S,
|
283 |
|
|
event_inhibit_cnt_in => event_inhibit_cnt_S,
|
284 |
|
|
baseline_out => baseline_S,
|
285 |
|
|
clamped_out => clamped_S,
|
286 |
|
|
del_clamp_out => del_clamp_S,
|
287 |
|
|
CFdev_clamp_out => CFdev_clamp_S,
|
288 |
|
|
cf_trace_out => cf_trace_S,
|
289 |
|
|
integral => integral_S,
|
290 |
|
|
sample_nr => sample_nr_S,
|
291 |
|
|
zeroX_out => zeroX_S,
|
292 |
|
|
event_detect_out => event_detect_S,
|
293 |
|
|
bl_gate_out => bl_gate_S,
|
294 |
|
|
ed_gate_out => ed_gate_S,
|
295 |
|
|
eventdata_valid => eventdata_valid_S,
|
296 |
|
|
eventnr_out => eventnr_S,
|
297 |
|
|
fraction => fraction_S,
|
298 |
|
|
energy => energy_S
|
299 |
|
|
);
|
300 |
|
|
|
301 |
|
|
rst_S <= rst;
|
302 |
|
|
clk_S <= clk;
|
303 |
|
|
program_S <= program;
|
304 |
|
|
baseline_enable_S <= baseline_enable;
|
305 |
|
|
double_CF_S <= double_CF_in;
|
306 |
|
|
bypass_mwd_S <= bypass_mwd;
|
307 |
|
|
bypass_reshape_S <= bypass_reshape;
|
308 |
|
|
invert_data_in_S <= invert_data_in;
|
309 |
|
|
|
310 |
|
|
data_in_S <= conv_std_logic_vector(conv_integer(unsigned(udata_in_S)), SIGNED_WIDTH) when invert_data_in_S = '0'
|
311 |
|
|
else conv_std_logic_vector(- conv_integer(unsigned(udata_in_S)), SIGNED_WIDTH);
|
312 |
|
|
|
313 |
|
|
decay_correction_S <= decay_correction_in;
|
314 |
|
|
reshape_correction_S <= reshape_correction_in;
|
315 |
|
|
threshold_S <= '0' & threshold_in; -- now it's 17 bit
|
316 |
|
|
mwd_pwr_S <= mwd_pwr_in;
|
317 |
|
|
cf_pwr_S <= cf_pwr_in;
|
318 |
|
|
cf_integral_pwr_S <= cf_integral_pwr_in;
|
319 |
|
|
baseline_pwr_S <= baseline_pwr_in;
|
320 |
|
|
baseline_inhibit_cnt_S <= baseline_inhibit_cnt_in;
|
321 |
|
|
event_inhibit_cnt_S <= event_inhibit_cnt_in;
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
mwd_switch_out <= reshape_switch_out_S;
|
325 |
|
|
baseline_out <= baseline_S;
|
326 |
|
|
clamped_out <= clamped_S;
|
327 |
|
|
del_clamp_out <= del_clamp_S;
|
328 |
|
|
CFdev_clamp_out <= CFdev_clamp_S;
|
329 |
|
|
cf_trace_out <= cf_trace_S;
|
330 |
|
|
integral <= integral_S;
|
331 |
|
|
sample_nr <= sample_nr_S;
|
332 |
|
|
zeroX_out <= zeroX_S;
|
333 |
|
|
event_detect_out <= event_detect_S;
|
334 |
|
|
bl_gate_out <= bl_gate_S;
|
335 |
|
|
ed_gate_out <= ed_gate_S;
|
336 |
|
|
eventdata_valid <= eventdata_valid_S;
|
337 |
|
|
eventnr_out <= eventnr_S;
|
338 |
|
|
fraction <= fraction_S;
|
339 |
|
|
energy <= energy_S;
|
340 |
|
|
|
341 |
|
|
-- fb_window_size <= fb_window_size_S;
|
342 |
|
|
|
343 |
|
|
-----------------------------------------------------------------------------------
|
344 |
|
|
|
345 |
|
|
-- sync : process(clk_S) -- introduced to compensate for synchronous resets (1 clock cycle delay)
|
346 |
|
|
-- begin
|
347 |
|
|
-- if (clk_S'event and clk_S = '1') then
|
348 |
|
|
enable_S <= enable;
|
349 |
|
|
udata_in_S <= data_in; -- add a sign bit to avoid disaster
|
350 |
|
|
-- end if;
|
351 |
|
|
-- end process;
|
352 |
|
|
|
353 |
|
|
end Behavioral;
|