基于VHDL语言的计时秒表设计
设计要求
设计一个带有开始与暂停的计时秒表,秒表的最低位是0.1秒,显示格式为0.00.00.0;带有复位开关。
设计步骤
步骤一:设计分析
1.系统底层设计模块分析
根据系统的设计要求,系统的底层设计主要由分频器模块、十进制计数器模块、六十进制计数器模块、多位数码管显示模块组成。
2.输入、输出信号分析
*(1)*输入信号:
start:计时信号(start=’1’开始计时、start=’0’暂停计时)。
reset:复位信号。
clk:时钟信号(50MHz)。
*(2)*输出信号:
q:数码管阴极控制信号。
a,b,c,d,e,f,g,h:数码管阳极控制信号。
步骤二:模块功能设计
1.分频器(将50MHz脉冲变成10Hz脉冲)
VHDL语言描述:
Library IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;
ENTITY fenpin IS
PORT(clk:IN std_logic;
clk_out:OUT std_logic);
END fenpin;
ARCHITECTURE behave OF fenpin IS
SIGNAL counter :integer range 0 to 2499999;
SIGNAL temp_out :std_logic;
BEGIN
PROCESS(clk)
BEGIN
IF (clk'EVENT AND clk ='1') THEN
counter <= counter+1;
IF (counter = 2499999) THEN
counter <= 0;
temp_out <= NOT temp_out;
END IF;
END IF;
clk_out <= temp_out;
END PROCESS;
END behave;
分频器的仿真图:
2.多位数码管动态扫描分频器(将50MHz脉冲变成100Hz脉冲)
VHDL语言描述:
Library IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;
ENTITY fenpin_100 IS
PORT(clk:IN std_logic;
clk_out:OUT std_logic);
END fenpin_100;
ARCHITECTURE behave OF fenpin_100 IS
SIGNAL counter :integer range 0 to 249999;
SIGNAL temp_out :std_logic;
BEGIN
PROCESS(clk)
BEGIN
IF (clk'EVENT AND clk ='1') THEN
counter <= counter+1;
IF (counter = 249999) THEN
counter <= 0;
temp_out <= NOT temp_out;
END IF;
END IF;
clk_out <= temp_out;
END PROCESS;
END behave;
多位数码管动态扫描分频器仿真图:
3.十进制计数器
VHDL语言描述:
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;
ENTITY cnt_10 IS
PORT(start,reset,clk:IN std_logic;
Q: buffer std_logic_vector(3 downto 0);
RCO : out std_logic );--进位输出端
END cnt_10;
ARCHITECTURE behave OF cnt_10 IS
BEGIN
RCO<='1'WHEN(Q="1001" AND start='1')ELSE '0';
PROCESS(clk,reset)
BEGIN
IF(reset='1')THEN
Q<="0000";
ELSIF(clk'EVENT AND clk = '1')THEN
IF(start='1')THEN
IF(Q="10001")THEN
Q<="0000";
ELSE
Q<=Q+1;
END IF;
END IF;
END IF;
END PROCESS;
END behave;
十进制计数器的仿真图:
4.六十进制计数器
VHDL语言描述:
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;
ENTITY cnt_60 IS
PORT(start,reset,clk:IN std_logic;
DHout:buffer std_logic_vector(3 downto 0); --高四位输出
DLout:buffer std_logic_vector(3 downto 0); --低四位输出
RCO:out std_logic); --进位输出端
END cnt_60;
ARCHITECTURE behave OF cnt_60 IS
BEGIN
RCO<='1'WHEN (DHout="0101" AND DLout="1001" AND start = '1')ELSE '0';--确定进位条件
PROCESS(clk,reset)
BEGIN
IF(reset='1')THEN
QHout<="0000";
QLout<="0000";
ELSIF(clk'EVENT AND clk='1')THEN
IF(start='1')THEN
DLout<=DLout+1;
END IF;
IF(DLout=9)THEN
DLout<="0000";
DHout<=DHout+1;
END IF;
IF(DHout=5 AND DLout=9)THEN
DHout<="0000";
END IF;
END IF;
END PROCESS;
END behave;
六十进制计数器的仿真图:
5.多位数码管显示模块
VHDL语言描述:
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
ENTITY Nixie_tube IS
PORT(num0,num1,num2:IN std_logic_vector(3 downto 0);
num3,num4,num5:IN std_logic_vector(3 downto 0);
clk:IN std_logic;
I:OUT std_logic_vector(5 downto 0); --阴极控制信号
display:OUT std_logic_vector(6 downto 0));
END Nixie_tube;
ARCHITECTURE behave OF Nixie_tube IS
SIGNAL counter: integer range 0 to 5;
BEGIN
PROCESS(clk)
VARIABLE num:std_logic_vector(3 downto 0);
BEGIN
IF (rising_edge(clk))THEN
IF counter=5 THEN
counter <= 0;
ELSE counter <= counter+1;
END IF;
CASE counter IS
WHEN 0 =>
I <= "111110";
num:=num0;
WHEN 1 =>
I <= "111101";
num:=num1;
WHEN 2 =>
I <= "111011";
num:=num2;
WHEN 3 =>
I <= "110111";
num:=num3;
WHEN 4 =>
I <= "101111";
num:=num4;
WHEN 5 =>
I <= "011111";
num:=num5;
END CASE;
CASE num IS
WHEN "0000" => display <= "0111111";
WHEN "0001" => display <= "0000110";
WHEN "0010" => display <= "1011011";
WHEN "0011" => display <= "1001111";
WHEN "0100" => display <= "1100110";
WHEN "0101" => display <= "1101101";
WHEN "0110" => display <= "1111101";
WHEN "0111" => display <= "0000111";
WHEN "1000" => display <= "1111111";
WHEN "1001" => display <= "1100011";
WHEN others => display <= "0000000";
END CASE;
END IF;
END PROCESS;
END behave;
多位数码管显示模块的仿真图:
步骤三:计时秒表的设计
VHDL语言描述:
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;
ENTITY digitalclock IS
PORT(clk :IN std_logic;
reset :IN std_logic;
start :IN std_logic;
q :OUT std_logic_vector(5 downto 0); --阴极控制信号
a,b,c,d,e,f,g,h: OUT std_logic);
END digitalclock;
ARCHITECTURE behave OF digitalclock IS
COMPONENT fenpin IS --分频器元件声明
PORT(clk:IN std_logic;
clk_out:OUT std_logic);
END COMPONENT fenpin;
COMPONENT fenpin_100 IS --多位数码管动态扫描分频器元件声明
PORT(clk:IN std_logic;
clk_out:OUT std_logic);
END COMPONENT fenpin_100;
COMPONENT cnt_10 IS --十进制计数器元件声明
PORT(start,reset,clk:IN std_logic;
Q: buffer std_logic_vector(3 downto 0);
RCO : out std_logic );
END COMPONENT cnt_10;
COMPONENT cnt_60 IS --六十进制计数器元件声明
PORT(start,reset,clk:IN std_logic;
DHout:buffer std_logic_vector(3 downto 0);
DLout:buffer std_logic_vector(3 downto 0);
RCO:out std_logic);
END COMPONENT cnt_60;
COMPONENT Nixie_tube IS --多位数码管显示模块元件声明
PORT(num0,num1,num2:IN std_logic_vector(3 downto 0);
num3,num4,num5:IN std_logic_vector(3 downto 0);
clk:IN std_logic;
I:OUT std_logic_vector(5 downto 0);
display:OUT std_logic_vector(6 downto 0));
END COMPONENT Nixie_tube;
SIGNAL clk_temp1,clk_temp2: std_logic;
SIGNAL NUM0,NUM1,NUM2,NUM3,NUM4,NUM5:std_logic_vector(3 downto 0);
SIGNAL RCO1,RCO2,RCO3,RCO4:std_logic;
BEGIN
h<='1';
A1:fenpin
PORT MAP(clk=>clk,clk_out=>clk_temp1);
A2:fenpin_100
PORT MAP(clk=>clk,clk_out=>clk_temp2);
A3:cnt_10
PORT MAP(start=>start,reset=>reset,clk=>clk_temp1,Q=>NUM0,RCO=>RCO1);
A4:cnt_60
PORT MAP(start=>start,reset=>reset,clk=>clk_temp1,DHout=>NUM2,DLout=>NUM1,
RCO=>RCO2);
A5:cnt_60
PORT MAP(start=>start,reset=>reset,clk=>clk_temp1,DHout=>NUM4,DLout=>NUM3,
RCO=>RCO3);
A6:cnt_10
PORT MAP(start=>start,reset=>reset,clk=>clk_temp1,Q=>NUM5,RCO=>RCO4);
A7:Nixie_tube
PORT MAP(num0=>NUM0,num1=>NUM1,num2=>NUM2,num3=>NUM3,num4=>NUM4,num5=>NUM5,
clk=>clk_temp2,I=>q,display(0)=>a,display(1)=>b,display(2)=>c,display(3)=>d,
display(4)=>e,display(5)=>f,display(6)=>g);
END behave;
RTL原理图
:
心得体会
*1.*主频脉冲(50MHz)的频率设置的太大,导致各个模块时序仿真的效果不是很好。
*2.*在 Quartus II 编译过程中,出现**Error: Node instance “XXX” instantiates undefined entity “XXX”**的错误时的解决方案。
分析:程序报错的原因是由于在元件例化过程中,实体未被定义。
具体解决方法如下:
以**Error: Node instance “A2” instantiates undefined entity “fenpin_100″**为例。
(1)在 Quartus II 的工具栏的File->Open,打开”fenpin_100″的vhd文件。
(2)点击工具栏的Project->Add Current File to Project。
(3)重新编译。
*3.*在系统的设计过程中,运用了分频器模块、十进制计数器模块、六十进制计数器模块、多位数码管显示模块的VHDL语言描述,对多位数码管显示的动态扫描原理有了更进一步的了解,深刻理解了“自顶向下”的设计思想,将极其复杂的数字系统划分成一系列的层次分明的模块,以此来完成系统整体结构的设计。