计数计时器的VHDL设计_第1页
计数计时器的VHDL设计_第2页
计数计时器的VHDL设计_第3页
计数计时器的VHDL设计_第4页
计数计时器的VHDL设计_第5页
已阅读5页,还剩26页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、计数/计时器的vhdl设计本课要解决的问题:n一般计时器的vhdl描述;n六十进制计数器和计时器的vhdl设计;n二十四进制计时器的vhdl设计;n数字钟的vhdl设计。一、 计数器的作用n在时钟的驱动下,对输入脉冲进行计数;如果输入的脉冲为时钟脉冲,就成为计时器。n当计数值达到一定数值,计数器产生进位输出,并复位。 二、计数器的设计(p63-67)n简单计时器的设计;n六十进制计数器和计时器的设计;n二十四进制计时器的设计;n数字钟的设计。n最简单的计时器entity cnt4 is port ( clk : in bit ; q : buffer integer range 15 down

2、to 0 ) ; end ; architecture bhv of cnt4 is begin process (clk) begin if clkevent and clk = 1 then q = q + 1 ; end if; end process ;end bhv; buffer模式才可以读取在时钟clk信号的驱动下q对时钟信号clk进行计数;由于q为buffer模式,所以可以读取q的值【例3-19】表式表式q = q + 1q = q + 1的右项与左项并非处于相同的时刻内,对于时序电的右项与左项并非处于相同的时刻内,对于时序电路,除了传输延时外,前者的结果出现于当前时钟周期;后

3、者,即路,除了传输延时外,前者的结果出现于当前时钟周期;后者,即左项要获得当前的左项要获得当前的q + 1q + 1,需等待下一个时钟周期。,需等待下一个时钟周期。 时钟信号到来?时钟信号到来?q计数加计数加1结束结束 library ieee ; use ieee.std_logic_1164.all ; use ieee.std_logic_unsigned.all ; entity cnt4 is port ( clk : in std_logic ; q : out std_logic_vector(3 downto 0) ) ; end ; architecture bhv of c

4、nt4 issignal q1 : std_logic_vector(3 downto 0); begin process (clk) begin if clkevent and clk = 1 then q1 = q1 + 1 ; end if; end process ; q 0) ; elsif clkevent and clk=1 then if en = 1 then if cqi 0); end if; end if; end if; if cqi = 9 then cout = 1; else cout = 0; end if; cq 0) 为省略赋值方式,对cqi清零检测是否允

5、许计数允许计数允许计数, 检测是否小于检测是否小于9大于大于9,计数值清零,计数值清零计数大于等于9,输出进位信号将计数值向端口输出library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity bcd60count isport(clk, bcd1wr, bcd10wr, cin: in std_logic; co: out std_logic; datain: in std_logic_vector(3 downto 0); bcd10n: buffer std_logic_vector(2 d

6、ownto 0); bcd1n: buffer std_logic_vector(3 downto 0);end bcd60count;【六十进制计数器】|实体n 六十进制计数器的设计clk: 时钟端;bcd1wr, bcd10wr: 计数初值的个位和十位允许写入端;datain: 计数初值输入端;bcd1n, bcd10n: 计数值的个位输出和十位输出;co: 计数值进位输出。|结构体architecture behave of bcd60count isbeginend behave;process(clk, bcd1wr)beginif(bcd1wr=1) then bcd1n=data

7、in;elsif(clkevent and clk=1) then if(cin=1) then if(bcd1n=“1001”) then bcd1n=0000; else bcd1n=bcd1n+1; end if; end if;end if;end process;process (bcd10n, bcd1n, cin)beginif(cin=1 and bcd1n=“1001” and bcd10n=“101”) then co=1;else co=0;end if;end process;process(clk, bcd10wr)beginif(bcd10wr=1) then bc

8、d10n=datain(2 downto 0);elsif(clkevent and clk=1) then if(cin=1 and bcd1n=“1001”) then if(bcd10n=“101”) then bcd10n=000; else bcd10n=bcd10n+1; end if; end if;end if;end process;process(clk, bcd1wr)beginif(bcd1wr=1) then bcd1n=datain;elsif(clkevent and clk=1) then if(cin=1) then if(bcd1n=“1001”) then

9、 bcd1n=0000; else bcd1n=bcd1n+1; end if; end if;end if;end process;进程处理个位计数bcd1wr为1时,对个位bcd1n进行置位在时钟信号驱动下,当进位输入cin为1时,若bcd1n为9则归零;否则bcd1n加1计数process(clk, bcd10wr)beginif(bcd10wr=1) then bcd10n=datain(2 downto 0);elsif(clkevent and clk=1) then if(cin=1 and bcd1n=“1001”) then if(bcd10n=“101”) then bcd

10、10n=000; else bcd10n=bcd10n+1; end if; end if;end if;end process;进程处理十位计数bcd10wr为1时,对十位bcd10n进行置位在时钟信号驱动下,当进位输入cin为1时, 个位bcd1n为9,若十位bcd10n为5, 则bcd10n归零;否则bcd1n加1计数process (bcd10n, bcd1n, cin)beginif (cin=1 and bcd1n=“1001” and bcd10n=“101”) then co=1;else co=0;end if;end process;进程处理进位输出当个位bcd1n为9,

11、十位bcd10为5, 即计数值为59时,若cin为1表示再来一个进位输入需要计数,则计数器有进位要输出六十进制计时器六十进制计时器library ieee;use ieee.std_logic_1164.all;entity clk_s isport(clk: in std_logic; q1: buffer integer range 0 to 9; qt: buffer integer range 0 to 6; co: out std_logic);end clk_s;architecture behav of clk_s isbeginprocess(clk)beginif(clkev

12、ent and clk=1) then if(q1=9) then q1=0; else q1=q1+1; end if;end if;end process;process(clk,q1)beginif(clkevent and clk=1) then if(q1=9) then if(qt=5) then qt=0; else qt=qt+1; end if; end if;end if;end process;process(clk, q1, qt)beginif(clkevent and clk=1) then if(qt=5 and q1=9) then co=1; else co=

13、0; end if;end if;end process;end behav;二十四进制计数器entity clk_h isport(clk: in bit; q1: buffer integer range 0 to 9; qt: buffer integer range 0 to 2; co: out bit);end clk_h;n二十四进制计数器的设计architecture a_clk_h of clk_h isbeginprocess(clk, qt)beginif (clkevent and clk=1) then if (qt=2 and q1=3) then q1=0; el

14、sif (q1=9) then q1=0; else q1=q1+1; end if;end if;end process;process(q1, clk)beginif (clkevent and clk=1) then if(q1=3) then if (qt=2) then qt=0; end if; elsif (q1=9) then qt=qt+1; end if;end if;end process;process(q1, qt, clk)beginif (clkevent and clk=1) then if (q1=3 and qt=2) then co=1; else co=

15、0; end if;end if;end process;end a_clk_h;n实验: 数字钟的设计六十进制计数器 (秒)六十进制计数器 (分)二十四进制计数器 (小时)基准脉冲秒进位分进位秒显示分显示小时显示三、分频器n 分频器以计数器为基础实现;n 对输入脉冲进行计数,输入为n个脉冲时,输出为1个脉冲,输出信号即对输入信号进行n分频。输入n个脉冲输出1个脉冲entity cnt4 is port ( clk : in bit ; q : buffer integer range 15 downto 0 ; cout: out bit ) ; end ; architecture bhv

16、 of cnt4 is begin process (clk) begin if clkevent and clk = 1 then if q=4 then q=0; else q = q + 1 ; end if; end if; if q =4 then cout = 1; else cout =4 then q:=0; else q := q + 1 ; end if; end if; if qp then cout = 1; else cout = 0; end if; end process ;end bhv; n占空比为50%的偶数倍分频器:n方案一:当计数器计数到n/2-1时,输

17、出信号翻转,同时计数器复位;n方案二:计数器为0n/2-1时,输出信号为0;计数器为n/2n-1时,输出信号为1。50%占空比的6分频器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity clk_div1 isport(clk_in:in std_logic; clk_out:out std_logic);end clk_div1;第一种方案:architecture a of clk_div1 issignal clk_outq

18、: std_logic:=0;signal countq:std_logic_vector(2 downto 0):=“000”;begin process(clk_in) begin if(clk_inevent and clk_in=1) then if(countq/=2)then countq=countq+1; else clk_outq=not clk_outq; countq0); end if; end if; end process;clk_out=clk_outq;end a;第二种方案:architecture b of clk_div1 issignal countq:

19、std_logic_vector(2 downto 0);begin process(clk_in) begin if(clk_inevent and clk_in=1) then if(countq5) then countq=countq+1; else countq0); end if; end if; end process; process(countq) begin if (countq3) then clk_out=0; else clk_out=1; end if; end process;end b;n占空比50%的奇数倍分频器: 欲实现占空比为50%的2n+1分频器,则需要对待分频时钟上升沿和下降沿分别进行n分频,然后将两个分频所得的时钟信号相或得到占空比为50%的2n+1分频器。library ieee;use

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论