实验五:计数器及七段数码显示译码器设计
一、实验目的:
1 进一步掌握VHDL语言的基本结构及设计的输入方法; 2 掌握VHDL语言的时序电路的设计方法; 3学习七段数码显示译码器设计;
4 学习VHDL的CASE语句应用及多层次设计方法。 二、实验内容
(一)七段数码显示译码器设计
七段数码是纯组合电路,通常的小规模专用IC,如74或4000系列的器件只能作十进制BCD码译码,然而数字系统中的数据处理和运算都是二进制的,所以输出表达式都是十六进制的,为了满足十六进制的译码显示,最方便的方法就是利用译码程序在FPGA/CPLD中实现。作为七段译码器,输出信号LED7S的输出分别接数码管的7个段。 (参考P141图4-87)。
(二)计数器
1、设计一个带使能输入、进位输出及同步清0的增1十进制计数器,波形图见图
管脚分配:输入时钟管脚clk-P78;同步清0管脚clr-P103,使能输入管脚en-P104,输出接一个数码管,管脚分配对应为161、162、163、164、166、167、168;进位位管脚P111(或170)。
2、设计一个用数码管显示的60进制同步计数器,个位显示0~9,十位显示0~5。 算法设计:个位计数器的模M=10,十位计数器的模M=6。用IF 语句描述计数器。 管脚分配:输入时钟管脚clk-P78,两个数码管管脚分别为:
SEG1(a,b,c,d,e,f,g,p)——P161, P162, P163, P164 P166, P167, P168, P169。 SEG2(a,b,c,d,e,f,g,p)——P170,P172,P173,P174,P175,P176,P177,P179 附:24进制计数器
library ieee; -------调用库 use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;
entity twelveto1 is -------实体描述 port(clk: in std_logic; --------端口说明 outputa:out std_logic_vector(0 to 6); outputb:out std_logic_vector(0 to 6)); end twelveto1;
architecture arch_twelveto1 of twelveto1 is --------结构体描述 signal sa:std_logic_vector(3 downto 0); signal sb:std_logic_vector(3 downto 0); begin
process(clk) --------进程语句描述 begin
if (clk'event and clk='1') then --------二十四归一条件语句模块 if (sa=3 and sb=2) then sa<=\ sb<=\ else
if sa=9 then
sa<=\ sb<=sb+1; else
sa<=sa+1; end if; end if; end if; end process;
with sa select outputa<=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ with sb select outputb<=\ \ \ \ \ \ \ \ \ \ --段码转换模块 --1 --2 --3 --4 --5 --6 --7 --8 --9 --A --b --C --d --E --F --0
--段码转换模块 --1 --2 --3 --4 --5 --6 --7 --8 --9 --A
\ --b \ --C \ --d \ --E \ --F \ --0 end arch_twelveto1;
3、设计一个分频电路:已知cpld/fpga信号源脉冲频率为50M,试编写一分频程序,得到一周期为1秒(频率为1Hz)的脉冲频率。
4、设计60进制计数器,计数频率为1Hz,并用七段数码管显示。 三、实验报告
1、简要说明实验步骤。
2、写出实验用的VHDL源程序。
3、记录仿真结果(波形),说明输出延时情况。 4、记录实验结果,并分析其结果的正确性。
5、说明实验中遇到的问题及解决方法,写出实验心得体会。
实验六 简单数字钟设计
数字钟是一个将“ 时”,“分”,“秒”显示于人的视觉器官的计时装置。它的计时周期为24小时,显示满刻度为23时59分59秒,另外应有校时功能和报时功能。干电路系统由秒信号发生器、“时、分、秒”计数器组成。“秒计数器”采用60进制计数器,每累计60秒发现一个“分脉冲”信号,该信号将作为“分计数器”的时钟脉冲。“分计数器”也采用60进制计数器,每累计60分钟,发出一个“时脉冲”信号,该信号将被送到“时计数器”。“时计数器”采用24进制计时器,可实现对一天24小时的累计。
基本要求:实现时分秒的准确计时(可采用完全VHDL实现;也可用混合输入设计,底层VHDL,顶层用原理图电路设计)
拓展要求:1、加入校时校分电路;2、加入整点/定点报时功能。 附:
1、串行扫描显示电路设计:通过用VHDL语言设计串形扫描显示电路
用VHDL设计,示例如下:、
library ieee; -------调用库 use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity tcx is -------实体说明
port( inclk:in std_logic; -------输入输出定义 outa:out std_logic_vector(6 downto 0); outb:out std_logic_vector(2 downto 0)); end tcx;
architecture arth_tcx of tcx is --------结构体定义 signal ma:std_logic_vector(2 downto 0); signal mb:std_logic_vector(3 downto 0); signal fp:std_logic_vector(24 downto 0); signal f:std_logic; begin
process(inclk) begin
if (inclk'event and inclk='1') then if fp=24999999 then
fp<=\ f<=not f; else
fp<=fp+1; end if; end if; end process;
process(f) begin
if (f'event and f='1') then ma<=ma+1; mb<=mb+1; end if; end process; Outb<=ma;
with mb select outa<= \ \ \ \ \ \ \ \ \ \ \ ---------进程说明---------分频模块 ---------扫描输出模块 ---------段码转换模块 --1 --2 --3 --4 --5 --6 --7 --8 --9 --A --b
\ --C \ --d \ --E \ --F \ --0 end arth_tcx;
2、 动态显示的十进制计数器
library ieee; --调用库 use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;
entity counter is -------实体说明
port( inclk:in std_logic; --输入输出定义 outa:out std_logic_vector(0 to 7);
outb:out std_logic_vector(2 downto 0)); end counter;
architecture arth_tcx of counter is --------结构体定义 signal st:std_logic_vector(2 downto 0); signal ma:std_logic_vector(3 downto 0); signal fp:std_logic_vector(15 downto 0); signal hm:std_logic_vector(8 downto 0); signal f,fpb:std_logic; begin
process(inclk) ---------进程说明
begin
if (inclk'event and inclk='1') then ---------1KHz分频模块 if fp=24999 then
fp<=\ f<=not f; else fp<=fp+1; end if; end if; end process;
process(fpb) begin
if (f'event and f='1') then st<=st+1; end if;
end process; ---------1Hz分频模块 process(f) begin
if (f'event and f='1') then if hm=499 then