1
|
---------------------------------------------------------------------------------------------------
|
2
|
-- Filename : usbrx_decimate.vhd
|
3
|
-- Project : OsmoSDR FPGA Firmware
|
4
|
-- Purpose : Variable decimation filter
|
5
|
-- (possible factors: 1,2,4,8,16,32,64)
|
6
|
---------------------------------------------------------------------------------------------------
|
7
|
|
8
|
-----------------------------------------------------------------------------------
|
9
|
-- Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany --
|
10
|
-- written by Matthias Kleffel --
|
11
|
-- --
|
12
|
-- This program is free software; you can redistribute it and/or modify --
|
13
|
-- it under the terms of the GNU General Public License as published by --
|
14
|
-- the Free Software Foundation as version 3 of the License, or --
|
15
|
-- --
|
16
|
-- This program is distributed in the hope that it will be useful, --
|
17
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
18
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
19
|
-- GNU General Public License V3 for more details. --
|
20
|
-- --
|
21
|
-- You should have received a copy of the GNU General Public License --
|
22
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
|
23
|
-----------------------------------------------------------------------------------
|
24
|
|
25
|
-------------------------------------------------------------------------------
|
26
|
-- decimation filter ----------------------------------------------------------
|
27
|
-------------------------------------------------------------------------------
|
28
|
|
29
|
library ieee;
|
30
|
use ieee.std_logic_1164.all;
|
31
|
use ieee.numeric_std.all;
|
32
|
library work;
|
33
|
use work.all;
|
34
|
use work.mt_toolbox.all;
|
35
|
use work.mt_filter.all;
|
36
|
use work.usbrx.all;
|
37
|
|
38
|
entity usbrx_decimate is
|
39
|
port (
|
40
|
-- common
|
41
|
clk : in std_logic;
|
42
|
reset : in std_logic;
|
43
|
|
44
|
-- config
|
45
|
config : in usbrx_fil_config_t;
|
46
|
|
47
|
-- input
|
48
|
in_clk : in std_logic;
|
49
|
in_i : in signed(15 downto 0);
|
50
|
in_q : in signed(15 downto 0);
|
51
|
|
52
|
-- output
|
53
|
out_clk : out std_logic;
|
54
|
out_i : out signed(15 downto 0);
|
55
|
out_q : out signed(15 downto 0)
|
56
|
);
|
57
|
end usbrx_decimate;
|
58
|
|
59
|
architecture rtl of usbrx_decimate is
|
60
|
|
61
|
-- config
|
62
|
signal active : std_logic_vector(5 downto 0);
|
63
|
|
64
|
-- adapted input
|
65
|
signal in_si : fir_dataword18;
|
66
|
signal in_sq : fir_dataword18;
|
67
|
|
68
|
-- filter input
|
69
|
signal fil_in_clk : std_logic_vector(5 downto 0);
|
70
|
signal fil_in_i : fir_databus18(5 downto 0);
|
71
|
signal fil_in_q : fir_databus18(5 downto 0);
|
72
|
|
73
|
-- filter output
|
74
|
signal fil_out_clk : std_logic_vector(5 downto 0);
|
75
|
signal fil_out_i : fir_databus18(5 downto 0);
|
76
|
signal fil_out_q : fir_databus18(5 downto 0);
|
77
|
|
78
|
-- unclipped output
|
79
|
signal nxt_clk : std_logic;
|
80
|
signal nxt_i : fir_dataword18;
|
81
|
signal nxt_q : fir_dataword18;
|
82
|
|
83
|
begin
|
84
|
|
85
|
-- convert input into 18bit signed
|
86
|
in_si <= signed(in_i) & "00";
|
87
|
in_sq <= signed(in_q) & "00";
|
88
|
|
89
|
-- control logic
|
90
|
process(clk)
|
91
|
variable tmp_i,tmp_q : fir_dataword18;
|
92
|
begin
|
93
|
if rising_edge(clk) then
|
94
|
|
95
|
-- get active stages
|
96
|
case to_integer(config.decim) is
|
97
|
when 0 => active <= "000000";
|
98
|
when 1 => active <= "000001";
|
99
|
when 2 => active <= "000011";
|
100
|
when 3 => active <= "000111";
|
101
|
when 4 => active <= "001111";
|
102
|
when 5 => active <= "011111";
|
103
|
when others => active <= "111111";
|
104
|
end case;
|
105
|
|
106
|
-- select output
|
107
|
case to_integer(config.decim) is
|
108
|
when 0 =>
|
109
|
nxt_clk <= in_clk;
|
110
|
nxt_i <= in_si;
|
111
|
nxt_q <= in_sq;
|
112
|
when 1 =>
|
113
|
nxt_clk <= fil_out_clk(0);
|
114
|
nxt_i <= fil_out_i(0);
|
115
|
nxt_q <= fil_out_q(0);
|
116
|
when 2 =>
|
117
|
nxt_clk <= fil_out_clk(1);
|
118
|
nxt_i <= fil_out_i(1);
|
119
|
nxt_q <= fil_out_q(1);
|
120
|
when 3 =>
|
121
|
nxt_clk <= fil_out_clk(2);
|
122
|
nxt_i <= fil_out_i(2);
|
123
|
nxt_q <= fil_out_q(2);
|
124
|
when 4 =>
|
125
|
nxt_clk <= fil_out_clk(3);
|
126
|
nxt_i <= fil_out_i(3);
|
127
|
nxt_q <= fil_out_q(3);
|
128
|
when 5 =>
|
129
|
nxt_clk <= fil_out_clk(4);
|
130
|
nxt_i <= fil_out_i(4);
|
131
|
nxt_q <= fil_out_q(4);
|
132
|
when others =>
|
133
|
nxt_clk <= fil_out_clk(5);
|
134
|
nxt_i <= fil_out_i(5);
|
135
|
nxt_q <= fil_out_q(5);
|
136
|
end case;
|
137
|
|
138
|
-- set output
|
139
|
out_clk <= nxt_clk;
|
140
|
if nxt_clk='1' then
|
141
|
tmp_i := nxt_i + 2;
|
142
|
tmp_q := nxt_q + 2;
|
143
|
out_i <= tmp_i(17 downto 2);
|
144
|
out_q <= tmp_q(17 downto 2);
|
145
|
end if;
|
146
|
|
147
|
-- handle reset
|
148
|
if reset='1' then
|
149
|
active <= (others=>'0');
|
150
|
nxt_clk <= '0';
|
151
|
nxt_i <= (others=>'0');
|
152
|
nxt_q <= (others=>'0');
|
153
|
out_clk <= '0';
|
154
|
out_i <= (others=>'0');
|
155
|
out_q <= (others=>'0');
|
156
|
end if;
|
157
|
end if;
|
158
|
end process;
|
159
|
|
160
|
|
161
|
process(in_clk,in_si,in_sq,fil_out_clk,fil_out_i,fil_out_q,active)
|
162
|
begin
|
163
|
-- feed first filter stage
|
164
|
fil_in_clk(0) <= in_clk and active(0);
|
165
|
fil_in_i(0) <= in_si;
|
166
|
fil_in_q(0) <= in_sq;
|
167
|
|
168
|
-- chain remaining filter stages
|
169
|
for i in 1 to 5 loop
|
170
|
fil_in_clk(i) <= fil_out_clk(i-1) and active(i-1);
|
171
|
fil_in_i(i) <= fil_out_i(i-1);
|
172
|
fil_in_q(i) <= fil_out_q(i-1);
|
173
|
end loop;
|
174
|
end process;
|
175
|
|
176
|
-- filter instance #1 (stage 0)
|
177
|
hbf1: entity usbrx_halfband
|
178
|
generic map (
|
179
|
N => 1
|
180
|
)
|
181
|
port map (
|
182
|
-- common
|
183
|
clk => clk,
|
184
|
reset => reset,
|
185
|
|
186
|
-- input
|
187
|
in_clk => fil_in_clk(0 downto 0),
|
188
|
in_i => fil_in_i(0 downto 0),
|
189
|
in_q => fil_in_q(0 downto 0),
|
190
|
|
191
|
-- output
|
192
|
out_clk => fil_out_clk(0 downto 0),
|
193
|
out_i => fil_out_i(0 downto 0),
|
194
|
out_q => fil_out_q(0 downto 0)
|
195
|
);
|
196
|
|
197
|
-- filter instance #2 (stage 1-5)
|
198
|
hbf2: entity usbrx_halfband
|
199
|
generic map (
|
200
|
N => 5
|
201
|
)
|
202
|
port map (
|
203
|
-- common
|
204
|
clk => clk,
|
205
|
reset => reset,
|
206
|
|
207
|
-- input
|
208
|
in_clk => fil_in_clk(5 downto 1),
|
209
|
in_i => fil_in_i(5 downto 1),
|
210
|
in_q => fil_in_q(5 downto 1),
|
211
|
|
212
|
-- output
|
213
|
out_clk => fil_out_clk(5 downto 1),
|
214
|
out_i => fil_out_i(5 downto 1),
|
215
|
out_q => fil_out_q(5 downto 1)
|
216
|
);
|
217
|
|
218
|
end rtl;
|