1 |
10 |
sradio |
---------------------------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Title : test bench
|
4 |
|
|
-- Design : cfft
|
5 |
|
|
-- Author : henning larsen
|
6 |
|
|
-- email :
|
7 |
|
|
--
|
8 |
|
|
---------------------------------------------------------------------------------------------------
|
9 |
|
|
--
|
10 |
|
|
-- File : tb_cfft1024x12.vhd
|
11 |
|
|
--
|
12 |
|
|
---------------------------------------------------------------------------------------------------
|
13 |
|
|
--
|
14 |
|
|
-- Description :
|
15 |
|
|
--
|
16 |
|
|
-- Simple "testbench" for cfft1024x12. It is realy just an excitation of inputs
|
17 |
|
|
-- The output has to be evaluated manually. run for 125 us with current settings.
|
18 |
|
|
-- Input is a dual sinsoid with constant amplitudes, and a DC value.
|
19 |
|
|
-- Input is real valued only. A calculation of the power spectrum, and a frequency bin
|
20 |
|
|
-- counter is included, but no reordering of output sequence is performed.
|
21 |
|
|
-- Frequencies are easy to select such that a minimum of spill into side bins is obtained.
|
22 |
|
|
-- Beware of the posibilty of saturation in the output. For single sinsoide,the saturation limit
|
23 |
|
|
-- is 2^14/29.4=557 units of input amplitude.
|
24 |
|
|
--
|
25 |
|
|
-- henning larsen
|
26 |
|
|
--
|
27 |
|
|
---------------------------------------------------------------------------------------------------
|
28 |
|
|
--
|
29 |
|
|
-- Revisions : 0
|
30 |
|
|
-- Revision Number : 1
|
31 |
|
|
-- Version : 1.1.0
|
32 |
|
|
-- Date : Nov 21 2002
|
33 |
|
|
-- Modifier : ZHAO Ming
|
34 |
|
|
-- Desccription : init release
|
35 |
|
|
-- compare output position
|
36 |
|
|
--
|
37 |
|
|
---------------------------------------------------------------------------------------------------
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
LIBRARY ieee;
|
42 |
|
|
USE ieee.std_logic_1164.all;
|
43 |
|
|
USE ieee.std_logic_arith.all;
|
44 |
|
|
USE ieee.math_real.all;
|
45 |
|
|
USE ieee.std_logic_signed.all;
|
46 |
|
|
|
47 |
|
|
ENTITY cfft1024x12_tester1 IS
|
48 |
|
|
END cfft1024x12_tester1 ;
|
49 |
|
|
ARCHITECTURE tester OF cfft1024x12_tester1 IS
|
50 |
|
|
-- Component Declarations
|
51 |
|
|
COMPONENT cfft1024X12
|
52 |
|
|
PORT (
|
53 |
|
|
clk : IN STD_LOGIC ;
|
54 |
|
|
rst : IN STD_LOGIC ;
|
55 |
|
|
start : IN STD_LOGIC ;
|
56 |
|
|
inv : IN std_logic ;
|
57 |
|
|
Iin : IN STD_LOGIC_VECTOR (11 DOWNTO 0);
|
58 |
|
|
Qin : IN STD_LOGIC_VECTOR (11 DOWNTO 0);
|
59 |
|
|
inputbusy : OUT STD_LOGIC ;
|
60 |
|
|
outdataen : OUT STD_LOGIC ;
|
61 |
|
|
Iout : OUT STD_LOGIC_VECTOR (13 DOWNTO 0);
|
62 |
|
|
Qout : OUT STD_LOGIC_VECTOR (13 DOWNTO 0);
|
63 |
|
|
OutPosition : out STD_LOGIC_VECTOR( 9 downto 0 )
|
64 |
|
|
);
|
65 |
|
|
END COMPONENT;
|
66 |
|
|
|
67 |
|
|
constant Tck_half : time:=10 ns;
|
68 |
|
|
constant Tckhalf : real:=10.0e-9;-- real value eqv of time, there is some conversion function
|
69 |
|
|
-- for this but could not find/remember.
|
70 |
|
|
constant ampl1 : real:=100.0;-- max amplitude is roughly 550=2^14/29.4 to avoid sturation in output
|
71 |
|
|
constant ampl2 : real:=200.0; -- .. but see intro comments
|
72 |
|
|
constant f1 : real := 100.0/TckHalf/2.0/1024.0;-- bin number =100
|
73 |
|
|
constant f2 : real := 33.0/TckHalf/2.0/1024.0;-- bin number =33
|
74 |
|
|
constant dc : real:=100.0;--bin number=0
|
75 |
|
|
|
76 |
|
|
signal c1,c2,cout: real;
|
77 |
|
|
signal clock : std_logic:='0';
|
78 |
|
|
signal reset : std_logic:='0';
|
79 |
|
|
signal start : std_logic:='0';
|
80 |
|
|
signal inv : std_logic ;
|
81 |
|
|
signal Iin : STD_LOGIC_VECTOR (11 DOWNTO 0);
|
82 |
|
|
signal Qin : STD_LOGIC_VECTOR (11 DOWNTO 0);
|
83 |
|
|
signal inputbusy : STD_LOGIC:='0' ;
|
84 |
|
|
signal outdataen : STD_LOGIC:='0' ;
|
85 |
|
|
signal Iout : STD_LOGIC_VECTOR (13 DOWNTO 0);
|
86 |
|
|
signal Qout : STD_LOGIC_VECTOR (13 DOWNTO 0);
|
87 |
|
|
signal amp : real; -- power spectrum
|
88 |
|
|
signal bitRev : STD_LOGIC_VECTOR (9 DOWNTO 0);-- bin counter
|
89 |
|
|
signal OutPosition : STD_LOGIC_VECTOR( 9 downto 0 );
|
90 |
|
|
|
91 |
|
|
BEGIN
|
92 |
|
|
-- Instance port mappings.
|
93 |
|
|
I0 : cfft1024X12
|
94 |
|
|
PORT MAP (
|
95 |
|
|
clk => clock,
|
96 |
|
|
rst => reset,
|
97 |
|
|
start => start,
|
98 |
|
|
inv => inv,
|
99 |
|
|
Iin => Iin,
|
100 |
|
|
Qin => Qin,
|
101 |
|
|
inputbusy => inputbusy,
|
102 |
|
|
outdataen => outdataen,
|
103 |
|
|
Iout => Iout,
|
104 |
|
|
Qout => Qout,
|
105 |
|
|
OutPosition => OutPosition
|
106 |
|
|
);
|
107 |
|
|
|
108 |
|
|
----------------------------------------------------------------------------
|
109 |
|
|
--
|
110 |
|
|
-- control signals ,setup
|
111 |
|
|
clock <= not clock after Tck_half;
|
112 |
|
|
reset <= '1', '0' after 2*Tck_half;
|
113 |
|
|
start <= '0', '1' after 3*Tck_half, '0' after 5*Tck_half;-- only one FFT is done
|
114 |
|
|
inv <= '0';-- FFT
|
115 |
|
|
|
116 |
|
|
----------------------------------------------------------------------------
|
117 |
|
|
--
|
118 |
|
|
sin_gen: process(clock, reset)
|
119 |
|
|
variable tid : real;
|
120 |
|
|
variable TM : real :=0.0 ;
|
121 |
|
|
begin
|
122 |
|
|
if Reset = '1' then
|
123 |
|
|
c1 <= 0.0;
|
124 |
|
|
c2 <= 0.0;
|
125 |
|
|
Iin<="000000000000" ;
|
126 |
|
|
Qin<="000000000000" ;
|
127 |
|
|
TM := 0.0;
|
128 |
|
|
tid := TM;
|
129 |
|
|
else
|
130 |
|
|
if clock'event and clock = '1' then
|
131 |
|
|
TM := TM + Tckhalf*2.0;
|
132 |
|
|
tid := TM;
|
133 |
|
|
c1 <= (ampl1 * sin(2.0*math_pi*f1*tid));
|
134 |
|
|
c2 <= (ampl2 * sin(2.0*math_pi*f2*tid));
|
135 |
|
|
cout <= c1+c2+dc;
|
136 |
|
|
Iin <= conv_std_logic_vector(integer(cout),Iin'length);
|
137 |
|
|
Qin <="000000000000" ;
|
138 |
|
|
end if;
|
139 |
|
|
end if;
|
140 |
|
|
end process sin_gen;
|
141 |
|
|
----------------------------------------------------------------------------
|
142 |
|
|
--
|
143 |
|
|
--Output power spectrum, normalized with the gain of 29.4
|
144 |
|
|
amp <= sqrt(real(CONV_integer(Iout)) * real(CONV_integer(Iout))
|
145 |
|
|
+ real(CONV_integer(Qout)) * real(CONV_integer(Qout)))/29.4;
|
146 |
|
|
----------------------------------------------------------------------------
|
147 |
|
|
--
|
148 |
|
|
-- radix 4 bit reversed counter
|
149 |
|
|
radix4cnt: process (clock)
|
150 |
|
|
variable cntr: std_logic_vector ( 9 downto 0);
|
151 |
|
|
begin
|
152 |
|
|
if rising_edge(clock) then
|
153 |
|
|
if outdataen='1' then
|
154 |
|
|
cntr:=unsigned(cntr)+1;
|
155 |
|
|
else
|
156 |
|
|
cntr:=(others => '0');
|
157 |
|
|
end if;
|
158 |
|
|
for k in 1 to ((10) / 2) loop
|
159 |
|
|
bitRev(2*k-2)<= cntr(10-2*k);
|
160 |
|
|
bitRev(2*k-1)<= cntr(10-(-1+2*k));
|
161 |
|
|
end loop;
|
162 |
|
|
end if;
|
163 |
|
|
end process radix4cnt;
|
164 |
|
|
|
165 |
|
|
END tester;
|