【发布时间】:2019-12-29 23:02:04
【问题描述】:
我是一个新手,我正在尝试在 VHDL 中实现一个除数组件的移位寄存器。移位寄存器必须采用 15 位输入并将其在每个时钟周期向右移位,同时在最高有效位上链接一个“0”。 我写了这段代码
------- 右移 ----------------------------------
> library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all;
>
> entity shift_right is port( in_shift_right: in std_logic_vector(14
> downto 0);
> clk_shift_right, rst_shift_right : in std_logic;
> out_shift_right : out std_logic_vector (14 downto 0) ); end shift_right;
>
> architecture behavioral of shift_right is begin
> process(clk_shift_right, rst_shift_right, in_shift_right ) variable
> tmp : std_logic_vector(14 downto 0); begin
> if rising_edge (clk_shift_right) then elsif rst_shift_right = '1' then
> tmp := (others => '0');
> elsif rising_edge(clk_shift_right) then
> tmp:='0'&in_shift_right(14 downto 1);
> end if;
> out_shift_right<=tmp; end process; end behavioral;
这是使用 Quartus 的图形工具测试的波形结果:
这不是我想要的,实际上只适用于第一个时钟周期。 虽然我在网上找到了以下代码
> library IEEE;
> use IEEE.STD_LOGIC_1164.ALL;
>
> entity shift is
> port(
> clk:in std_logic;
> rst:in std_logic;
> sin:in std_logic;
> pin:in std_logic_vector(7 downto 0);
> mode:in std_logic_vector(1 downto 0);
> sout:out std_logic;
> pout:out std_logic_vector(7 downto 0)
> );
> end shift;
>
>
> architecture Behavioral of shift is
> signal temp:std_logic_vector(7 downto 0);
>
>
> begin
> process(rst,clk,sin,mode,pin)
>
> begin
>
> if rst='1' then
> sout<='0';
> pout<="00000000";
> temp<="00000000";
>
>
> elsif(clk'event and clk='1')then
>
> case mode is
> --SISO
> when "00"=>
> temp(6 downto 0)<= temp(7 downto 1);
> temp(7)<=sin;
> sout<=temp(0);
>
> --SIPO
> when"01"=>
> temp(6 downto 0)<= temp(7 downto 1);
> temp(7)<=sin;
> pout<=temp;
>
> --PIPO
> when"10"=>
> temp<=pin;
> pout<=temp;
>
>
> when others=>
> null;
>
> end case;
>
> end if;
>
> end process;
>
> end Behavioral;
它实际上可以按我的意愿工作,但是,正如您从波形中看到的那样,它仅在“案例”上选择的模式为“01”时才有效,但仅在“10”模式之后才有效。 我也无法理解为什么它仅在时钟周期延迟后才起作用,我在图片中突出显示:
非常感谢任何可以帮助我的人
【问题讨论】:
-
你的代码很乱。我想如果你只是整理一下缩进,你会立即开始看到一些问题。