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

时间:2015-09-16 00:55:08

标签: vhdl type-conversion multiplication

我试图将行中的值相乘:

Q< = unsigned(reg_output)或(unsigned(multiplicand)and unsigned(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 个答案:

答案 0 :(得分:1)

问题来自:

unsigned(shifted_lsb)*"0010"

shifted_lsb不是矢量,您无法将其转换为unsigned这是一种矢量类型。正如Khanh N. Dang所建议的,你只能测试它的价值。

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

  • 缩进你的代码,以便我们可以毫不费力地阅读它,
  • 首先考虑硬件:如果您对所需的硬件(寄存器,加法器,多路复用器......)有清晰的认识,那么编码通常会非常简单,
  • 再次阅读有关同步过程的教科书部分。
相关问题