计数器的VHDL设计.doc
文本预览下载声明
实验名称: 计数器的VHDL设计
一、带高电平使能信号,低电平清零信号,低电平置数信号的十进制计数器的VHDL设计
1.实体框图
2.程序设计
①编译前的程序
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
Entity cnt10 is
Port(clk,RST,SET,EN:in std_logic;
CQ:out std_logic_vector(3 downto 0);
Cout:out std_logic);
End cnt10;
Architecture one of cnt10 is
Begin
Process(clk,RST,SET,EN)
Variable CQ1:std_logic_vector(3 downto 0);
Begin
if RST=0 Then CQ1:=(others=0);
elsif clkevent and clk=1 then
if SET=0 Then CQ1:=(others=1);
elsif EN=1 Then
if CQ19 Then CQ1:=CQ1+1;
else CQ1:=(others=0);
end if;
end if;
end if;
if CQ1=9 Then cout=1;
else cout=0;
end if;
CQ=CQ1;
End process;
End one;
②程序编译错误情况
错误:
Error (10500): VHDL syntax error at /cnt10.vhd(12) near text ?; expecting :, or ,
标点符号格式输入不对引起的,切换到英文输入模式重新输入即可
③正确的程序
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
Entity cnt10 is
Port(clk,RST,SET,EN:in std_logic;
CQ:out std_logic_vector(3 downto 0);
Cout:out std_logic);
End cnt10;
Architecture one of cnt10 is
Begin
Process(clk,RST,SET,EN)
Variable CQ1:std_logic_vector(3 downto 0);
Begin
if RST=0 Then CQ1:=(others=0);
elsif clkevent and clk=1 then
if SET=0 Then CQ1:=(others=1);
elsif EN=1 Then
if CQ19 Then CQ1:=CQ1+1;
else CQ1:=(others=0);
end if;
end if;
end if;
if CQ1=9 Then cout=1;
else cout=0;
end if;
CQ=CQ1;
End process;
End one;
3.仿真波形图
4.仿真波形分析
当低电平清零信号有效时,计数器清零;当低电平置数信号有效时,计数器置数
使能信号为高电平且脉冲上升沿有效时,计数器开始计数(从0到9)为十进制计数
一、64进制的二进制计数器的VHDL设计
1.实体框图
2.程序设计
①编译前的程序
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
Entity cnt64 is
Port( clk:in std_logic;
D:in std_logic_vector(5 downto 0);
Q:out std_logic_vector(5 downto 0));
End cnt64;
Architecture two of cnt64 is
Signal Q1: std_logic_vector(5 downto 0);
Begin
Process(clk)
Begin
if clkevent
显示全部