【问题标题】:Design a shift register in VHDL用VHDL设计一个移位寄存器
【发布时间】:2015-04-24 07:04:21
【问题描述】:

我尝试设计一个bch码作为移位寄存器,所以我有这个示意图:

(可点击)

我在 Altera Quartus 中编写了一个 VHDL 代码来设计这个带有循环的移位寄存器,编译工作但在 ModelSim 中的仿真过程中没有得到预期的结果(无输出)。我的代码中可能有一些错误:

-- Library declaration
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_arith.ALL;
USE IEEE.std_logic_unsigned.ALL;


-- Entity declaration
ENTITY bchcode_implementation_top IS

PORT(clk : IN std_logic;                    
  Q : OUT std_logic_vector(7 downto 0));

END bchcode_implementation_top;


-- Architecture declaration
ARCHITECTURE arch_bchcode_implementation_top OF bchcode_implementation_top IS

SIGNAL M: std_logic_vector(7 downto 0) := "10000000";

BEGIN
PROCESS(clk)

    VARIABLE W: std_logic;
   VARIABLE D: std_logic_vector(7 downto 0) := "00000000";

        BEGIN
            loop_bchcode: FOR I IN 7 TO 0 LOOP
                IF rising_edge(clk) THEN
                    W := D(0) XOR M(I);
                    D(7) := W;
                    D(6) := D(7);
                    D(5) := D(6);
                    D(4) := D(5);
                    D(3) := D(4) XOR W;
                    D(2) := D(3);
                    D(1) := D(2) XOR W;
                    D(0) := D(1) XOR W;
                END IF;
            Q <= D;
        END LOOP loop_bchcode;
END PROCESS;

END arch_bchcode_implementation_top;

如果有人有想法请..谢谢您的回复。

【问题讨论】:

  • 变量被立即赋值。例如,如果 D(6) := D(7) 然后 D(5) := D(6)D(5) 将等于 D(7)。这意味着D(6) 的值已被破坏,您必须更改分配顺序。所以如果你想使用变量赋值的顺序必须是D(0), D(1), ..., D(7)
  • 感谢您的回复,我已将所有 D 都更改了,但我仍然没有预期的结果,如果有人可以告诉我我的代码中是否还有其他错误,谢谢

标签: loops vhdl shift


【解决方案1】:

根据您的代码,我认为您要设计以下原理图:

正如我在上面的评论中提到的,如果你想使用变量(而不是信号),你必须改变赋值的顺序。

循环的范围也必须是7 DOWNTO 0(而不是7 TO 0)。

1 个周期后输出就绪。如果要在 8 个周期内执行操作,则必须使用在每个时钟上升沿递增的计数器。 (而不是使用for loop

我使用上述更改编辑了您的代码,并使用 Modelsim 10.3 对其进行了模拟。我可以在第一个时钟上升沿得到正确的结果:

LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;

-- Entity declaration
ENTITY bchcode_implementation_top IS
    PORT(
        clk : IN  std_logic;                    
        Q   : OUT std_logic_vector(7 DOWNTO 0)
    );
END bchcode_implementation_top;


-- Architecture declaration
ARCHITECTURE arch_bchcode_implementation_top OF bchcode_implementation_top IS
    SIGNAL M : std_logic_vector(7 DOWNTO 0) := "10000000";
BEGIN

    PROCESS(clk)
        VARIABLE I : integer;
        VARIABLE W : std_logic;
        VARIABLE D : std_logic_vector(7 DOWNTO 0) := "00000000";
    BEGIN
        loop_bchcode: FOR I IN 7 DOWNTO 0 LOOP
            IF rising_edge(clk) THEN
                    W := D(0) XOR M(I);
                    D(0) := D(1) XOR W;
                    D(1) := D(2) XOR W;
                    D(2) := D(3);
                    D(3) := D(4) XOR W;
                    D(4) := D(5);
                    D(5) := D(6);
                    D(6) := D(7);
                    D(7) := W;
            END IF;
        END LOOP loop_bchcode;
        Q <= D;
    END PROCESS;

END arch_bchcode_implementation_top;

【讨论】:

  • 非常感谢您的回复。当我在 Quartus 上编译时,我几乎没有错误:“无法推断 D[5] 的寄存器,因为它不会在时钟沿之外保持其值”。 (也适用于 D[6] 和 D[7])
  • 当我模拟代码时,它可以工作,但结果与理论上计算的结果不匹配,这里给出noelshack.com/…(D7 到 D0)
【解决方案2】:

我终于解决了这个问题,这是我描述 bch 码 (15,7) 移位寄存器的代码,感谢 Amir 的帮助。

-- Library declaration
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.numeric_std.ALL;



-- Entity declaration
ENTITY bchcode_implementation_top IS

PORT(clk, rst : IN std_logic;
 Din : IN std_logic_vector(7 downto 0);
  Dout : BUFFER std_logic_vector(7 downto 0)); -- OUT port cannot be read back to the design

END bchcode_implementation_top;


-- Architecture declaration
ARCHITECTURE arch_bchcode_implementation_top OF bchcode_implementation_top  IS

SIGNAL count : std_logic_vector(7 downto 0);

BEGIN
PROCESS(clk, rst, Din)

VARIABLE I : integer := 7;

BEGIN
    count <= Din;

        IF rst = '1' THEN
            Dout <= "00000000";
        ELSE
            IF rising_edge(clk) THEN
                Dout(0) <= Dout(1) XOR (Dout(0) XOR count(I));
                Dout(1) <= Dout(2) XOR (Dout(0) XOR count(I));  
                Dout(2) <= Dout(3);
                Dout(3) <= Dout(4) XOR (Dout(0) XOR count(I));
                Dout(4) <= Dout(5);
                Dout(5) <= Dout(6);
                Dout(6) <= Dout(7);
                Dout(7) <= Dout(0) XOR count(I);
                I := I - 1;
            END IF;
        END IF; 

END PROCESS;

END arch_bchcode_implementation_top;

【讨论】:

    猜你喜欢
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多