Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

Multiplication VHDL

Hi, i have problems with my vhdl code.

can you help me plz

This is the code:

library ieee;use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all ; 
entity correla 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 correla  is
      
      
       type RAM is array (0 to 3) of integer range -8 to 7 ;
        signal CD   : RAM;
        signal temp :integer range 0 to 15;
        signal i    :integer range 0 to 3 ;
       signal sum   :integer range 0 to 16  ;
       signal AB    :integer range 0 to 17 ;
begin
  
                 CD(0)<=to_integer(code(15 downto 12));
                 CD(1)<=to_integer(code(11 downto 8)) ;
                 CD(2)<=to_integer(code(7 downto 4 )) ;
                 CD(3)<=to_integer(code(3 downto 0))  ;
                 
     étalement:process(clk,rst)
           
        begin 
                  if(rst='1') then 
                     Q<=(others=>'0');
                       i<= 0  ;
                      temp<=0;
                      AB<=0;
                   
                   else 
                        if(clk'event and clk ='1') then 
                            sum<=0;
                            
                            
                                
                                temp<=to_integer(data(i)*code(i)) ;
                                      i<=i+1 ;
                                  sum<=sum(i) +(temp(i)+temp(i+1)) ;
                             end if ;
                     end if ;  
                                     
                        AB<=sum ;
                         Q<=std_logic_vector(AB) ;
                       
            end process ;
 end architecture ; 
                 

15 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    yeah !

    like this :

    library ieee;

    use ieee.std_logic_1164.all;

    use ieee.numeric_std.all;

    entity correla 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 correla 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(16 downto 0) ;

    signal CD : RAM;

    signal temp: ram16;

    signal sum :Rom ;

    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);

    étalement: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";

    sum(0)<=x"00000";

    sum(1)<=x"00000";

    else

    if(clk'event and clk ='1') then

    for i in 0 to 3 loop

    temp(i) <= signed(data)*signed(CD(i));

    end loop ;

    sum(0)<= temp(0)+temp(1) ;

    sum(1)<= temp(2)+temp(3) ;

    AB<=sum(0)+sum(1) ;

    Q<=std_logic_vector(AB) ;

    --

    end if ;

    end if ;

    end process ;

    end architecture ;

    error : Error (10324): VHDL Expression error at correla.vhd(55): expression ""0000000000000000"" has 16 elements ; expected 17 elements.

    55 : sum(0)<=x"0000";

    can you help me !!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    like this :

    library ieee;

    use ieee.std_logic_1164.all;

    use ieee.numeric_std.all;

    entity correla 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 correla 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(16 downto 0) ;

    signal CD : RAM;

    signal temp: ram16;

    signal sum :Rom ;

    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";

    sum(0)<="00000000000000000";

    sum(1)<="00000000000000000";

    else

    if(clk'event and clk ='1') then

    for i in 0 to 3 loop

    temp(i) <= signed(data)*signed(CD(i));

    end loop ;

    sum(0)<= temp(0)+temp(1) ;

    sum(1)<= temp(2)+temp(3) ;

    AB<=sum(0)+sum(1) ;

    Q<=std_logic_vector(AB) ;

    --

    end if ;

    end if ;

    end process ;

    end architecture ;

    error : Error (10344): : expression has 16 elements, but must have 17 elements

    sum(0)<= temp(0)+temp(1) ;

    thanks a lot
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The error messages are usually quite helpful

    The answer is that the expression has 16 elements, but sum has 17