EDA技术课程设计报告数字秒表设计.doc
石家庄经济学院信息工程学院电子信息工程专业EDA技术课程设计报告题目: 数 字 秒 表 姓 名 学 号 班 级 指导教师 2011年 1 月 14 日课程设计任务书班级 4081090102 姓名 陈 魏 学号 408109060127 课程设计题目 数字秒表 课程设计起止日期 2010年12月27日 至 2011年1月14日 实习地点 实验楼308 课程设计内容与要求设计一个以0.01s为基准计时信号的实用数字式秒表要求:1、及格:计时显示范围059min59.99s; 2、中:具有清零、启动计时、暂停计时及继续计时功能,操作按键(开关)不超过两个; 3、良:有倒计时功能; 4、优:具有记录最近10次计时操作结果的功能。 指导教师 董建彬 2010 年 12月 27 日课程设计报告一、设计原理与技术方法:包括:电路工作原理分析与原理图、元器件选择与参数计算、电路调试方法与结果说明;软件设计说明书与流程图、软件源程序代码、软件调试方法与运行结果说明。数字秒表计时电路控制电路显示电路时基分频六进制十进制扫描电路七段译码器 图1 数字秒表原理图时基分频:主要是给计时电路一个精确的脉冲信号 计时电路:执行计时功能,计时方法为对标准时钟脉冲计数。计时范围是0秒-59分59.99秒,那么计时采用2个六进制计数器和4个十进制计数器构成,其中毫秒位、十毫秒位、秒位和分位采用十进制计数器,十秒位和十分位采用六进制计数器。 控制电路:主要执行清零、启动、暂停和倒计时功能,分别由开关或按钮控制。 显示电路:计时显示电路的作用是将计时值在LED七段数码管上显示出来。计时电路值经过BCD七段译码后驱动LED数码管。显示则采用扫描显示,每次只驱动一位数码管,各位数据轮流驱动对应的数码管进行显示。图2 数字秒表流程图结束开始显示选通分十分控制开关十秒秒毫秒十毫秒流程图:注:此表可加附页及格:程序下载后计时从0开始到59分59.99s 图3 数字秒表(及格)整体组装设计原理图CB程序(时基分频):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cb isport(clk:in std_logic; clock:out std_logic);end cb;architecture art of cb issignal count:integer range 0 to 70000;signal clk_data:std_logic;beginprocess(clk) -时钟进程begin if clk'event and clk='1' then -上升沿时给脉冲 if count=70000 then -当脉冲计到70000时返回0 count<=0; clk_data<=not clk_data; -此时时钟信号变化 else count<=count+1; -当脉冲没到70000时脉冲加1 end if;end if;clock<=clk_data;end process;end art;COUNT10程序(十进制):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count10 isPort(clk,en:in std_logic; Q:out std_logic_vector(3 downto 0); co:out std_logic);End count10;Architecture rtl of count10 isSignal count_4:std_logic_vector(3 downto 0);Begin Q(0)<=count_4(0); -中间信号变量 Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);Process(clk)Beginif(clk'event and clk='1')then If(en='1')then If(count_4>="1001")then -当开始计数,上升沿且计数到9时 co<='1' -给下一个计数器一个时钟信号,计数值变为0 Count_4<="0000" Else co<='0' -计数值小于等于9时,只需把计数值加1即可 Count_4<=count_4+'1' End if; End if;End if;End process;End rtl; 图4 count10(十进制)仿真图COUNT6A程序(六进制):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count6a isPort(clk,en:in std_logic; Q:out std_logic_vector(3 downto 0); co:out std_logic);End count6a;Architecture rtl of count6a isSignal count_4:std_logic_vector(3 downto 0);Begin Q(0)<=count_4(0); Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);Process(clk)Beginif(clk'event and clk='1')then If(en='1')then If(count_4<="0101")then -当开始计数,上升沿且计数小于等于5时 co<='0' -把计数值加1 Count_4<=count_4+'1' Else -计数大于5时,给下一个计数器一个时钟信号 co<='1' 把计数值变为0 Count_4<="0000" End if; End if;End if;End process;End rtl; 图5 count6a(六进制)仿真图COUNT6程序(六进制):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count6 isPort(clk,en:in std_logic; Q:out std_logic_vector(3 downto 0);End count6;Architecture rtl of count6 isSignal count_4:std_logic_vector(3 downto 0);Begin Q(0)<=count_4(0); Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);Process(clk)Beginif(clk'event and clk='1')then If(en='1')then If(count_4<="0100")then Count_4<=count_4+'1' Else Count_4<="0000" End if; End if;End if;End process;End rtl;图6 count6(六进制)仿真图MUX6程序(六选一选通器):library ieee;use ieee.std_logic_1164.all;entity mux6 isport(INTPUT1:in std_logic_vector(3 downto 0); INTPUT2:in std_logic_vector(3 downto 0); INTPUT3:in std_logic_vector(3 downto 0); INTPUT4:in std_logic_vector(3 downto 0); INTPUT5:in std_logic_vector(3 downto 0); INTPUT6:in std_logic_vector(3 downto 0); a,b,c:in std_logic; y:out std_logic_vector(3 downto 0);end mux6;architecture rt1 of mux6 issignal sel:std_logic_vector(2 downto 0);beginsel<=c&b&a;process(sel)beginif(sel="000")then -当sel为0时,选通十毫秒计数器y<=INTPUT1;elsif(sel="001")then -当sel为1时,选通毫秒计数器y<=INTPUT2;elsif(sel="010")then -当sel为2时,选通秒计数器y<=INTPUT3;elsif(sel="011")then -当sel为3时,选通十秒计数器y<=INTPUT4;elsif(sel="100")then -当sel为4时,选通分计数器y<=INTPUT5; elsey<=INTPUT6; -当sel为其他时,选通十分计数器end if;end process;end rt1;CNT6程序(扫描显示):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity cnt6 isPort(clk:in std_logic; qa,qb,qc:out std_logic); End cnt6;Architecture rtl of cnt6 isSignal count_3:std_logic_vector(2 downto 0);Begin Qa<=count_3(0); Qb<=count_3(1); Qc<=count_3(2); Process(clk)Beginif(clk'event and clk='1')then If(count_3<="100")then Count_3<=count_3+'1' Else Count_3<="000" End if;End if;End process;End rtl;SEG7程序(七段译码):LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY seg7 IS PORT( A:IN STD_LOGIC_VECTOR(3 DOWNTO 0); Y:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);END seg7;ARCHITECTURE a OF seg7 ISBEGIN WITH a SELECTY<="1111110"WHEN "0000", 七段译码器分别在LED数码管上显示a,b,c,d,e,f,g段 "0110000"WHEN "0001", "1101101"WHEN "0010", "1111001"WHEN "0011", "0110011"WHEN "0100", "1011011"WHEN "0101", "1011111"WHEN "0110", "1110000"WHEN "0111", "1111111"WHEN "1000", "1111011"WHEN "1001", "0000000"WHEN OTHERS; END a;中:通过EN开关实现暂停/开启功能,通过CLR开关实现清零功能 CB10程序(时基分频):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cb10 isport(clk:in std_logic; clock:out std_logic);end cb10;architecture art of cb10 issignal count:integer range 0 to 70000;signal clk_data:std_logic;beginprocess(clk)begin if clk'event and clk='1' then if count=70000 then count<=0; clk_data<=not clk_data; else count<=count+1; end if;end if;clock<=clk_data;end process;end art;COUNT10程序(十进制):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count10 isPort(clk,clr,en:in std_logic; Q:out std_logic_vector(3 downto 0); co:out std_logic);End count10;Architecture rtl of count10 isSignal count_4:std_logic_vector(3 downto 0);Begin Q(0)<=count_4(0); Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);Process(clk,clr)BeginIf(clr='1')then Count_4<="0000"Elsif(clk'event and clk='1')then If(en='1')thenIf(count_4>="1001")then co<='1'Count_4<="0000"Else co<='0'Count_4<=count_4+'1'End if;End if;End if;End process;End rtl; 图7 count10(十进制)仿真图COUNT6A程序(六进制):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity count6a isport(clk,clr,en:in std_logic; Q:out std_logic_vector(3 downto 0); co:out std_logic);end count6a;architecture rtl of count6a issignal count_4:std_logic_vector(3 downto 0);begin Q(0)<=count_4(0); Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);process(clk,clr)beginif(clr='1')then -当CLR控制开关为1时,清零 count_4<="0000"elsif(clk'event and clk='1')then if(en='1')thenif(count_4<="0100")then co<='0'count_4<=count_4+'1'else co<='1'count_4<="0000"end if;end if;end if;end process;end rtl;图8 count6a(六进制)仿真图COUNT6程序(六进制):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count6 isPort(clk,clr,en:in std_logic; Q:out std_logic_vector(3 downto 0);End count6;Architecture rtl of count6 isSignal count_4:std_logic_vector(3 downto 0);Begin Q(0)<=count_4(0); Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);Process(clk,clr)BeginIf(clr='1')then -当CLR控制开关为1时,清零 Count_4<="0000"Elsif(clk'event and clk='1')then If(en='1')thenIf(count_4<="0100")thenCount_4<=count_4+'1'Else Count_4<="0000"End if;End if;End if;End process;End rtl;图9 count6(六进制)仿真图MUX6程序(六选一选通器):library ieee;use ieee.std_logic_1164.all;entity mux6 isport(INTPUT1:in std_logic_vector(3 downto 0); INTPUT2:in std_logic_vector(3 downto 0); INTPUT3:in std_logic_vector(3 downto 0); INTPUT4:in std_logic_vector(3 downto 0); INTPUT5:in std_logic_vector(3 downto 0); INTPUT6:in std_logic_vector(3 downto 0); a,b,c:in std_logic; y:out std_logic_vector(3 downto 0);end mux6;architecture rt1 of mux6 issignal sel:std_logic_vector(2 downto 0);beginsel<=c&b&a;process(sel)beginif(sel="000")then y<=INTPUT1;elsif(sel="001")theny<=INTPUT2;elsif(sel="010")theny<=INTPUT3;elsif(sel="011")theny<=INTPUT4;elsif(sel="100")theny<=INTPUT5;elsey<=INTPUT6;end if;end process;end rt1;CNT6程序(扫描显示):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity cnt6 isPort(clk,clr:in std_logic; qa,qb,qc:out std_logic); End cnt6;Architecture rtl of cnt6 isSignal count_3:std_logic_vector(2 downto 0);Begin Qa<=count_3(0); Qb<=count_3(1); Qc<=count_3(2); Process(clk,clr)BeginIf(clr='1')then -当CLR控制开关为1时,清零 Count_3<="000"Elsif(clk'event and clk='1')then If(count_3<="100")then Count_3<=count_3+'1'Else Count_3<="000"End if;End if;End process;End rtl;SEG7程序(七段译码器):library ieee;use ieee.std_logic_1164.all;entity seg7 IS port( A:in std_logic_vector(3 downto 0); Y:out std_logic_vector(6 downto 0);end seg7;architecture a of seg7 isbegin with a selectY<="1111110"when "0000", "0110000"when "0001", "1101101"when "0010", "1111001"when "0011", "0110011"when "0100", "1011011"when "0101", "1011111"when "0110", "1110000"when "0111", "1111111"when "1000", "1111011"when "1001", "0000000"when others;end a;良好:通过UPDOWN开关实现倒计时功能 图10 数字秒表(良好)整体组装设计原理图CB10程序(时基分频):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cb10 isport(clk:in std_logic; clock:out std_logic);end cb10;architecture art of cb10 issignal count:integer range 0 to 100000;signal clk_data:std_logic;beginprocess(clk)begin if clk'event and clk='1' then if count=100000 then count<=0; clk_data<=not clk_data; else count<=count+1; end if;end if;clock<=clk_data;end process;end art;COUNT10程序(十进制):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count10 isPort(clk,updown,clr,en:in std_logic; Q:out std_logic_vector(3 downto 0); co:out std_logic);End count10;Architecture rtl of count10 isSignal count_4:std_logic_vector(3 downto 0);Begin Q(0)<=count_4(0); Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);Process(clk,clr)BeginIf(clr='1')then -当CLR控制开关为1时,清零 Count_4<="0000"Elsif(clk'event and clk='1')then if(en='1')then if(updown='1')then -当updown控制开关为1时进行正计数 If(count_4>="1001")then co<='1' Count_4<="0000" else co<='0' Count_4<=count_4+'1' end if; elsif(updown='0')then -当updown控制开关为0时进行倒计数 if(count_4<="0000")then co<='1' Count_4<="1001" Else co<='0' Count_4<=count_4-'1' End if; end if; End if;end if; End process;End rtl; 图11 count10(十进制)仿真图COUNT6A程序(六进制):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count6a isPort(clk,clr,en,updown:in std_logic; Q:out std_logic_vector(3 downto 0); co:out std_logic);End count6a;Architecture rtl of count6a isSignal count_4:std_logic_vector(3 downto 0);Begin Q(0)<=count_4(0); Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);Process(clk,clr)BeginIf(clr='1')then Count_4<="0000"Elsif(clk'event and clk='1')then If(en='1')then if(updown='1')then -当updown控制开关为1时进行正计数 If(count_4>="0101")then co<='1' Count_4<="0000" Else co<='0' Count_4<=count_4+'1' end if; elsif(updown='0')then -当updown控制开关为0时进行倒计数 If(count_4<="0000")then co<='1' Count_4<="0101" Else co<='0' Count_4<=count_4-'1' end if; end if;End if;End if;End process;End rtl; 图12 count6a(六进制)仿真图COUNT6程序(六进制):Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count6 isPort(clk,clr,en,updown:in std_logic; Q:out std_logic_vector(3 downto 0);End count6;Architecture rtl of count6 isSignal count_4:std_logic_vector(3 downto 0);Begin Q(0)<=count_4(0); Q(1)<=count_4(1); Q(2)<=count_4(2); Q(3)<=count_4(3);Process(clk,clr)BeginIf(clr='1')then Count_4<="0000"Elsif(clk'event and clk='1')then If(en='1')then if(updown='1')then If(count_4>="0101")then Count_4<="0000" Else Count_4<=count_4+'1' end if; elsif(updown='0')then If(count_4>="0000")then Count_4<="0101" Else Count_4<=count_4-'1' end if; end if;End if;End if;End process;End rtl; 图13 count6(六进制)仿真图MUX6程序(六选一选通器):library ieee;use ieee.std_logic_1164.all;entity mux6 isport(INTPUT1:in std_logic_vector(3 downto 0); INTPUT2:in std_logic_vector(3 downto 0); INTPUT3:in std_logic_vector(3 downto 0); INTPUT4:in std_logic_vector(3 downto 0); INTPUT5:in std_logic_vector(3 downto 0); INTPUT6:in std_logic_vector(3 downto 0);