【问题标题】:Why is this Shift Register not loading properly in VHDL?为什么这个移位寄存器不能在 VHDL 中正确加载?
【发布时间】:2014-12-08 19:31:53
【问题描述】:

我有一个定制设计的移位寄存器,其输入为 DL(最左侧输入)、DR(最右侧)、清除和加载 DR 的 CLR、向右移位的 S 和加载最左侧的 W。经过测试,最右边的正在加载,而不是左边。我已经多次重读代码,但我无法弄清楚哪里出了问题。代码如下:

    library IEEE;
use IEEE.std_logic_1164.all;

entity shiftregister is
    port (
        CLK, CLR: in STD_LOGIC;
        S: in STD_LOGIC; --Shift right
 W: in STD_LOGIC; --Write
 Cin: in STD_LOGIC; --possible carry in from the addition
        DL: in STD_LOGIC_VECTOR (7 downto 0); --left load for addition result
 DR: in STD_LOGIC_VECTOR (7 downto 0); --right load for initial multiplier
        Q: out STD_LOGIC_VECTOR (15 downto 0)
     );
end shiftregister ;

architecture shiftregister of shiftregister is
signal IQ: std_logic_vector(15 downto 0):= (others => '0');
begin
   process (CLK)
   begin
 if(CLK'event and CLK='1') then 
          if CLR = '1' then 
   IQ(7 downto 0)  <= DR;  --CLR clears and initializes the multiplier
   IQ(15 downto 8) <= (others => '0');
   else 
  if (S='1') then
    IQ <= Cin & IQ(15 downto 1);
  elsif (W='1') then
    IQ(15 downto 8) <= DL;
  end if;
          end if;

 end if;  
    end process;
Q<=IQ;
end shiftregister;

波形

测试台

library IEEE;
use IEEE.std_logic_1164.all;

entity register_tb is
end register_tb;

architecture register_tb of register_tb is
    component shiftregister is port (
        CLK, CLR: in STD_LOGIC;
        S: in STD_LOGIC; --Shift right
        W: in STD_LOGIC; --Write
        Cin: in STD_LOGIC; --possible carry in from the addition
        DL: in STD_LOGIC_VECTOR (7 downto 0); --left load for addition result
        DR: in STD_LOGIC_VECTOR (7 downto 0); --right load for initial multiplier
        Q: out STD_LOGIC_VECTOR (15 downto 0)
    );
    end component;

    signal CLK: std_logic:='0';
    signal CLR: std_logic:='1';
    signal Cin: std_logic:='0';
    signal S: std_logic:='1';
    signal W: std_logic:='0';
    signal DL, DR: std_logic_vector(7 downto 0):="00000000";
    signal Q: std_logic_vector(15 downto 0):="0000000000000000";
begin 
    U0: shiftregister port map (CLK, CLR, S, W, Cin, DL,DR,Q);

    CLR <= not CLR    after 20 ns;
    CLK <= not CLK    after 5 ns;
    W   <= not W      after 10 ns;
    DL  <= "10101010" after 10 ns;
    DR  <= "00110011" after 10 ns;

end register_tb;

【问题讨论】:

  • 怎么不工作了?您能否展示一个不产生预期输出的示例输入/输出?也许是来自chipscope / signaltap的波形?
  • 此外,我不确定我是否愿意将可以写入 fifo 任何部分的东西称为移位寄存器...
  • 通过快速扫描,看起来您所写的就是正在发生的事情。您能否另外指出波形的行为与您的预期不同的地方?
  • @BillLynch 当 CLR 为 1 时,不加载最右边的位,DR,` if CLR = '1' then` IQ &lt;= (others =&gt; '0'); IQ(7 downto 0) &lt;= DR;
  • @BillLynch 对可能发生的事情有什么想法吗?

标签: loading vhdl shift-register


【解决方案1】:

您的模拟显示您的S 输入始终很高。您设置条件的方式,这意味着最后一个 elsif 语句将不会执行,因为S 优先于W。如果你希望你的 write 优先于你的 shift 操作,你应该切换你的条件

if (W='1') then
  IQ(15 downto 8) <= DL;
elsif (S='1') then
  IQ <= Cin & IQ(15 downto 1);
end if;

根据您对所需行为的评论,您可以执行以下操作:

if (S='1' and W='1') then
  IQ  <= Cin & DL & IQ(7 downto 1);
elsif (W='1') then -- S=0
  IQ(15 downto 8) <= DL;
elsif (S='1') then -- W=0
  IQ <= Cin & IQ(15 downto 1);
end if; -- W=0 & S=0

【讨论】:

  • 它解决了这个问题,但是有没有办法让它在 S=1 和 W=1 时都这样做,因为这就是我想要它做的事情
  • WS 都是1 时,这取决于您想要的最终结果。您是否希望将IQ 的高字节设置为DL,同时仍移动低字节?在这种情况下,Cin 会发生什么?
  • Cin 是一个 0。所以我们可以忽略它并附加一个 0
  • 是否可以将 IQ 的高字节设置为 DL THEN 移位整个输出?
  • 看看编辑。可能不是您想要的,但您应该能够使用相同的概念
【解决方案2】:

一些改进:

(1) 从灵敏度列表中删除除 CLK 之外的所有信号。您的进程没有异步信号,因此灵敏度列表中只需要时钟。

process(CLK)

(2) 仅将零分配给所需的位 -> 品味问题;)

IQ(7 downto 0)  <= DR;              --CLR clears and initializes the multiplier
IQ(15 downto 8) <= (others => '0');

(3) elsif 语句可以明确赋值优先级:

if (S='1') then
  IQ <= Cin & IQ(15 downto 1);
elsif (W='1') then
  IQ(15 downto 8) <= DL;
end if;

(4) 行 Q &lt;= IQ; 生成第二个 16 位寄存器。我认为这不是故意的。将此行移出进程。

【讨论】:

  • 感谢您的回复!我实现了你的更改,但我得到的是 0 而不是 X
  • 你能发布一个新的波形,扩展视图信号 Q,这样我们就可以看到低字节和高字节了吗?我还建议降低信号W 的速度,以便我们可以看到变化。改进(5):信号 IQ 应该有一个初始值:signal IQ: std_logic_vector(15 downto 0) := (others =&gt; '0'); - 如果您更改了计算机上的代码,请同时编辑您的问题,以便我们看到您的代码的当前版本:)
  • 我会上传几张
  • 我认为一切都按预期工作,是吗?注意:您的时钟以 180° 相位开始(延迟 1/2 周期),这会导致奇怪的波形。我建议将 CLK 的默认值设置为 '1'。
  • pwolfsbergs 回答解决了这个问题,但它改变了我想要的输出。我想要一个 S 和 W 都可以为 1 的情况
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-03
  • 1970-01-01
  • 2021-07-20
  • 2016-09-02
  • 1970-01-01
相关资源
最近更新 更多