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

Subversion Repositories pulse_processing_algorithm

[/] [pulse_processing_algorithm/] [moving_average_programmable.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  :       moving_average_programmable 
33
-- Description  :       Moving/running average over a programmable number (power of 2) of samples
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 moving_average_programmable is
43
        generic(        MEM_PWR         : natural       := 1);
44
        port (  rst                     : in std_logic ;
45
                                clk                     : in std_logic ;
46
                                enable          : in  std_logic;
47
                                program         : in  std_logic;
48
                                avg_pwr_in      : in  std_logic_vector(7 downto 0);
49
                                data_in         : in  std_logic_vector;
50
                                data_out                : out  std_logic_vector
51
                        );
52
end moving_average_programmable;
53
 
54
 
55
architecture Behavioral of moving_average_programmable is
56
 
57
        constant        WIDTH           : natural := data_in'length;
58
        constant        E_WIDTH : natural := WIDTH + MEM_PWR;   --      data_out'length;
59
 
60
        component progdelay_pipeline
61
                generic (RAM_SIZE_PWR   : natural       := 1;
62
                                        FLEX_RAM_STYLE  : string                := "distributed");
63
                Port (clk                       : in  STD_LOGIC;
64
                                rst                     : in  STD_LOGIC;
65
                                enable          : in  STD_LOGIC;
66
                                program         : in  STD_LOGIC;
67
                                delay_in                : in    STD_LOGIC_VECTOR;
68
                                data_in         : in    STD_LOGIC_VECTOR;
69
                                data_out                : out   STD_LOGIC_VECTOR;
70
                                data_valid      : out   std_logic
71
                        );
72
        end component;
73
 
74
        component SISO_add_a
75
--              generic(        WIDTH           :       natural);
76
                port (
77
                        dataa           : IN STD_LOGIC_VECTOR;
78
                        datab           : IN STD_LOGIC_VECTOR;
79
                        result  : OUT STD_LOGIC_VECTOR
80
                );
81
        end component;
82
 
83
        component SISO_sub_a
84
                generic(        --WIDTH                 :       natural;
85
                                        A_MINUS_B       :       boolean
86
                                        );
87
                port (
88
                        dataa           : IN STD_LOGIC_VECTOR;
89
                        datab           : IN STD_LOGIC_VECTOR;
90
                        result  : OUT STD_LOGIC_VECTOR
91
                );
92
        end component;
93
 
94
        component dff_re
95
                port (rst               : in    STD_LOGIC;
96
                                clk             : in    STD_LOGIC;
97
                                enable  : IN  STD_LOGIC := '1';
98
                                d                       : in    STD_LOGIC_VECTOR;
99
                                q                       : out   STD_LOGIC_VECTOR
100
                        );
101
        end component;
102
 
103
------------------------------------------------------
104
 
105
   signal rst_S                         : std_logic := '1';
106
        signal rst_change_S             : std_logic := '1';
107
        signal rst_sum_S                        : std_logic := '1';
108
        signal clk_S                            : std_logic     := '1';
109
        signal enable_S                 : std_logic := '0';
110
        signal enable_change_S  : std_logic := '0';
111
        signal enable_sum_S             : std_logic := '0';
112
        signal program_S                        : std_logic := '0';
113
        signal avg_pwr_S                        : std_logic_vector(7 downto 0)                           := x"04";
114
        signal delay_S                          : STD_LOGIC_VECTOR(9 downto 0)                           := conv_std_logic_vector(16, 10);       -- default delay = 16
115
        signal data_in_S                        : std_logic_vector(WIDTH - 1 downto 0)           := (others      => '0');
116
        signal del_data_S                       : std_logic_vector(WIDTH - 1 downto 0)           := (others      => '0');
117
        signal sub_result_S             : std_logic_vector(WIDTH - 1 downto 0)           := (others      => '0');
118
        signal change_S                 : std_logic_vector(WIDTH - 1 downto 0)           := (others      => '0');
119
        signal wide_change_S            : std_logic_vector(E_WIDTH - 1 downto 0) := (others      => '0');
120
        signal msum_S                           : std_logic_vector(E_WIDTH - 1 downto 0) := (others      => '0');
121
        signal add_result_S             : std_logic_vector(E_WIDTH - 1 downto 0) := (others      => '0');
122
        signal data_out_S                       : std_logic_vector(WIDTH - 1 downto 0)           := (others      => '0');
123
 
124
 
125
begin
126
        mavg_pipe : progdelay_pipeline
127
                generic map(RAM_SIZE_PWR        =>      MEM_PWR,
128
                                                FLEX_RAM_STYLE  => "distributed")
129
                PORT MAP(rst                    => rst_S,
130
                                        clk                     => clk_S,
131
                                        enable          =>      enable_S,
132
                                        program         => program_S,
133
                                        delay_in                => delay_S,
134
                                        data_in         => data_in_S,
135
                                        data_out        => del_data_S,
136
                                        data_valid      => open
137
                                );
138
 
139
--      SUB = (a - b) !!
140
        sub_Msum : SISO_sub_a
141
                GENERIC MAP(--WIDTH             =>WIDTH,
142
                                                A_MINUS_B       =>      true)
143
                PORT MAP(dataa   => data_in_S,
144
                                        datab    => del_data_S,
145
                                        result => sub_result_S
146
                                );
147
 
148
        change_reg : dff_re
149
                PORT MAP(rst            => rst_change_S,
150
                                        clk             =>      clk_S,
151
                                        enable  =>      enable_S,
152
                                        d                       =>      sub_result_S,
153
                                        q                       =>      change_S
154
                                );
155
 
156
        wide_change_S           <= conv_std_logic_vector(conv_integer(change_S), E_WIDTH);
157
        add_Msum : SISO_add_a
158
--              GENERIC MAP (WIDTH => E_WIDTH)
159
                PORT MAP(dataa          => wide_change_S,
160
                                        datab           => msum_S,
161
                                        result  => add_result_S
162
                                );
163
 
164
        msum_reg : dff_re
165
                PORT MAP(rst            => rst_sum_S,
166
                                        clk             =>      clk_S,
167
                                        enable  =>      enable_sum_S,
168
                                        d                       =>      add_result_S,
169
                                        q                       =>      msum_S
170
                                );
171
 
172
        clk_S                           <= clk;                                                                                                 -- connect clk PORT to internal clk-signal
173
        rst_S                           <= rst;
174
        enable_S                        <= enable;
175
        program_S                       <= program;
176
        avg_pwr_S                       <= avg_pwr_in;
177
        delay_S                         <= conv_std_logic_vector(((2**conv_integer(avg_pwr_S))), 10);
178
 
179
        data_in_S                       <= data_in;
180
        data_out                                <= data_out_S;
181
 
182
 
183
        reset_proc : process(clk_S)
184
        begin
185
                if rising_edge(clk_S) then
186
                        if (rst_S = '1') or (program_S = '1') then
187
                                rst_change_S            <= '1';
188
                                rst_sum_S                       <= '1';
189
                        else
190
                                rst_change_S            <= (rst_S or program_S);                --rst_delay_s;
191
                                rst_sum_S                       <= rst_change_S;
192
                                enable_sum_S            <= enable_S;            --rst_delay_s;
193
                end if;
194
                end if;
195
        end process;
196
 
197
 
198
        data_out_S      <=      msum_S((conv_integer(avg_pwr_S) + WIDTH - 1)  downto conv_integer(avg_pwr_S));
199
 
200
end Behavioral;
201
 

powered by: WebSVN 2.1.0

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