OpenCores
URL https://opencores.org/ocsvn/pulse_processing_algorithm/pulse_processing_algorithm/trunk

Subversion Repositories pulse_processing_algorithm

[/] [pulse_processing_algorithm/] [CF_zeroX.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
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  :       CF_zeroX
33
-- Description  :       Zero-crossing detection
34
--      Inputs          :       
35
--      Outputs         :       
36
-----------------------------------------------------------------------------------------------
37
--      Generics                :       
38
--      Parameters      :
39
-----------------------------------------------------------------------------------------------
40
library IEEE;
41
use IEEE.STD_LOGIC_1164.ALL;
42
use IEEE.STD_LOGIC_ARITH.ALL;
43
use IEEE.STD_LOGIC_SIGNED.ALL;
44
 
45
entity CF_zeroX is
46
        generic(        BASE_WINDOW_PWR         :       natural :=      1;
47
                                ZEROX_WINDOW_PWR                :       natural :=      1;
48
                                ZEROX_THRESHOLD_PWR     :       natural :=      1
49
                                );
50
        Port (  rst                     : in  STD_LOGIC;
51
                                clk                     : in  STD_LOGIC;
52
                                enable          : in  STD_LOGIC := '1';
53
                                data_in         : in  STD_LOGIC_VECTOR;
54
                                zeroX_out       : out   STD_LOGIC
55
                        );
56
end CF_zeroX;
57
 
58
architecture Behavioral of CF_zeroX is
59
 
60
        constant        WIDTH                                           : natural := data_in'length;
61
        constant        ZEROX_WINDOW                    : natural := 2**ZEROX_WINDOW_PWR;
62
        constant        INHIBIT_COUNT                   : natural := ZEROX_WINDOW;                                              -- gating period after zero-cross-detection
63
 
64
        component pipeline
65
                generic(        RAM_SIZE_PWR    : natural;
66
                                        DEPTH                           :       natural);
67
                port (  rst             : IN STD_LOGIC ;
68
                                        clk             : IN STD_LOGIC ;
69
                                        enable  : IN  STD_LOGIC := '1';
70
                                        data_in : IN STD_LOGIC_VECTOR;
71
                                        data_out        : OUT STD_LOGIC_VECTOR
72
                                );
73
        end component;
74
 
75
        component compare_a2b is
76
                Port (  clk     : std_logic;
77
                                        a               : in    STD_LOGIC_VECTOR;
78
                                        b               : in    STD_LOGIC_VECTOR;
79
                                        lt              : out   STD_LOGIC;
80
                                        gt              : out   STD_LOGIC
81
                                );
82
        end component;
83
 
84
-----------------------------------------------------------------------
85
 
86
        signal rst_S                            : std_logic := '1';
87
        signal clk_S                            : std_logic := '0';
88
        signal enable_S                 : std_logic := '0';
89
        signal data_in_S                        : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
90
        signal del1_data_S              : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
91
        signal del2_data_S              : std_logic_vector(WIDTH - 1 downto 0) := (others => '0');
92
        signal zeroX_S                          : std_logic := '0';
93
        signal front1_hi_enuf_S : std_logic := '0';
94
        signal front2_hi_enuf_S : std_logic := '0';
95
        signal end_lo_enuf_S            : std_logic := '0';
96
        signal inhibited_S              : std_logic := '0';
97
        signal inhibit_cnt_S            : std_logic_vector(ZEROX_WINDOW_PWR + 1 downto 0) := conv_std_logic_vector(INHIBIT_COUNT,ZEROX_WINDOW_PWR + 2);
98
 
99
        signal p1_threshold_S           : std_logic_vector(WIDTH - 1 downto 0) := conv_std_logic_vector(2,WIDTH);        -- add a SIGN bit !!!
100
        signal p2_threshold_S           : std_logic_vector(WIDTH - 1 downto 0) := conv_std_logic_vector(1,WIDTH);        -- add a SIGN bit !!!
101
        signal n_threshold_S            : std_logic_vector(WIDTH - 1 downto 0) := conv_std_logic_vector(-1,WIDTH);       -- add a SIGN bit !!!
102
 
103
---------------------------------------------------------------------------------------------------------
104
        begin
105
 
106
                zerox_win_proc : process(rst_S, clk_S, enable_S, data_in_S)
107
                        begin
108
                                if (clk_S'event and clk_S = '1') then
109
                                        if (rst_S = '1') then
110
                                                del1_data_S     <=      (others => '0');
111
                                                del2_data_S     <=      (others => '0');
112
                                        else
113
                                                if (enable_S = '1') then
114
                                                        del1_data_S     <= data_in_S;
115
                                                        del2_data_S     <= del1_data_S;
116
                                                end if;
117
                                        end if;
118
                                end if;
119
                end process;
120
 
121
                p1_threshold    : compare_a2b                                                   -- check if data at the front of the zerox-window exceeds the positive threshold
122
                        port map        (       clk     => clk_S,
123
                                                        a               =>      data_in_S,
124
                                                        b               =>      p1_threshold_S,
125
                                                        lt              =>      open,
126
                                                        gt              =>      front1_hi_enuf_S
127
                                                );
128
 
129
                p2_threshold    : compare_a2b                                                   -- check if data at the front of the zerox-window exceeds the positive threshold
130
                        port map        (       clk     => clk_S,
131
                                                        a               =>      del1_data_S,
132
                                                        b               =>      p2_threshold_S,
133
                                                        lt              =>      open,
134
                                                        gt              =>      front2_hi_enuf_S
135
                                                );
136
 
137
                n_threshold     : compare_a2b                                                   -- check if data at the end of the zerox-window goes below the 1st negative threshold
138
                        port map        (       clk     => clk_S,
139
                                                        a               =>      del2_data_S,
140
                                                        b               =>      n_threshold_S,
141
                                                        lt              =>      end_lo_enuf_S,
142
                                                        gt              =>      open
143
                                                );
144
 
145
                inhibit : compare_a2b                                                   -- check if data at the end of the zerox-window stays above the 2nd negative threshold
146
                        port map        (       clk     => clk_S,
147
                                                        a               =>      inhibit_cnt_S,
148
                                                        b               =>      conv_std_logic_vector(0, inhibit_cnt_S'length),
149
                                                        lt              =>      open,
150
                                                        gt              =>      inhibited_S
151
                                                );
152
 
153
 
154
                clk_S                   <= clk;                                                                                                 -- connect clk PORT to internal clk-signal
155
                rst_S                   <= rst;
156
                enable_S        <= enable;
157
                data_in_S       <= data_in;
158
--              zeroX_S         <=      front1_hi_enuf_S and front2_hi_enuf_S and end_lo_enuf_S and not(inhibited_S);
159
                zeroX_out       <= zerox_S;
160
                -- positive threshold = 4*negative threshold... constant-fraction of 4
161
                p1_threshold_S  <= conv_std_logic_vector(2**(ZEROX_THRESHOLD_PWR + 1), WIDTH);
162
                p2_threshold_S  <= conv_std_logic_vector(2**(ZEROX_THRESHOLD_PWR), WIDTH);
163
                n_threshold_S   <= conv_std_logic_vector(-(2**ZEROX_THRESHOLD_PWR), WIDTH);
164
 
165
                zeroX_inhibit : process (clk_S, rst_S, enable_S)
166
                begin
167
                        if (clk_S'event and clk_S = '1') then
168
                                if (rst_S = '1') then
169
                                        zeroX_S <= '0';
170
                                else
171
                                        if  (enable_S = '1') then
172
                                                --zeroX_out <= zeroX_S;
173
                                                zeroX_S         <=      front1_hi_enuf_S and front2_hi_enuf_S and end_lo_enuf_S and not(inhibited_S);
174
                                        end if;
175
 
176
                                        if  (enable_S = '1') then
177
                                                if (zeroX_S = '1') then
178
                                                        inhibit_cnt_S <= conv_std_logic_vector(INHIBIT_COUNT,ZEROX_WINDOW_PWR + 2);
179
                                                else
180
                                                        if (inhibit_cnt_S > 0) then
181
                                                                inhibit_cnt_S <= inhibit_cnt_S - 1;
182
                                                        end if;
183
                                                end if;
184
                                        end if;
185
                                end if;
186
                        end if;
187
                end process;
188
 
189
end Behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.