实验一 序列检测器

一、实验内容

设计一个序列检测器检测序列 1110010。使用波形图进行仿真(至少要有一个检测成功

的波形)。

二、设计过程

每输入一个序列 1110010 则会在输出端输出一个 1,其余时间为 0。

首先写出状态转移图,再利用 case 语句,根据状态转移图写出状态的转移及输出。

检测序列为七位,所以可以设状态机状态数为 8 个;

输出信号由当前状态和输入条件决定,设计为 mealy 型状态机或 moore 型状态机,采用

异步复位

img

三、源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sequence1 is
port(cl,i,reset:in std_logic;
o: out std_logic);
end sequence1;

architecture a of sequence1 is
type mytype is (A,B,C,D,E,F,G,H);
signal ty:mytype;
begin
process(cl,reset)
begin
if reset='0' then
ty<=A;
elsif cl'event and cl='1' then
case ty is
when A=>if i='1' then ty<=B;end if;
when B=>if i='1' then ty<=C;
else ty<=A;end if;
when C=>if i='1' then ty<=D;
else ty<=A;end if;
when D=>if i='0' then ty<=E;
else ty<=B;end if;
when E=>if i='0' then ty<=F;
else ty<=B;end if;
when F=>if i='1' then ty<=G;
else ty<=A;end if;
when G=>if i='0' then ty<=H;
else ty<=B;end if;
when H=>if i='1' then ty<=B;
else ty<=A;end if;
end case;
end if;
end process;
output_p:
process(ty)
begin
case ty is
when H=>o<='1';
when others=>o<='0';
end case;
end process;
end architecture;

四、仿真验证与实验结果

img

从波形图中可以看出输入“1110010”后输出1,当reset为“0”重置时,输出“1”变为“0”。

实验二 计数器

一、实验内容

计数器是通过电路的状态反映驶入脉冲数目的电路。计数器是应用非常广泛的时序电路,

按照技术的特点分为二进制计数器、十进制计数器、环形计数器、扭环形计数器等。二进制

计数器又分为加计数器、减计数器等。

二、设计过程

用 VHDL 语言实现计数状态连续的模值为 2N的计数器。这是一个同步清零的 4 为二进

制加计数器,其计数的状态是从“0000~1111”进行变化。整个的计数周期是 16 个时钟周期,即 24 个时钟周期。凡是这种技术周期为 2N且对计数状态无特殊要求的计数器,可以通过直接定义 N 位的计数信号和端口,对信号进行加或减操作,而不必进行计数状态的判断和控制。使用波形图进行仿真。

三、源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library ieee;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_1164.all;
entity sequence2 is
port(clk:in std_logic;
p:out std_logic;
q:out std_logic_vector(3 downto 0));
end sequence2;
architecture a of sequence2 is
begin
process(clk)
variable x:std_logic_vector(3 downto 0);
begin
if clk'event and clk='1' then
if x<"1111" then x:=x+1;
else x:="0000";
end if;
end if;
if x="1111" then p<='1';
else p<='0';
end if;
q<=x;
end process;
end architecture;

四、仿真验证与实验结果

img

实现加一功能,当达到1111时输出为1.

实验三 8 位寄存器74374

一、实验内容

在数字系统中,寄存器可用来存储一组二进制代码,而触发器具有记忆功能,所以可以

用触发器构成寄存器。本实验要求同学们完成 8 位寄存器 74374 的 VHDL 描述。74374 的逻辑框图如下图所示,功能表如下表所示。逻辑框图中 D 为寄存器的 8 位数据输入,Q 位寄存器的 8 位数据输出端,CLK 为时钟信号,OE 为控制信号。从功能表可以看出 OE 为低电平时,在时钟上升沿输入端信号从输出端输出,其他时刻输出保持;而 OE 为高电平时, 输出一直保持为高阻。

img

二、设计过程

根据 74374 的逻辑框图和真值表,用 VHDL 语言实现 74374 的功能。并使用波形图进

行仿真。

三、源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sequence3 is
port(OE,CLK:in std_logic;
D:in std_logic_vector(7 downto 0);
Q:out std_logic_vector(7 downto 0));
end sequence3;
architecture a of sequence3 is
begin
process(CLK,OE,D)
begin
if OE='1' then
Q<="11111111";
elsif CLK'event and CLK='1' then
Q<=D;
end if;
end process;
end architecture;

四、仿真验证与实验结果

img