azwaa
Member level 1
- Joined
- May 21, 2014
- Messages
- 32
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 197
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity correla4bit is
port (
clk : in std_logic ;
rst : in std_logic ;
data: in std_logic_vector(11 downto 0) ;
code: in std_logic_vector(15 downto 0 ) ;
Q :out std_logic_vector(17 downto 0) ) ;
end entity ;
architecture arch of correla4bit is
type RAM is array (0 to 3) of std_logic_vector(3 downto 0) ;
type ram16 is array (0 to 3) of signed(15 downto 0) ;
type Rom is array (0 to 3) of signed(11 downto 0) ;
signal voie :Rom ;
signal CD : RAM;
signal temp: ram16;
signal sum0 :signed (16 downto 0) ;
signal sum1 :signed (16 downto 0) ;
signal AB :signed (17 downto 0) ;
begin
CD(0) <= code(15 downto 12);
CD(1) <= code(11 downto 8);
CD(2) <= code(7 downto 4);
CD(3) <= code(3 downto 0);
etalement:process(clk,rst)
begin
if(rst='1') then
Q <=(others=>'0');
temp(0)<=x"0000";
temp(1)<=x"0000";
temp(2)<=x"0000";
temp(3)<=x"0000";
elsif(clk'event and clk ='1') then
voie(0)<=signed(data) ;
voie(1)<=voie(0);
voie(2)<=voie(1);
voie(3)<=voie(2);
for i in 0 to 3 loop
temp(i) <= voie(i)*signed(CD(i));
end loop ;
sum0<= resize(temp(0),17)+temp(1) ;
sum1<= resize(temp(2),17)+temp(3) ;
AB<=resize(sum0,18)+sum1 ;
Q<=std_logic_vector(AB) ;
end if ;
end process ;
end architecture ;
This is just a standard N tap FIR.
First of all, I suggest you bring in all C co-efficients separately, not as a single bus.
Second, for N taps, you will probably need a package to create the array types to make the design generic.
I dont know why you have declared RAM and ROM types - there is no RAM or ROM in your drawings. They are just arrays of registers.
I would also suggest putting registers after each multiplier and adder stage, or the fmax is going to be very low.
type ram16 is array (0 to longueur-1 ) of signed( 15 downto 0) ;
type ram17 is array (0 to (longueur/2)-1 ) of signed( 16 downto 0) ;
type ram18 is array (0 to (longueur/4)-1 ) of signed( 17 downto 0) ;
signal temp: ram16;
signal temp1: ram17;
signal temp2: ram18;
type Tem1 is array (0 to longueur-1 ) of signed( 15 downto 0) ;
type Tem2 is array (0 to (longueur/2)-1 ) of signed( 16 downto 0) ;
type Tem3 is array (0 to (longueur/4)-1 ) of signed( 17 downto 0) ;
signal temp1: Tem1 ;
signal temp2: Tem2 ;
signal temp3: Tem3;
I understand the diagram, I have written this structure in VHDL a few times (for 1D and 2D FIRs).
I understand your diagram perfectly. I dont understand what you are asking us to look at. The code you posted in the first post will only do the 4-tap FIR. Now you are poasting the variable length arrays that will also only cover the 4 (maybe the 8-tap)-tap FIR. To do it the way you want to (an N tap filter), the easiet way would be to define an array of tem1 type that you can extend the different layers of your adder tree. Many of the entries will be unused, but it gives a basic structure.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 type mult_array_t is array(0 to longueur-1) of signed(15 downto 0); type adder_stage_t is array(0 to longueur/2-1) of signed(Q'length-1 downto 0); type adder_tree_t is array(0 to log2(longueur)-1) of adder_stage_t; signal mults : mult_array_t; signal adders : adder_tree_t; ... --multiplies: mult_proc : process(clk) begin if rising_edge(clk) then for i in mults'range loop mults(i) <= ip(i) * C(i); end loop; --initial adders: for i in adders(0)'range loop adders(0)(i) <= resize(mults(i*2), Q'length) + resize( mults(i*2 +1), Q'length); end loop; --other adder stages: for level in 1 to adders'high loop for i in 0 to longueur/ (2**(level+1)) loop adders(level)(i) <= adders(level-1)(i*2) + adders(level-1)(i*2 + 1); end loop end loop; end if; end process; Q <= adders(adders'high)(0);
(Q'length-1 downto 0);
for level in 1 to adders'high loop
Q <= adders(adders'high)(0);
generic (
longueur : natural :=16 ;
result := integer(ceil(log2(real(longueur))))) ;
Q :out std_logic_vector(result-1 downto 0) ) ;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use IEEE.math_real."ceil";
use IEEE.math_real."log2";
entity correla is
generic (
longueur : natural :=16 ;
result := integer(ceil(log2(real(longueur))))) ;
port (
clk : in std_logic ;
rst : in std_logic ;
data: in std_logic_vector(11 downto 0) ;
code: in std_logic_vector((4*longueur)-1 downto 0 ) ;
Q :out std_logic_vector(result-1 downto 0) ) ;
end entity ;
architecture arch of correla is
type RAM is array (0 to 3) of std_logic_vector(3 downto 0) ;
type Rom is array (0 to longueur-1) of signed(11 downto 0) ;
type mult_array_t is array (0 to longueur-1 ) of signed( 15 downto 0) ;
type adder_stage_t is array(0 to longueur/2-1) of signed(Q'longueur-1 downto 0) ;
type adder_tree_t is array(0 to result-1) of adder_stage_t;
signal mults : mult_array_t;
signal adders : adder_tree_t;
signal voie :Rom ;
signal CD : RAM;
signal temp: ram16;
--signal AB :signed (17 downto 0) ;
begin
AY:for j in 0 to longueur-1 generate
CD(j)<=code(4*(longueur-j)-1 downto 4*(longueur-j)-4 );
end generate AY ;
etalement:process(clk,rst)
begin
if(rst='1') then
Q <=(others=>'0');
F:for k in 0 to longueur-1 loop
mults(k)<=(others=>'0');
end loop ;
elsif(clk'event and clk ='1') then
voie(0)<=signed(data) ;
B:for L in 1 to longueur-1 loop
voie(L)<=voie(L-1);
end loop ;
for i in 0 to longueur-1 loop
mults(i) <= voie(i)*signed(CD(i));
end loop ;
--initial adders:
for i in 0 to result-1 loop
adders(0)(i) <= resize(mults(i*2), Q'length) + resize( mults(i*2 +1), Q'length);
end loop;
--other adder stages:
for level in 1 to adders'high loop
for i in 0 to longueur/ (2**(level+1)) loop
adders(level)(i) <= adders(level-1)(i*2) + adders(level-1)(i*2 + 1);
end loop
end loop;
end if ;
end process ;
Q <= adders(adders'high)(0);
end architecture ;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use IEEE.math_real."ceil";
use IEEE.math_real."log2";
entity correla is
generic (
longueur : natural :=16 ;
result := integer(ceil(log2(real(longueur))))) ;
port (
clk : in std_logic ;
rst : in std_logic ;
data: in std_logic_vector(11 downto 0) ;
code: in std_logic_vector((4*longueur)-1 downto 0 ) ;
Q :out std_logic_vector(result-1 downto 0) ) ;
end entity ;
architecture arch of correla is
type RAM is array (0 to 3) of std_logic_vector(3 downto 0) ;
type Rom is array (0 to longueur-1) of signed(11 downto 0) ;
type mult_array_t is array (0 to longueur-1 ) of signed( 15 downto 0) ;
type adder_stage_t is array(0 to longueur/2-1) of signed(Q'longueur-1 downto 0) ;
type adder_tree_t is array(0 to result-1) of adder_stage_t;
signal mults : mult_array_t;
signal adders : adder_tree_t;
signal voie :Rom ;
signal CD : RAM;
signal temp: ram16;
--signal AB :signed (17 downto 0) ;
begin
AY:for j in 0 to longueur-1 generate
CD(j)<=code(4*(longueur-j)-1 downto 4*(longueur-j)-4 );
end generate AY ;
etalement:process(clk,rst)
begin
if(rst='1') then
Q <=(others=>'0');
F:for k in 0 to longueur-1 loop
mults(k)<=(others=>'0');
end loop ;
elsif(clk'event and clk ='1') then
voie(0)<=signed(data) ;
B:for L in 1 to longueur-1 loop
voie(L)<=voie(L-1);
end loop ;
for i in 0 to longueur-1 loop
mults(i) <= voie(i)*signed(CD(i));
end loop ;
--initial adders:
for i in 0 to result-1 loop
adders(0)(i) <= resize(mults(i*2), Q'length) + resize( mults(i*2 +1), Q'length);
end loop;
--other adder stages:
for level in 1 to adders'high loop
for i in 0 to longueur/ (2**(level+1)) loop
adders(level)(i) <= adders(level-1)(i*2) + adders(level-1)(i*2 + 1);
end loop
end loop;
end if ;
end process ;
Q <= adders(adders'high)(0);
end architecture ;
entity correla is
result:= integer(ceil(log2(real(longueur))))
) ;
result:= integer(ceil(log2(real(longueur)))) ;
use IEEE.math_real.all;
use IEEE.math_real."ceil";
use IEEE.math_real."log2";
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?