
学院:电子工程学院
学号: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 is
Port ( clk : in STD_LOGIC;
clk_1k : out STD_LOGIC;
clk_100 : out STD_LOGIC);
end fenpin;
architecture Behavioral of fenpin is
signal 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';
begin
process(clk)
begin
if clk'event and clk='1' then
if 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)
begin
if 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 is
Port ( 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 is
signal cnt_temp :STD_LOGIC_VECTOR (3 downto 0):="0000";
begin
process(reset,clk)
begin
if reset='0' then cnt_temp<="0000";
elsif clk'event and clk='1' then
if carry_in='1' then
if 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 is
Port ( 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 is
signal cnt_temp:STD_LOGIC_VECTOR(3 downto 0):="0000";
begin
process(reset,clk)
begin
if reset='0' then cnt_temp<="0000";
elsif clk'event and clk='1' then
if carry_in='1' then
if 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 is
Port ( ss : in STD_LOGIC;
en : out STD_LOGIC);
end enable;
architecture Behavioral of enable is
signal en_temp:STD_LOGIC:='0';
begin
process(ss)
begin
if ss'event and ss='0' then
en_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 is
Port ( 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 is
signal sel_temp :STD_LOGIC_VECTOR (2 downto 0);
signal led_temp :STD_LOGIC_VECTOR (3 downto 0);
begin
process(clk)--用时钟信号控制位选
begin
if clk'event and clk='1' then
if 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)--用位选信号控制段选的输出
begin
if 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)--将段选信号译码
begin
led<="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.锁存控制
设计思路:在计数器输出和显示器输入之间添加一个缓存装置,按下锁存键时,计数器的输出赋给一个临时变量,这时锁存控制装置的输出等于计数器的输出。而当按下读取键时,之前赋值的缓存就输入给显示装置,显示器显示的是之前锁存的数据。
源程序如下:
entity latch is
Port ( latch : in STD_LOGIC;
readlatch : in STD_LOGIC;
input1 : in STD_LOGIC_VECTOR (3 downto 0);
input2 : in STD_LOGIC_VECTOR (3 downto 0);
input3 : in STD_LOGIC_VECTOR (3 downto 0);
input4 : in STD_LOGIC_VECTOR (3 downto 0);
input5 : in STD_LOGIC_VECTOR (3 downto 0);
input6 : in STD_LOGIC_VECTOR (3 downto 0);
output1 : out STD_LOGIC_VECTOR (3 downto 0);
output2 : out STD_LOGIC_VECTOR (3 downto 0);
output3 : out STD_LOGIC_VECTOR (3 downto 0);
output4 : out STD_LOGIC_VECTOR (3 downto 0);
output5 : out STD_LOGIC_VECTOR (3 downto 0);
output6 : out STD_LOGIC_VECTOR (3 downto 0));
end latch;
architecture Behavioral of latch is
signal latch1,latch2,latch3,latch4,latch5,latch6: STD_LOGIC_VECTOR(3 DOWNTO 0):="0000";
begin
process(latch)
begin
if latch='0' then
latch1<=input1;
latch2<=input2;
latch3<=input3;
latch4<=input4;
latch5<=input5;
latch6<=input6;
end if;
end process;
process(readlatch)
begin
if readlatch='0' then
output1<=latch1;
output2<=latch2;
output3<=latch3;
output4<=latch4;
output5<=latch5;
output6<=latch6;
else
output1<=input1;
output2<=input2;
output3<=input3;
output4<=input4;
output5<=input5;
output6<=input6;
end if;
end process;
end Behavioral;
三 设计实现
1.顶层设计
2.管脚分配
NET "clk" LOC = T8;
NET "G" LOC = D7;
NET "reset" LOC = H7;
NET "ss" LOC = F4;
NET "sel<0>" LOC = F8;
NET "sel<1>" LOC = D8;
NET "sel<2>" LOC = E7;
NET "L" LOC = G5;
NET "led<0>" LOC = C11;
NET "led<1>" LOC = A11;
NET "led<2>" LOC = B12;
NET "led<3>" LOC = A12;
NET "led<4>" LOC = C12;
NET "led<5>" LOC = C13;
NET "led<6>" LOC = A13;
NET "led<7>" LOC = B14;
NET "Read" LOC = J7;
3.下载过程
(1)光标移至【 Generate Programing File】后单击鼠标右键,然后单击【 Properties】
(2)将Unused IOB Pins选为Pull Up方式
(3)双击【 Generate Programing File】
(4)双击【 Generate Prom, ACE,or JTAG File】
(5) 选择后缀为bit的文件,单击【 Open】,之后单击【 Bypass 】
(6) 右键,单击第一个选项,完成下载
四 测试结果及结论
经实验开发板实际测试,数字跑表运行正常,实现了设计要求,可以精确计时到0.01s,清零,使能端,锁存端,读取端均可对计时过程进行正确控制,达到了预期目标。
