【发布时间】: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 <= (others => '0');IQ(7 downto 0) <= DR; -
@BillLynch 对可能发生的事情有什么想法吗?
标签: loading vhdl shift-register