可变模计数器 实验名称:可变模数计数器一、实验目的:设计一个可变模计数器,计数器由3个触发器构成,在外部控制信号S2S1的控制下分别实现模3、模5、模7和模8的计数,即(1)、S2S1=00时,实现模3计数,触发器状态依次为0→1→2→0;(2)、S2S1=01时,实现模5计数,触发器状态依次为0→1→2→3→4→0;(3)、S2S1=10时,实现模7计数,触发器状态依次为0→1→2→3→4→5→6→0;(4)、S2S1=11时,实现模8计数,触发器状态依次为0→1→2→3→4→5→6→7→0;二、实验
内容
财务内部控制制度的内容财务内部控制制度的内容人员招聘与配置的内容项目成本控制的内容消防安全演练内容
:(1)、顶层原理图:(2)、各个模块程序:1、模3:(库略)entitycnt3isport(s2,s1,en,rd:instd_logic;clk:instd_logic;q:outstd_logic_vector(3downto0));endcnt3;architecturecntofcnt3issignalqn:std_logic_vector(3downto0);beginprocess(clk,s1,s2)beginif(rd='0')thenqn<=X"0";elsif(en='0')thenqn<=X"0";elsif(clk'eventandclk='1'ands1='0'ands2='0')thenifqn(3downto0)=X"2" thenqn(3downto0)<="0000";elseqn<=qn+1;endif;endif;endprocess;q<=qn;endcnt;2、模5:(库略) entitycnt5isport(s2,s1,en,rd:instd_logic;clk:instd_logic;q:outstd_logic_vector(3downto0));endcnt5;architecturecntofcnt5issignalqn:std_logic_vector(3downto0);beginprocess(clk,s1,s2)beginif(rd='0')thenqn<=X"0";elsif(en='0')thenqn<=X"0";elsif(clk'eventandclk='1'ands1='1'ands2='0')thenifqn(3downto0)=X"4" thenqn(3downto0)<="0000";elseqn<=qn+1;endif;--else--qn<=X"0";endif;endprocess;q<=qn;endcnt;3、模7:(库略)entitycnt7isport(s2,s1,en,rd:instd_logic;clk:instd_logic;q:outstd_logic_vector(3downto0));endcnt7;architecturecntofcnt7issignalqn:std_logic_vector(3downto0);beginprocess(clk,s1,s2)beginif(rd='0')thenqn<=X"0";elsif(en='0')thenqn<=X"0";elsif(clk'eventandclk='1'ands1='0'ands2='1')thenifqn(3downto0)=X"6" thenqn(3downto0)<="0000";elseqn<=qn+1;endif;--else--qn<=X"0";endif;endprocess;q<=qn;endcnt;4、模8:(库略)entitycnt8isport(s2,s1,en,rd:instd_logic;clk:instd_logic;q:outstd_logic_vector(3downto0));endcnt8;architecturecntofcnt8issignalqn:std_logic_vector(3downto0);beginprocess(clk,s1,s2)beginif(rd='0')thenqn<=X"0";elsif(en='0')thenqn<=X"0";elsif(clk'eventandclk='1'ands1='1'ands2='1')thenifqn(3downto0)=X"7" thenqn(3downto0)<="0000";elseqn<=qn+1;endif;--else--qn<=X"0";endif;endprocess;q<=qn;endcnt;5、decoder显示:(库略)entitydecoderisport(s1,s2:instd_logic;seg:outstd_logic_vector(6downto0);done,dtwo,dthree,dfour:in std_logic_vector(3downto0) );enddecoder;architecturedecofdecoderissignald:std_logic_vector(3downto0);beginprocess(s1,s2)beginif(s1='0'ands2='0')thend<=done;elsif(s1='1'ands2='0') thend<=dtwo;elsif(s1='0'ands2='1') thend<=dthree;elsed<=dfour;endif;endprocess;withdselectseg<="0111111" when"0000","0000110"when"0001","1011011"when"0010","1001111"when"0011","1100110"when"0100","1101101"when"0101","1111101"when"0110","0000111"when"0111","1111111"when"1000","1101111"when"1001","0000000"whenothers;enddec;三、实验总结:通过本次实验,掌握了从顶层文件原理图开始,自上而下的设计电路的方法,感受到此方法的在各个模块程序调试时的方便,有更好的逻辑思路。除此之外,还对VHDL语言的编写、调试,更好的掌握VHDL语言的编写的一些技巧。