【问题标题】:Out come of vhdl code not as expectedvhdl 代码的输出与预期不符
【发布时间】:2014-10-23 13:35:03
【问题描述】:

我想将 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;

【问题讨论】:

  • 您有多个问题。首先,您从多个进程驱动temp_numres,这将导致这些信号的争用。其次,您似乎试图将temp_num 用作局部变量,但事实并非如此。见How does signal assignment work in a process?。更重要的是,从算法上讲,您到底要做什么还不清楚。您是否尝试加载 num 一次然后旋转几次?您是否要连续转换它?
  • 感谢您的回复,是的,我正在尝试连续转换它。

标签: vhdl


【解决方案1】:

输出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;

这将在模拟中起作用,但'event 在合成中不起作用,因为 通常没有像'event 这样可以感知值变化的硬件,所以 构造不能通过综合映射到硬件。

因此,对于可综合设计,您可以考虑添加load 输入:

load : in  std_logic;

并使用它来加载内部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;

最后,您应该考虑删除 use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;,因为这两个包不是标准的 VHDL 包,尽管位于 IEEE 库中。只需删除这两个 行,然后使用 std_logic_unsigned 中的 shift_right 函数 喜欢:

temp_num <= std_logic_vector(shift_right(unsigned(temp_num), 1));

【讨论】:

    猜你喜欢
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多