VHDL 增量器 "add one"

VHDL incrementer "add one"

这道题的道理我不会怎么写table所以我做不了这道题,谁能帮我理解一下这道题让我们做什么?非常感谢。

增量器是一种组合电路,可将输入的无符号整数 (X) 加 1。输出无符号整数 (Y) 具有与输入相同的位数。没有输出进位,一个全“1”递增到全“0”的输入字符串。

a) 用输入 A0 、 B0 和 C0 编写全加器方程。 (又名 Cin)

b) 替换为 A0 = X0 , B0 = ‘0’ 和 C0 = ‘1 然后化简。

c) 用输入 Ai 、 Bi 和 Ci.

写出全加器方程

d) 代入 Ai = Xi , Bi = ‘0’ 然后化简。

e) 考虑一个 A = X、B = 0 和 Cin = ‘1’ 的 6 位纹波加法器。显然,这将是一个增量器。使用您在 (b) 和 (d) 中导出的简化电路绘制 6 位增量器的结构图。 (标记所有实例和信号。)

VHDL 可用于对各个门的时间延迟进行建模。有关信号分配的 BNF 语法,请参阅您的讲义。延迟格式由模拟器使用,但被合成器忽略。使用以下语句对 2 输入门和反相器进行编码。

使用具有 4 ns 延迟的语句对 2 输入与门进行编码,Y <= A 和 B 在 4 ns 之后;

使用具有 4 ns 延迟的语句对 2 输入 XOR 门进行编码,Y <= A xor B after 4 ns;

使用延迟 1 ns 的语句对反相器进行编码,Y <= not A after 1 ns;
创建一个名为 PLA03 的新目录,然后启动一个名为 PLA03.Always 的新 ModelSim 项目,将 Entity/Architectures 放入他们自己的源文件中,并使用实体名称作为文件名。

f) 为 (b) 中的简化电路写一个 Entity/Architecture。将实体命名为 IncStage0

g) 为 (d) 中的简化电路写一个 Entity/Architecture。将实体命名为 IncStageI

h) 在 (e) 中为您的 6 位增量器编写一个名为 Inc6 的实体和一个结构体系结构。请记住将输入和输出声明为无符号。

library ieee;
use ieee.std_logic_1164.all;  
Use ieee.numeric_std.all;
Entity IncStage0 is
  port(
       X:in unsigned;
        S: out unsigned;
        Cout: out unsigned);
End Entity IncStage0;
Architecture behaviour of IncStage0 is
Begin
  S <= not X after 4 ns;
  Cout <= X;
End Architecture behaviour;

library ieee;
use ieee.std_logic_1164.all;  
Use ieee.numeric_std.all;
Entity IncStageI is
  port(
      X:in unsigned;
      Cin: in unsigned;
      S: out unsigned;
      Cout:out unsigned);
End Entity IncStageI;
Architecture stageI of IncStageI is
Begin
  S <= X xor Cin after 4 ns;
  Cout <= X and Cin after 4 ns;
End Architecture stageI;

library ieee;
use ieee.std_logic_1164.all;  
Use ieee.numeric_std.all;
Entity Inc6 is
  port( 
        X:in unsigned (5 downto 0);
        Y:out unsigned (5 downto 0));
End Entity Inc6;
Architecture behaviour of Inc6 is
  signal C:unsigned (5 downto 0);
  Component IncStage0
     port(
       X:in unsigned;
        S: out unsigned;
        Cout: out unsigned);
  End Component ;
 Component IncStageI
     port(
      X:in unsigned;
      Cin: in unsigned;
      S: out unsigned;
      Cout:out unsigned);
  End Component;
Begin
  I0: IncStage0
    port map(X=>X, S=>Y, Cout=>C);
  I1: IncStageI
    port map(X=>X, S=>Y, Cout=>C,Cin=>C);
  I2: IncStageI
    port map(X=>X, S=>Y, Cout=>C,Cin=>C);
  I3: IncStageI
    port map(X=>X, S=>Y, Cout=>C,Cin=>C);
  I4: IncStageI
    port map(X=>X, S=>Y, Cout=>C,Cin=>C);
  I5: IncStageI
    port map(X=>X, S=>Y, Cout=>C,Cin=>C);
End Architecture behaviour;

Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.numeric_std.all;
Entity TBInc6 is
End Entity TBInc6;
Architecture rtl of TBInc6 is
  signal tbX,tbY: unsigned(5 downto 0);
Begin
DUT: Entity work.Inc6 port map(X => tbX, Y => tbY);
Main: Process
  Begin
    for i in 0 to 63 loop
      tbX <= to_unsigned(i,6);
      wait for 30 ns;
    end loop;
    Wait;
  End Process Main;
End Architecture rtl;

问题似乎要解决的问题是,虽然您可以使用通用加法器 (A + B + carry) 来执行增量,但如果您只需要 (A + 1)(A + carry).

似乎假设您已经学习了基本的数字逻辑、门、半加器和全加器。如果没有,这个信息很容易找到。

因此,首先为每个位画出 "Full Adder" 电路。在步骤 (e) 中,显示将 6 位加法器从 (A + B + carry) 简化为 (A + carry).

时的简化情况(在门级)

剩下的步骤会让您看看简化电路是否真的更快。看起来是一个很好的练习,可以使用这些工具来做一些非常基本的事情。

修复了 incStage0 中 NOT 的延迟(应该是 1 ns,而不是 4 ns),并将类型 unsigned 的无约束子类型指示更改为类型 std_logic(incStage0、incStageI 和它们的组件声明),以及恢复您在问题第 5 次编辑中删除的 I0 到 I5 的索引,然后您得到:

与教师提供的波形相比,这看起来是正确的。

请注意,很难击中移动的目标,每次您更改问题时,答案都会更改。一个很好的迹象表明你应该问单独的问题。

您可以修改 inc6 以将信号 C 声明为:

architecture behaviour of Inc6 is
  signal C:unsigned (4 downto 0);
  component IncStage0
     port(
       X:in std_logic;
        S: out std_logic;
        Cout: out std_logic);
  end component ;

并更改 I5 实例化:

  I5: IncStageI
    port map(X=>X(5), S=>Y(5), Cout=> open, Cin=>C(4));

因为您在接口列表中使用名称关联,您可以简单地:

  I5: IncStageI
    port map(X=>X(5), S=>Y(5),Cin=>C(4));

不提执行。

附录

Is that means I should change every type unsigned to std_logic or std_logic_vector?But if I try to change everything to std_logic, it says no feasible entries for to_unsigned which is in part h code, how to fix that?

没有。 unsigned 是数组类型。来自包 numeric_std (-2008):

 type UNRESOLVED_UNSIGNED is array (NATURAL range <>) of STD_ULOGIC;

 subtype UNSIGNED is (resolved) UNRESOLVED_UNSIGNED;  

-1987, -1993, -2002:

  type UNSIGNED is array (NATURAL range <>) of STD_LOGIC;

在包 std_logic_1164 中时 (-2008):

  subtype STD_LOGIC is resolved STD_ULOGIC;

-1987, -1993, -2002:

 SUBTYPE std_logic IS resolved std_ulogic;

在VHDL标准的所有修订版中std_logic的基类型是std_ulogic,也是无符号数组类型的元素类型的基类型。

这意味着您可以将无符号(表示位)的元素连接到 std_logic 信号,包括端口。两者的元素基本类型都是 std_ulogic,它是位的多值表示,提供弱和强逻辑电平强制和表示位值的元值:

TYPE std_ulogic IS ( 'U',  -- Uninitialized
                     'X',  -- Forcing  Unknown
                     '0',  -- Forcing  0
                     '1',  -- Forcing  1
                     'Z',  -- High Impedance
                     'W',  -- Weak     Unknown
                     'L',  -- Weak     0
                     'H',  -- Weak     1
                     '-'   -- Don't care
                   );

(另见 IEEE Std 1076-2008, 16.8.2.2 STD_LOGIC_1164 值 - "The logical values '1', 'H', '0', and 'L' of type STD_ULOGIC are interpreted as representing one of two logic levels, where each logic level represents one of two distinct voltage ranges in the circuit to be synthesized.",两个逻辑值之一。

正如您无疑发现的那样,您无法将数组类型连接到标量类型。 incStage0 (I0) 和 inStageI (I1, I2, I3, I4 and I5) 表示 bits:

h) Write an Entity named Inc6 and a Structural Architecture for your 6-bit Incrementer in (e). Remember to declare the inputs and outputs as unsigned.

在显示 I5 上实际使用打开的代码片段中,C 的声明显示为无符号,I5 使用索引名称(数组对象上的元素)显示。除了将 inc6 的位片元素声明为 std_logic:

entity IncStage0 is
  port(
       X:in std_logic;
        S: out std_logic;
        Cout: out std_logic);

Entity IncStageI is
  port(
      X:in std_logic;
      Cin: in std_logic;
      S: out std_logic;
      Cout:out std_logic);

  component IncStage0
     port(
       X:in std_logic;
        S: out std_logic;
        Cout: out std_logic);
  end component ;
 component IncStageI
     port(
      X:in std_logic;
      Cin: in std_logic;
      S: out std_logic;
      Cout:out std_logic);
  end component;

您需要 inc6 中的无符号数组值:

entity Inc6 is
  port( 
        X:in unsigned (5 downto 0);
        Y:out unsigned (5 downto 0));

architecture behaviour of Inc6 is
  signal C: unsigned (4 downto 0);

并将索引数组元素作为连接到标量形式的实际值:

begin
  I0: IncStage0
    port map(X=>X(0), S=>Y(0), Cout=>C(0));
  I1: IncStageI
    port map(X=>X(1), S=>Y(1), Cout=>C(1),Cin=>C(0));
  I2: IncStageI
    port map(X=>X(2), S=>Y(2), Cout=>C(2),Cin=>C(1));
  I3: IncStageI
    port map(X=>X(3), S=>Y(3), Cout=>C(3),Cin=>C(2));
  I4: IncStageI
    port map(X=>X(4), S=>Y(4), Cout=>C(4),Cin=>C(3));
  I5: IncStageI
    port map(X=>X(5), S=>Y(5), Cout=> open,Cin=>C(4));

这使 TBinc6 保持原样,因为您最初使用无符号和 to_unsigned 显示它没有错误。

并且不要忘记更改 incStage0 中延迟的时间规范:

architecture behaviour of IncStage0 is
begin
  S <= not X after 1 ns;

之后您可以生成与练习讲义相同的波形。

在 运行 之前,您对数组类型和标量类型及其值之间的区别的回答已超过 99%。给你片段的含糊其词让参加课程的学生声称他们的工作是他们自己的。学习理解,而不是简单的照搬。