【国产FPGA高云GW1N-4系列开发板测评】——7、数码管显示秒表
本帖最后由 gs001588 于 2021-12-26 00:03 编辑<p><span style="font-size:16px;"><span style="font-family:宋体;"> 【国产FPGA高云GW1N-4系列开发板测评】——7、数码管显示秒表</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 在上一贴基础上更改为数码管显示秒表功能,应该是比较简单的。(上一贴:<a href="https://bbs.eeworld.com.cn/thread-1190207-1-1.html" target="_blank">【国产FPGA高云GW1N-4系列开发板测评】——6、数码管显示时钟(时、分、秒) https://bbs.eeworld.com.cn/thread-1190207-1-1.html</a>)</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> </span></span></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 使用SW1作为秒表开始(使能)和暂停,SW2作为秒表清零。</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 直接上代码:</span></span></p>
<pre>
<code>--*******************************************************************************
--*-------------------------- file ---------------
--* name:segx4.vhd
--* ver : A
--* date:2021-12-9
--*------------------------------------------------
--*******************************************************************************
---------- LIB----------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
----------ENTITY -------------------------------------------------------------
ENTITY segx4 IS
PORT (
-------------------------------------------------------------------------------
--系统全局时钟 CLK
-------------------------------------------------------------------------------
CLK_50M: INSTD_LOGIC; --50MHz系统时钟
-------------------------------------------------------------------------------
--系统全局复位 RESET
-------------------------------------------------------------------------------
NRESET: INSTD_LOGIC;
-------------------------------------------------------------------------------
--SEGx4
-------------------------------------------------------------------------------
DIS: OUTSTD_LOGIC_VECTOR(7 DOWNTO 0);
SEL: OUTSTD_LOGIC_VECTOR(4 DOWNTO 1);
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--SWx4
-------------------------------------------------------------------------------
SW: INSTD_LOGIC_VECTOR(4 DOWNTO 1)
-------------------------------------------------------------------------------
);
END segx4;
-----------ARCHITECTURE-------------------------------------------------------
ARCHITECTURE MY_CODE OF segx4 IS
-----------------------------------------------------------------------
SIGNAL COUNTER1: integer range 0 to 62500;
SIGNAL CNT: integer range 0 to 8;
SIGNAL SCAN_CLK: STD_LOGIC;
TYPE DIS_Reg_Index IS ARRAY(1 to 4) OF STD_LOGIC_VECTOR(7 downto 0);
SIGNAL DIS_Reg: DIS_Reg_Index;
SIGNAL SEL_Reg: STD_LOGIC_VECTOR(4 downto 1);
-----------------------------------------------------------------------
TYPE SMG_INDEX IS ARRAY(0 to 9) OF STD_LOGIC_VECTOR(7 downto 0);
CONSTANT SMG: SMG_INDEX := (X"C0",-- 0
X"F9",-- 1
X"A4",-- 2
X"B0",-- 3
X"99",-- 4
X"92",-- 5
X"82",-- 6
X"F8",-- 7
X"80",-- 8
X"90" -- 9
);
CONSTANT BLANK: STD_LOGIC_VECTOR(7 DOWNTO 0):=X"FF";
SIGNAL COUNTER2: integer range 0 to 500000;
SIGNAL SEC: integer range 0 to 99;
SIGNAL CLK_10MS: STD_LOGIC;
SIGNAL CNT_10MS: integer range 0 to 99;
--**********************************************************************************
--*****
--**********************************************************************************
BEGIN
PROCESS(NRESET,CLK_50M)
BEGIN
IF (NRESET = '0') THEN
COUNTER1 <= 0;
ELSIF (RISING_EDGE(CLK_50M)) THEN
IF (COUNTER1 < 62500-1) THEN
COUNTER1 <= COUNTER1 + 1;
ELSE
COUNTER1 <= 0;
END IF;
END IF;
END PROCESS;
PROCESS(NRESET,CLK_50M)
BEGIN
IF (NRESET = '0') THEN
SCAN_CLK <= '0';
ELSIF (RISING_EDGE(CLK_50M)) THEN
IF (COUNTER1 = 62500-1) THEN
SCAN_CLK <= NOT SCAN_CLK;
END IF;
END IF;
END PROCESS;
PROCESS(NRESET,SCAN_CLK)
BEGIN
IF (NRESET = '0') THEN
CNT <= 1;
ELSIF (RISING_EDGE(SCAN_CLK)) THEN
IF (CNT = 4) THEN
CNT <= 1;
ELSE
CNT <= CNT + 1;
END IF;
END IF;
END PROCESS;
SEL_Reg <=(1=>'0',others=>'1') WHEN CNT = 1 ELSE
(2=>'0',others=>'1') WHEN CNT = 2 ELSE
(3=>'0',others=>'1') WHEN CNT = 3 ELSE
(4=>'0',others=>'1') WHEN CNT = 4 ELSE
(others=>'1');
SEL <= SEL_Reg;
DIS <= DIS_Reg(CNT);
DIS_Reg(4)<= SMG(SEC / 10);
DIS_Reg(3)<= '0' & SMG(SEC REM 10)(6 DOWNTO 0);
DIS_Reg(2)<= SMG(CNT_10MS / 10);
DIS_Reg(1)<= SMG(CNT_10MS REM 10);
PROCESS(NRESET,CLK_50M)
BEGIN
IF (NRESET = '0') THEN
COUNTER2 <= 0;
ELSIF (RISING_EDGE(CLK_50M)) THEN
IF (COUNTER2 = 500000-1)THEN
COUNTER2 <= 0;
ELSE
COUNTER2 <= COUNTER2 + 1;
END IF;
END IF;
END PROCESS;
PROCESS(NRESET,CLK_50M)
BEGIN
IF (NRESET = '0') THEN
CLK_10MS <= '0';
ELSIF (RISING_EDGE(CLK_50M)) THEN
IF (COUNTER2 = 250000-1) OR (COUNTER2 = 500000-1)THEN
CLK_10MS <= NOT CLK_10MS;
END IF;
END IF;
END PROCESS;
PROCESS(NRESET,CLK_10MS)
BEGIN
IF (NRESET = '0' OR SW(2) = '1') THEN
SEC <= 00;
CNT_10MS <= 00;
ELSIF (RISING_EDGE(CLK_10MS) AND (SW(1) = '0')) THEN
IF (CNT_10MS = 99) THEN
CNT_10MS <= 0;
IF (SEC = 99) THEN
SEC <= 0;
ELSE
SEC <= SEC + 1;
END IF;
ELSE
CNT_10MS <= CNT_10MS + 1;
END IF;
END IF;
END PROCESS;
END MY_CODE;
</code></pre>
<p> </p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 123行之前代码功能,请参考上一贴,这里不再赘述。</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 125到129行,数码管4位分别显示秒表的秒十位、秒个位加点、100ms、10ms。</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> SEL的位选、DIS的显示段值正好都与CNT相关,每个位显示寄存器DIS_REG()实时赋值,DIS_Reg(CNT)查表显示。</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"></span></span></p>
<p> </p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 131到142行,分频产生10ms定时节拍;</span></span></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 144行到153行,产生50%点空比,10ms脉冲时钟;</span></span></p>
<p><font face="宋体"><span style="font-size: 16px;"> 155行到172行为秒表主功能代码。SW(2)为‘1’时秒表清零;为‘0’时允许秒表计时。SW(1)为‘0’时秒表正常走,为‘1’时秒表暂停。最大计时99秒99。</span></font></p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"></span></span></p>
<p> </p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 显示效果如下图,未做动态视频。请参考以主代码或下载工程文件,验证功能。</span></span></p>
<p></p>
<p> </p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> 工程文件:</span></span></p>
<p><br />
</p>
<p><span style="font-size:16px;"><span style="font-family:宋体;"> </span></span></p>
<p>楼主的国产FPGA秒表评测,不错</p>
<p>下篇准备测评什么,好期待</p>
<p> </p>
<p>下次贴代码可以直接贴到 -高级模式-代码框,显示效果要好一点</p>
Jacktang 发表于 2021-12-27 07:14
楼主的国产FPGA秒表评测,不错
下篇准备测评什么,好期待
下次贴代码可以直接贴到 -高级模 ...
<p>多谢捧场!</p>
<p>已经添加到代码框了,但是没有VHDL或Verilog的格式选项,所以效果不是太好</p>
页:
[1]