代码之家  ›  专栏  ›  技术社区  ›  Techno04335

VHDL代码:转换std_logic_vector的类型转换非法

  •  0
  • Techno04335  · 技术社区  · 10 年前

    我试图将行中的值相乘:

    Q<=无符号(reg_output)或(无符号(被乘数)和无符号(shifted_lsb)*“0010”);

    注意:我知道被乘数是std_logic_vector,我这样做是为了通过if进行比较。

    每次编译时都会出现错误: 从ieee.std_logic_1164.std_logic到ieee.NUMERIC_std的类型转换非法。UNSIGNED(非数值到数组)。

    下面是我的代码:

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all; 
    entity shiftaddr is
     port(
     clk, clear : in std_logic;
     multiplicand: in std_logic_vector(3 downto 0);
     reg_output: in unsigned(7 downto 0);
     shifted_lsb: in std_logic;
     Q: out unsigned(7 downto 0) );
    end shiftaddr;
    
    architecture arch of shiftaddr is
     signal temp: std_logic_vector(3 downto 0);
    begin
    
     shift: process(clk,clear,multiplicand, shifted_lsb,reg_output) --Define a process and state the inputs
    
    
    begin
    
    if (clk = '0') then
     Q <= reg_output;
    end if;
    
    if (clk = '1') then
    
    
        if (multiplicand(0) = '1') then Q <= (reg_output);
        end if;
    
        if (multiplicand(1) = '1') then 
        Q<= unsigned(reg_output) or (unsigned(multiplicand) and unsigned(shifted_lsb)*"0010");
        end if;
    end if;
    
     end process;
    end arch;
    

    我该如何解决这个问题?谢谢

    1 回复  |  直到 10 年前
        1
  •  1
  •   Renaud Pacalet    10 年前

    问题来自:

    unsigned(shifted_lsb)*"0010"
    

    shifted_lsb 不是矢量,不能将其转换为 unsigned 其是矢量类型。正如Khanh N.Dang所建议的,你可以测试它的价值。

    但你的代码可能是假的:当你的一个信号被命名时,你的敏感度列表不是同步进程的敏感度 clk 此外,如果您希望您的进程是同步的,则会遇到问题,因为您使用了时钟的两种状态。您可能应该:

    • 缩进你的代码,这样我们就可以毫不费力地阅读它,
    • 首先考虑硬件:如果你对你想要的硬件(寄存器、加法器、多路复用器……)有一个清晰的概念,那么编码通常会变得非常简单,
    • 再次阅读课本中关于同步进程的部分。