Vhdl 用led输出实现10位移位寄存器

Vhdl 用led输出实现10位移位寄存器,vhdl,shift-register,Vhdl,Shift Register,我正在尝试实现以下移位寄存器 entity MyShiftRegister is port( clock: in std_logic; DataIn: in std_logic_vector (9 downto 0); Left: in std_logic; --synchronous left rotate Right: in std_logic; --synchronous right ro

我正在尝试实现以下移位寄存器

entity MyShiftRegister is
    port(
        clock:   in  std_logic;
        DataIn:  in  std_logic_vector (9 downto 0); 
        Left:    in  std_logic;  --synchronous left rotate
        Right:   in  std_logic;  --synchronous right rotate
        Load:    in  std_logic;  --synchronous parallel load
        Clear:   in  std_logic;  -- synchronous clear
        DataOut: out std_logic_vector (9 downto 0);     
这就是我目前所拥有的


IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.NUMERIC_STD.ALL;
实体问题2是
港口(
led:缓冲器标准逻辑向量(9到0);
clk:标准逻辑中;
btnu:标准逻辑中;
btnL:标准逻辑中;
btnR:标准逻辑中;
btnD:标准逻辑中;
btnC:标准逻辑中
);
结束问题2;
问题2的架构是
恒定激活:标准逻辑:='1';
常数不活动:标准逻辑:='0';
常数步长0:std逻辑向量(9到0):=“0000000000”;
常数步长1:标准逻辑向量(9到0):=“000000000 1”;
常数步长二:标准逻辑向量(9到0):=“00000000 10”;
常数步长三:标准逻辑向量(9到0):=“00000000100”;
常数步长四:标准逻辑向量(9到0):=“0000001000”;
常数步进五:标准逻辑向量(9到0):=“0000010000”;
常数步进六:标准逻辑向量(9到0):=“000010000”;
常数步长七:标准逻辑向量(9到0):=“0001000000”;
常数步进八:标准逻辑向量(9到0):=“0010000000”;
常数步进九:标准逻辑向量(9到0):=“0100000000”;
常数步长:标准逻辑向量(9到0):=“0100000000”;
信号数据输入:标准逻辑向量(9到0):=“1111”;
信号负载:标准逻辑:=btnD;
信号复位:标准逻辑;
左信号:标准逻辑:=btnL;
信号右:标准逻辑:=btnR;
信号数据输出:标准逻辑向量:=led(9到0);
信号清除:标准逻辑:=btnU;
信号速度启用:标准逻辑;
开始
速度控制:进程(clk)
变量计数器:整数范围0到10000000;
开始
速度\u启用启动:

constant step_nine:  std_logic_vector(9 downto 0) :="0100000000";
constant step_ten:   std_logic_vector(9 downto 0) :="0100000000";
这是不正确的。应该是

constant step_nine:  std_logic_vector(9 downto 0) :="0100000000";
constant step_ten:   std_logic_vector(9 downto 0) :="1000000000";
但无论如何,这种方法很容易出错。让我们简化一下:

process(sel)
    variable selected_led : natural;
begin
    led <= (others => '0');
    selected_led := to_integer(unsigned(sel));
    if selected_led < led'length then
        led(selected_led) <= '1';
    end if;
end process;

这段代码充斥着设计错误,毫无意义。为什么使用led的多路复用器<代码>数据输出
不是4位;这是一个语法错误。您的左移位和右移位分支不能正确移位或旋转(尤其是右移位)。您的实际实体与您提供的实体不匹配,因为您正试图实现该实体。速度控制过程无法合成,因为它混合了组合分配和注册分配。默认值(
:=
)不是默认连接。你知道同步桶形移位器(由
MyShiftRegister
实体描述)应该做什么吗?你列出的所有其他问题我仍在编写代码。我只是不知道如何在不使用计数器将位
数据移出的情况下向左或向右移位。通常,桶形移位器在左或右输入上每脉冲将位向左或向右旋转一个位置。您正在使用
DataOut
作为存储元素,尽管它可能是一个名称不同的信号。如果有活动的高发光二极管,则可以将存储元素复制到输出端口,例如
led。因此,为了使LED旋转,我是否需要声明我的任何数据输出位初始为高
process(sel)
    variable selected_led : natural;
begin
    led <= (others => '0');
    selected_led := to_integer(unsigned(sel));
    if selected_led < led'length then
        led(selected_led) <= '1';
    end if;
end process;
for i in 0 to led'length-1 loop
    if (i = selected_led) then
        led(i) <= '1';
    end if;
end loop;
process(clock)
begin
    if rising'edge(clock) then
        if clear = '1' then
            data_out <= (others => '0');
        elsif load = '1' then
            data_out <= data_in;
        elsif right_rotate = '1' then
            data_out <= data_out(0) & data_out(data_out'length-1 downto 1);
        elsif left_rotate = '1' then
            data_out <= data_out(data_out'length-2 downto 0) &
                data_out(data_out'length-1);
        end if;
    end if;
end process;