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

Subversion Repositories astron_r2sdf_fft

[/] [astron_r2sdf_fft/] [trunk/] [rTwoSDF.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
--------------------------------------------------------------------------------
2
--      Description      :    Entity, Architecture
3
--------------------------------------------------------------------------------
4
--   Author: Raj Thilak Rajan : rajan at astron.nl: Nov 2009
5
--   Copyright (C) 2009-2010
6
--   ASTRON (Netherlands Institute for Radio Astronomy)
7
--   P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
8
--
9
--   This file is part of the UniBoard software suite.
10
--   The file is free software: you can redistribute it and/or modify
11
--   it under the terms of the GNU General Public License as published by
12
--   the Free Software Foundation, either version 3 of the License, or
13
--   (at your option) any later version.
14
--
15
--   This program is distributed in the hope that it will be useful,
16
--   but WITHOUT ANY WARRANTY; without even the implied warranty of
17
--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
--   GNU General Public License for more details.
19
--
20
--   You should have received a copy of the GNU General Public License
21
--   along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
--------------------------------------------------------------------------------
23
--------------------------------------------------------------------------------
24
 
25
-- Purpose: Pipelined radix 2 FFT
26
-- Description: ASTRON-RP-755
27
-- Remarks: doc/readme.txt
28
 
29
 
30
library ieee, common_pkg_lib, common_requantize_lib;
31
use IEEE.std_logic_1164.all;
32
use common_pkg_lib.common_pkg.all;
33
use work.twiddlesPkg.all;
34
use work.rTwoSDFPkg.all;
35
 
36
entity rTwoSDF is
37
  generic (
38
    -- generics for the FFT    
39
    g_nof_chan    : natural := 0;     -- Exponent of nr of subbands (0 means 1 subband)
40
    g_use_reorder : boolean := true;
41
    g_in_dat_w    : natural := 8;     -- number of input bits
42
    g_out_dat_w   : natural := 14;    -- number of output bits
43
    g_stage_dat_w : natural := 18;    -- number of bits used between the stages
44
    g_guard_w     : natural := 2;     -- guard bits are used to avoid overflow in single FFT stage.   
45
    g_nof_points  : natural := 1024;  -- N point FFT
46
    -- generics for rTwoSDFStage
47
    g_pipeline    : t_fft_pipeline := c_fft_pipeline
48
  );
49
  port (
50
    clk      : in  std_logic;
51
    rst      : in  std_logic := '0';
52
    in_re    : in  std_logic_vector(g_in_dat_w-1 downto 0);
53
    in_im    : in  std_logic_vector(g_in_dat_w-1 downto 0);
54
    in_val   : in  std_logic := '1';
55
    out_re   : out std_logic_vector(g_out_dat_w-1 downto 0);
56
    out_im   : out std_logic_vector(g_out_dat_w-1 downto 0);
57
    out_val  : out std_logic
58
  );
59
end entity rTwoSDF;
60
 
61
architecture str of rTwoSDF is
62
 
63
  constant c_nof_stages         : natural := ceil_log2(g_nof_points);
64
  constant c_stage_offset       : natural := 0;                               -- In "normal" pipelined fft operation the stage offset is 0
65
  constant c_twiddle_offset     : natural := 0;                               -- In "normal" pipelined fft operation the twiddle offset is 0
66
 
67
  -- Round last stage output to g_out_dat_w if g_out_dat_w < g_stage_dat_w else resize to g_out_dat_w
68
  constant c_out_scale_w        : integer := g_stage_dat_w - g_out_dat_w;     -- Estimate number of LSBs to round throw away when > 0 or insert when < 0
69
 
70
  -- Scale the input to make optimal use of the g_stage_dat_w of the stages, using a margin of g_guard_w to account for factor > 2 gain of the first stage
71
  constant c_in_scale_w         : natural := g_stage_dat_w - g_guard_w - g_in_dat_w; -- use type natural instead of integer to implicitly ensure that the g_stage_dat_w >= g_input_dat_w
72
 
73
  -- number the stage instances from c_nof_stages:1
74
  -- . the data input for the first stage has index c_nof_stages
75
  -- . the data output of the last stage has index 0
76
  type t_data_arr is array(c_nof_stages downto 0) of std_logic_vector(g_stage_dat_w-1 downto 0);
77
 
78
  signal data_re      : t_data_arr;
79
  signal data_im      : t_data_arr;
80
  signal data_val     : std_logic_vector(c_nof_stages downto 0):= (others=>'0');
81
 
82
  signal out_cplx     : std_logic_vector(2*g_stage_dat_w-1 downto 0);
83
  signal raw_out_cplx : std_logic_vector(2*g_stage_dat_w-1 downto 0);
84
  signal raw_out_re   : std_logic_vector(g_stage_dat_w-1 downto 0);
85
  signal raw_out_im   : std_logic_vector(g_stage_dat_w-1 downto 0);
86
  signal raw_out_val  : std_logic;
87
 
88
begin
89
 
90
  -- Inputs
91
  data_re( c_nof_stages) <= scale_and_resize_svec(in_re, c_in_scale_w, g_stage_dat_w);
92
  data_im( c_nof_stages) <= scale_and_resize_svec(in_im, c_in_scale_w, g_stage_dat_w);
93
  data_val(c_nof_stages) <= in_val;
94
 
95
  ------------------------------------------------------------------------------
96
  -- pipelined FFT stages
97
  ------------------------------------------------------------------------------
98
 
99
  gen_fft: for stage in c_nof_stages downto 1 generate
100
    u_stage : entity work.rTwoSDFStage
101
    generic map (
102
      g_nof_chan       => g_nof_chan,
103
      g_stage          => stage,
104
      g_stage_offset   => c_stage_offset,
105
      g_twiddle_offset => c_twiddle_offset,
106
      g_scale_enable   => sel_a_b(stage <= g_guard_w, FALSE, TRUE),  -- On average all stages have a gain factor of 2 therefore each stage needs to round 1 bit except for the last g_guard_w nof stages due to the input c_in_scale_w
107
      g_pipeline       => g_pipeline
108
    )
109
    port map (
110
      clk       => clk,
111
      rst       => rst,
112
      in_re     => data_re(stage),
113
      in_im     => data_im(stage),
114
      in_val    => data_val(stage),
115
      out_re    => data_re(stage-1),
116
      out_im    => data_im(stage-1),
117
      out_val   => data_val(stage-1)
118
    );
119
  end generate;
120
 
121
  ------------------------------------------------------------------------------
122
  -- Optional output reorder
123
  ------------------------------------------------------------------------------
124
 
125
  no_reorder : if g_use_reorder=false generate
126
    raw_out_re  <= data_re(0);
127
    raw_out_im  <= data_im(0);
128
    raw_out_val <= data_val(0);
129
  end generate;
130
 
131
  gen_reorder : if g_use_reorder=true generate
132
    raw_out_cplx <= data_im(0) & data_re(0);
133
 
134
    raw_out_re <= out_cplx(  g_stage_dat_w-1 downto 0);
135
    raw_out_im <= out_cplx(2*g_stage_dat_w-1 downto g_stage_dat_w);
136
 
137
    u_cplx: entity work.rTwoOrder
138
    generic map (
139
      g_nof_points => g_nof_points,
140
      g_nof_chan   => g_nof_chan
141
    )
142
    port map (
143
      clk     => clk,
144
      rst     => rst,
145
      in_dat  => raw_out_cplx,
146
      in_val  => data_val(0),
147
      out_dat => out_cplx,
148
      out_val => raw_out_val
149
    );
150
  end generate;
151
 
152
  ------------------------------------------------------------------------------
153
  -- pipelined FFT output requantization
154
  ------------------------------------------------------------------------------
155
  u_requantize_re : entity common_requantize_lib.common_requantize
156
  generic map (
157
    g_representation      => "SIGNED",
158
    g_lsb_w               => c_out_scale_w,
159
    g_lsb_round           => TRUE,
160
    g_lsb_round_clip      => FALSE,
161
    g_msb_clip            => FALSE,
162
    g_msb_clip_symmetric  => FALSE,
163
    g_pipeline_remove_lsb => 0,
164
    g_pipeline_remove_msb => 0,
165
    g_in_dat_w            => g_stage_dat_w,
166
    g_out_dat_w           => g_out_dat_w
167
  )
168
  port map (
169
    clk        => clk,
170
    clken      => '1',
171
    in_dat     => raw_out_re,
172
    out_dat    => out_re,
173
    out_ovr    => open
174
  );
175
 
176
  u_requantize_im : entity common_requantize_lib.common_requantize
177
  generic map (
178
    g_representation      => "SIGNED",
179
    g_lsb_w               => c_out_scale_w,
180
    g_lsb_round           => TRUE,
181
    g_lsb_round_clip      => FALSE,
182
    g_msb_clip            => FALSE,
183
    g_msb_clip_symmetric  => FALSE,
184
    g_pipeline_remove_lsb => 0,
185
    g_pipeline_remove_msb => 0,
186
    g_in_dat_w            => g_stage_dat_w,
187
    g_out_dat_w           => g_out_dat_w
188
  )
189
  port map (
190
    clk        => clk,
191
    clken      => '1',
192
    in_dat     => raw_out_im,
193
    out_dat    => out_im,
194
    out_ovr    => open
195
  );
196
 
197
  -- Valid Output
198
  out_val <= raw_out_val;
199
 
200
end str;

powered by: WebSVN 2.1.0

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