数字跑表(电子科大)
- 格式:doc
- 大小:196.00 KB
- 文档页数:16
数字跑表设计报告学院:电子工程学院学号:2011029180015姓名:洪娜建班级:电磁场5班一系统总体设计设计要求设计一个数字秒表,有6个输出显示,分别为百分之一秒、十分之一秒、秒、十秒、分、十分,系统主要由显示译码器、分频器、十进制计数器和六进制计数器组成。
整个秒表还需有一个启动/停止信号和一个复位信号,以便秒表能随意停止及启动。
要求:1、跑表精度为0.01秒2、跑表计时范围为:1小时3、设置开始计时/停止计时、复位两个按钮4、显示工作方式:用六位BCD七段数码管显示读数5、扩展功能:锁存控制功能。
系统工作原理数字跑表通过系统将48MHz时钟进行分频得到100Hz的秒表时钟,之后通过对时钟信号进行计数得到具体的跑表显示数值,跑表数值作为显示单元电路的输入,显示单元控制数码管动态扫描显示计数因此,系统主要划分为:分频器,计数器,显示控制,开始\停在使能控制,清零控制,锁存控制。
原理图如下:二单元电路设计1.分频器设计思路:输入信号48MHz,将其48000分频可得1KHz信号,再将1KHz信号10分频可得100Hz信号。
1KHz用于显示LED扫描,100Hz用于计数器时钟。
源程序如下:entity fenpin isPort ( clk : in STD_LOGIC;clk_1k : out STD_LOGIC;clk_100 : out STD_LOGIC);end fenpin;architecture Behavioral of fenpin issignal cnt1:INTEGER RANGE 1 TO 24000;signal cnt2:INTEGER RANGE 1 TO 5;signal clk_1k_temp:STD_LOGIC:='0';signal clk_100_temp:STD_LOGIC:='0';beginprocess(clk)beginif clk'event and clk='1' thenif cnt1=24000 then cnt1<=1;clk_1k_temp<=not clk_1k_temp;else cnt1<=cnt1+1;end if;end if;end process;clk_1k<=clk_1k_temp;process(clk_1k_temp)beginif clk_1k_temp'event and clk_1k_temp='1' then if cnt2=5 then cnt2<=1;clk_100_temp<=not clk_100_temp;else cnt2<=cnt2+1;end if;end if;end process;clk_100<=clk_100_temp;end Behavioral;2.计数器实验需要用到2个六进制计数器和4个十进制计数器,本人使用的级联方式为同步级联。
十进制计数器的源程序:entity counter10 isPort ( reset : in STD_LOGIC;clk : in STD_LOGIC;carry_in : in STD_LOGIC;carry_out : out STD_LOGIC;cnt_out : out STD_LOGIC_VECTOR (3 downto 0));end counter10;architecture Behavioral of counter10 issignal cnt_temp :STD_LOGIC_VECTOR (3 downto 0):="0000";beginprocess(reset,clk)beginif reset='0' then cnt_temp<="0000";elsif clk'event and clk='1' thenif carry_in='1' thenif cnt_temp<"1001" then cnt_temp<=cnt_temp+1;else cnt_temp<="0000";end if;end if;end if;if carry_in='1' and cnt_temp="1001" then carry_out<='1';else carry_out<='0';end if;end process;cnt_out<=cnt_temp;end Behavioral;仿真结果:六进制计数器的源程序为:entity counter6 isPort ( reset : in STD_LOGIC;clk : in STD_LOGIC;carry_in : in STD_LOGIC;carry_out : out STD_LOGIC;cnt_out : out STD_LOGIC_VECTOR(3 downto 0)); end counter6;architecture Behavioral of counter6 issignal cnt_temp:STD_LOGIC_VECTOR(3 downto 0):="0000"; beginprocess(reset,clk)beginif reset='0' then cnt_temp<="0000";elsif clk'event and clk='1' thenif carry_in='1' thenif cnt_temp<"0101" then cnt_temp<=cnt_temp+1;else cnt_temp<="0000";end if;end if;end if;if carry_in='1' and cnt_temp="0101" then carry_out<='1';else carry_out<='0';end if;end process;cnt_out<=cnt_temp;end Behavioral;仿真结果:3.使能控制按一下使能控制键,跑表开始计时,再次按下,跑表暂停计时,且计数器使能端高电平有效。
因此程序设计思路为:最初提供一个低电平信号‘0’,按一下使能控制键时,信号翻转位‘1’,开始计时;当再次按下使能控制键时,信号再次翻转,变为‘0’,计时暂停。
源程序为:entity enable isPort ( ss : in STD_LOGIC;en : out STD_LOGIC);end enable;architecture Behavioral of enable issignal en_temp:STD_LOGIC:='0';beginprocess(ss)beginif ss'event and ss='0' thenen_temp<=not en_temp;end if;end process;en<=en_temp;end Behavioral;4.显示控制显示控制电路根据输入的时钟信号对输入的数据信号进行选择输出,同时输出位选信号控制数码管的动态信号。
显示控制模块应包含一个六进制计数器、六选一数据选择器和七段译码器,六进制计数器的时钟信号频率为1KHZ,计数输出作为位选控制信号sel(2:0),数据选择器的地址控制信号为计数输出,数据选择器的数据端为要显示的六位数据mh(3:0),ml(3:0),sh(3:0),sl(3:0),ds(3:0),cs(3:0),根据地址控制信号选择其中一路输出至译码器,译码器的输出作为段选控制信号led(6:0)。
源程序为:entity xianshi isPort ( clk : in STD_LOGIC;mh : in STD_LOGIC_VECTOR (3 downto 0);ml : in STD_LOGIC_VECTOR (3 downto 0);sh : in STD_LOGIC_VECTOR (3 downto 0);sl : in STD_LOGIC_VECTOR (3 downto 0);ds : in STD_LOGIC_VECTOR (3 downto 0);cs : in STD_LOGIC_VECTOR (3 downto 0);sel : out STD_LOGIC_VECTOR (2 downto 0);led : out STD_LOGIC_VECTOR (7 downto 0);G : out STD_LOGIC);end xianshi;architecture Behavioral of xianshi issignal sel_temp :STD_LOGIC_VECTOR (2 downto 0);signal led_temp :STD_LOGIC_VECTOR (3 downto 0); beginprocess(clk)--用时钟信号控制位选beginif clk'event and clk='1' thenif sel_temp="101" then sel_temp<="000";else sel_temp<=sel_temp+1;end if;end if;end process;process(sel_temp,cs,ds,sl,sh,ml,mh)--用位选信号控制段选的输出beginif sel_temp="000" then led_temp<=cs;elsif sel_temp="001" then led_temp<=ds;elsif sel_temp="010" then led_temp<=sl;elsif sel_temp="011" then led_temp<=sh;elsif sel_temp="100" then led_temp<=ml;else led_temp<=mh;end if;end process;process(led_temp)--将段选信号译码beginled<="11111111";if led_temp="0000" then led<="00000011";elsif led_temp="0001" then led<="10011111";elsif led_temp="0010" then led<="00100101";elsif led_temp="0011" then led<="00001101";elsif led_temp="0100" then led<="10011001";elsif led_temp="0101" then led<="01001001";elsif led_temp="0110" then led<="01000001";elsif led_temp="0111" then led<="00011111";elsif led_temp="1000" then led<="00000001";elsif led_temp="1001" then led<="00001001";end if;end process;G<='0';sel<=sel_temp;end Behavioral;5.锁存控制设计思路:在计数器输出和显示器输入之间添加一个缓存装置,按下锁存键时,计数器的输出赋给一个临时变量,这时锁存控制装置的输出等于计数器的输出。