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: baseline_follower.vhd
|
33 |
|
|
-- Description: Combination of data-delay and programmable-moving_average
|
34 |
|
|
-- Because you normally don't want to use event-data for baseline calculation, the
|
35 |
|
|
-- datacollection is inhibited when event occurs (gated). In order to overcome
|
36 |
|
|
-- latency of event-detection the baseline-follower has a history-buffer. This
|
37 |
|
|
-- buffer has a programmable size.
|
38 |
|
|
-- The size of the baseline-moving average is programmable as a power of 2.
|
39 |
|
|
--
|
40 |
|
|
-----------------------------------------------------------------------------------------------
|
41 |
|
|
library IEEE;
|
42 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
43 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
44 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
45 |
|
|
|
46 |
|
|
entity baseline_follower is
|
47 |
|
|
generic( WINDOW_PWR : natural := 1; -- defines the maximum window in which event disturbance is seen
|
48 |
|
|
MAX_BASELINE_PWR : natural := 1 -- size of the baseline window
|
49 |
|
|
);
|
50 |
|
|
Port ( rst : in STD_LOGIC;
|
51 |
|
|
clk : in STD_LOGIC;
|
52 |
|
|
enable : in STD_LOGIC;
|
53 |
|
|
program : in STD_LOGIC;
|
54 |
|
|
gate : in STD_LOGIC;
|
55 |
|
|
baseline_pwr_in : in STD_LOGIC_VECTOR(7 downto 0);
|
56 |
|
|
buffer_size_in : in STD_LOGIC_VECTOR(7 downto 0); --
|
57 |
|
|
data_in : in STD_LOGIC_VECTOR;
|
58 |
|
|
data_out : out STD_LOGIC_VECTOR;
|
59 |
|
|
buffer_data_valid : out STD_LOGIC
|
60 |
|
|
);
|
61 |
|
|
end baseline_follower;
|
62 |
|
|
|
63 |
|
|
architecture Behavioral of baseline_follower is
|
64 |
|
|
|
65 |
|
|
constant WIDTH : natural := data_in'length;
|
66 |
|
|
constant B_WIDTH : natural := WIDTH + MAX_BASELINE_PWR; -- extended width for MAX_BASELINE_PWR
|
67 |
|
|
-- constant BASELINE_SIZE : natural := 2**BASELINE_PWR; -- extended width for BASELINE_PWR
|
68 |
|
|
constant M2_PWR : natural := WINDOW_PWR + 1;
|
69 |
|
|
constant M2 : natural := 2**M2_PWR; -- M is the MWD window-size; M2= 2*M
|
70 |
|
|
|
71 |
|
|
component progdelay_pipeline
|
72 |
|
|
generic( RAM_SIZE_PWR : natural;
|
73 |
|
|
FLEX_RAM_STYLE : string
|
74 |
|
|
);
|
75 |
|
|
port (rst : IN STD_LOGIC ;
|
76 |
|
|
clk : IN STD_LOGIC ;
|
77 |
|
|
enable : IN STD_LOGIC := '1';
|
78 |
|
|
program : in STD_LOGIC;
|
79 |
|
|
delay_in : in STD_LOGIC_VECTOR;
|
80 |
|
|
data_in : IN STD_LOGIC_VECTOR;
|
81 |
|
|
data_out : OUT STD_LOGIC_VECTOR;
|
82 |
|
|
data_valid : OUT STD_LOGIC
|
83 |
|
|
);
|
84 |
|
|
end component;
|
85 |
|
|
|
86 |
|
|
component moving_average_programmable
|
87 |
|
|
generic(MEM_PWR : natural);
|
88 |
|
|
port (rst : in std_logic;
|
89 |
|
|
clk : in std_logic;
|
90 |
|
|
enable : in std_logic;
|
91 |
|
|
program : in std_logic;
|
92 |
|
|
avg_pwr_in : in std_logic_vector(7 downto 0);
|
93 |
|
|
data_in : in std_logic_vector;
|
94 |
|
|
data_out : out std_logic_vector
|
95 |
|
|
);
|
96 |
|
|
end component;
|
97 |
|
|
-- component moving_average
|
98 |
|
|
-- generic( WINDOW_PWR : natural;
|
99 |
|
|
-- WINDOW_SIZE : natural
|
100 |
|
|
-- );
|
101 |
|
|
-- Port ( rst : IN STD_LOGIC ;
|
102 |
|
|
-- clk : IN STD_LOGIC ;
|
103 |
|
|
-- enable : in STD_LOGIC := '1';
|
104 |
|
|
-- data_in : in STD_LOGIC_VECTOR;
|
105 |
|
|
-- data_out : out STD_LOGIC_VECTOR
|
106 |
|
|
-- );
|
107 |
|
|
-- end component;
|
108 |
|
|
-----------------------------------------------------------------------
|
109 |
|
|
|
110 |
|
|
signal rst_S : std_logic := '1';
|
111 |
|
|
signal clk_S : std_logic := '0';
|
112 |
|
|
signal enable_S : std_logic := '0';
|
113 |
|
|
signal program_S : std_logic := '0';
|
114 |
|
|
signal data_in_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
115 |
|
|
signal M2del_data_S : std_logic_vector (WIDTH - 1 downto 0) := (others => '0');
|
116 |
|
|
signal baseline_S : STD_LOGIC_VECTOR (WIDTH - 1 downto 0) := (others => '0');
|
117 |
|
|
signal baseline_gate_S : STD_LOGIC := '0';
|
118 |
|
|
signal buffer_size_S : STD_LOGIC_VECTOR (7 downto 0) := (others => '0');
|
119 |
|
|
signal baseline_pwr_S : STD_LOGIC_VECTOR (7 downto 0) := (others => '0');
|
120 |
|
|
signal deldata_valid_S : STD_LOGIC := '0';
|
121 |
|
|
|
122 |
|
|
-----------------------------------------------------------------------
|
123 |
|
|
|
124 |
|
|
begin
|
125 |
|
|
-- M2 pipe is to prevent an event (pulse) from poluting the baseline
|
126 |
|
|
M2_pipe : progdelay_pipeline
|
127 |
|
|
generic map(RAM_SIZE_PWR => M2_PWR,
|
128 |
|
|
FLEX_RAM_STYLE => "distributed"
|
129 |
|
|
)
|
130 |
|
|
PORT MAP(rst => rst_S,
|
131 |
|
|
clk => clk_S,
|
132 |
|
|
enable => enable_S, -- not gated !! just keep the record.
|
133 |
|
|
program => program_S,
|
134 |
|
|
delay_in => buffer_size_S, -- data delay is equal to the inhibit period
|
135 |
|
|
data_in => data_in_S,
|
136 |
|
|
data_out => M2del_data_S,
|
137 |
|
|
data_valid => deldata_valid_S -- Tells you when the pipe has been filled an is enabled
|
138 |
|
|
);
|
139 |
|
|
|
140 |
|
|
-- baseline_smooth : moving_average
|
141 |
|
|
-- generic map(WINDOW_PWR => BASELINE_PWR,
|
142 |
|
|
-- WINDOW_SIZE => BASELINE_SIZE
|
143 |
|
|
-- )
|
144 |
|
|
-- port map ( rst => rst_S,
|
145 |
|
|
-- clk => clk_S,
|
146 |
|
|
-- enable => baseline_gate_S,
|
147 |
|
|
-- data_in => M2del_data_S,
|
148 |
|
|
-- data_out => baseline_S
|
149 |
|
|
-- );
|
150 |
|
|
baseline_smooth : moving_average_programmable
|
151 |
|
|
generic map(MEM_PWR => MAX_BASELINE_PWR)
|
152 |
|
|
port map( rst => rst_S,
|
153 |
|
|
clk => clk_S,
|
154 |
|
|
enable => baseline_gate_S,
|
155 |
|
|
program => program_S,
|
156 |
|
|
avg_pwr_in => baseline_pwr_S,
|
157 |
|
|
data_in => M2del_data_S,
|
158 |
|
|
data_out => baseline_S
|
159 |
|
|
);
|
160 |
|
|
|
161 |
|
|
-- hook-up the external ports to the internal signals -----------------
|
162 |
|
|
rst_S <= rst;
|
163 |
|
|
clk_S <= clk;
|
164 |
|
|
enable_S <= enable;
|
165 |
|
|
program_S <= program;
|
166 |
|
|
baseline_gate_S <= deldata_valid_S and gate;
|
167 |
|
|
baseline_pwr_S <= baseline_pwr_in;
|
168 |
|
|
buffer_size_S <= buffer_size_in;
|
169 |
|
|
data_in_S <= data_in;
|
170 |
|
|
data_out <= baseline_S;
|
171 |
|
|
buffer_data_valid <= deldata_valid_S;
|
172 |
|
|
|
173 |
|
|
end Behavioral;
|