计数器的VHDL设计Word下载.docx
《计数器的VHDL设计Word下载.docx》由会员分享,可在线阅读,更多相关《计数器的VHDL设计Word下载.docx(12页珍藏版)》请在冰点文库上搜索。
Cout:
outstd_logic);
Endcnt10;
Architectureoneofcnt10is
Begin
Process(clk,RST,SET,EN)
VariableCQ1:
std_logic_vector(3downto0);
Begin
ifRST='
0'
ThenCQ1:
=(others=>
'
);
elsifclk'
eventandclk='
1'
then
ifSET='
elsifEN='
Then
ifCQ1<
9ThenCQ1:
=CQ1+1;
elseCQ1:
endif;
ifCQ1=9Thencout<
='
;
elsecout<
endif;
CQ<
=CQ1;
Endprocess;
Endone;
②程序编译错误情况
错误:
Error(10500):
VHDLsyntaxerrorat/cnt10.vhd(12)neartext"
?
expecting"
:
"
or"
"
标点符号格式输入不对引起的,切换到英文输入模式重新输入即可
③正确的程序
3.仿真波形图
4.仿真波形分析
当低电平清零信号有效时,计数器清零;
当低电平置数信号有效时,计数器置数
使能信号为高电平且脉冲上升沿有效时,计数器开始计数(从0到9)为十进制计数
一、64进制的二进制计数器的VHDL设计
Entitycnt64is
Port(clk:
D:
instd_logic_vector(5downto0);
Q:
outstd_logic_vector(5downto0));
Endcnt64;
Architecturetwoofcnt64is
SignalQ1:
std_logic_vector(5downto0);
Process(clk)
Begin
ifclk'
if(Q1="
011111"
)ThenQ1<
="
000000"
elseQ1<
=Q1+1;
Endprocess;
Q<
=Q1;
Endtwo;
VHDLsyntaxerroratcnt64.vhd(18)neartext"
process"
if"
;
VHDLsyntaxerroratcnt64.vhd(20)neartext"
two"
经过检查,发现原程序少了ENDIF,加上即可;
EntityCDU_64is
Q:
outstd_logic_vector(7downto0));
EndCDU_64;
ArchitecturethreeofCDU_64is
Signalcout2,cout1:
std_logic_vector(3downto0);
if(cout2=6andcout1=3)Then
cout2<
0000"
cout1<
elseif(cout1=9)then
=cout2+1;
cout1<
elsecout2<
=cout2;
=cout1+1;
=cout2&
cout1;
Endthree;
无
64进制的BCD码设计:
分为高四位和低四位,当低四位从0到9时,高四位进1,直到低四位从0到9,使得高四位从0到6,最后一次低四位计数到3为止,实现64进制的BCD码计数功能
一、8位左移计数器的VHDL设计
Entityshfrtis
Port(clk,load:
DIN:
instd_logic_vector(7downto0);
QB:
Endshfrt;
Architecturefourofshfrtis
process(clk,Load)
variableREG8:
std_logic_vector(7downto0);
ifload='
ThenREG8:
=DIN;
elseREG8(7downto1):
=REG8(6downto0)
REG8(0):
QB<
=REG8(7);
Endfour;
错误Error(10500):
VHDLsyntaxerroratshfrt.vhd(16)neartext"
REG8"
发现原程序中少了一个分号,添加后即可。
outstd_logic_vector(7downto0));
=REG8(6downto0);
=REG8;
当load=1且为下降沿时开始左移移位,最低位补‘1’,输出端为8位同时输出,即实现了并行输出的功能。