输出的vhdl代码不符合预期

输出的vhdl代码不符合预期,vhdl,Vhdl,我想将num作为8位输入,然后在时钟的每个上升沿上移动它,并在输出“res”上输出它。代码如下所示。但当模拟时,它并没有给出预期的结果 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; use ieee.numeric_std.all; entity shiftreg is port ( num : in std_lo

我想将num作为8位输入,然后在时钟的每个上升沿上移动它,并在输出“res”上输出它。代码如下所示。但当模拟时,它并没有给出预期的结果

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;

entity shiftreg is
    port (
    num : in std_logic_vector (7 downto 0);
    clk : in std_logic; 
    res : out std_logic_vector (7 downto 0)
    );
end entity;

architecture behav of shiftreg is 
    signal temp_num : std_logic_vector (7 downto 0):= "00000000"; 
begin
    process(num) 
    begin
        if(num' event) then
            temp_num <= num;
            res<=temp_num; 
        end if;
    end process;

    process(clk) 
    begin
        if(rising_edge(clk)) then
            temp_num <= shr(temp_num,"01");
            res<=temp_num;
        end if;
    end process;
end behav;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.std_logic_arith.all;
使用ieee.std_logic_unsigned.all;
使用ieee.numeric_std.all;
实体移位是
港口(
num:标准逻辑向量(7到0);
clk:标准逻辑中;
res:out标准逻辑向量(7到0)
);
终端实体;
shiftreg的体系结构行为是
信号温度数值:标准逻辑矢量(7到0):=“00000000”;
开始
进程(num)
开始
如果(num'事件),则

temp_num输出
res
和信号
temp_num
均由两个驱动器驱动 进程,因此模拟器将执行分辨率,这可能导致
X
部分或所有位的值

一般来说,那么信号和输出是设计模块应该驱动的 只有一个过程,因为这也是合成工具所期望的。对于 测试台,则可能有多个驾驶员

因此,如果意图是反映
num
输入中的任何更改 立即切换到
res
输出,随后的
clk
上升沿应 导致右移,则这两个过程可以合并为一个过程 处理并分配给
res
如下:

process (num, clk) is
begin
  if (num'event) then
    temp_num <= num;
  elsif (rising_edge(clk)) then
    temp_num <= shr(temp_num, "01");
  end if;
end process;
res <= temp_num;
并将其用于加载内部
temp_num
,过程如下:

process (clk) is
begin
  if (rising_edge(clk)) then
    if load = '1' then
      temp_num <= num;
    else
      temp_num <= shr(temp_num, "01");
    end if;
  end if;
end process;
res <= temp_num;

你有很多问题。首先,您正在从多个进程驱动
temp_num
res
,这将导致对这些信号的争用。其次,您可能试图将
temp_num
用作局部变量,但事实并非如此。看见更重要的是,从算法上讲,不清楚你到底想做什么。您是否尝试加载
num
一次,然后将其旋转几次?你想连续移动吗?谢谢你的回复,是的,我想连续移动。
process (clk) is
begin
  if (rising_edge(clk)) then
    if load = '1' then
      temp_num <= num;
    else
      temp_num <= shr(temp_num, "01");
    end if;
  end if;
end process;
res <= temp_num;
temp_num <= std_logic_vector(shift_right(unsigned(temp_num), 1));