【发布时间】:2019-11-29 23:43:04
【问题描述】:
我目前正在尝试在 7 段上显示计数器状态。 如果我按下一个按钮(物理上)它应该增加这个计数器状态。 但在我的情况下,它显示一个随机数,我认为它是一种错误的去抖动/计数器方法。
我搜索了网络,但无法解决此问题。 如果有人可以帮助我,我将非常感激!
编辑:7 段显示器运行良好我对所有数字 (0-9) 进行了测试 所以它在我的 debounce 或 counter 方法中肯定失败了。
//debouncer.vhdl
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
entity Debounce is
Port ( CLK100MHZ : in STD_LOGIC;
BTNU : in STD_LOGIC;
BTNU_I : out STD_LOGIC);
end Debounce;
architecture Behavioral of Debounce is
signal keydeb : std_logic := '0';
signal debcnt : integer range 0 to 63 := 0;
begin
process begin
wait until rising_edge(CLK100MHZ);
-- XOR
if (BTNU=keydeb) then debcnt <= 0;
else debcnt <= debcnt+1;
end if;
-- Latch
if (debcnt=63) then keydeb <= BTNU;
end if;
end process;
BTNU_I <= keydeb;
end Behavioral;
//main.vhdl
//declared ports
Port (
BTNU: in std_logic; //button
CPU_RESETN: in std_logic;
CLK100MHZ: in std_logic;
);
//declared signals
signal Qint10m: std_logic_vector(3 downto 0); //number which holds the number to display
signal BTNU_I: std_logic; //button debounced
signal testC: integer range 9 downto 0; //counter
BTNU_debounce: entity Work.Debounce port map(
CLK100MHZ => CLK100MHZ,
BTNU => BTNU,
BTNU_I => BTNU_I);
bcd_counttest: process(CPU_RESETN, CLK100MHZ, BTNU_I)
begin
if(CPU_RESETN='0') then
testC <= 0;
elsif( CLK100MHZ'event and CLK100MHZ = '1') then
if(BTNU_I = '1') then
if(testC = 8) then
testC <= 0;
else
testC <= testC+1 ;
end if;
end if;
end if;
end process bcd_counttest;
Qint10m <= std_logic_vector(to_unsigned(testC, Qint10m'length));
【问题讨论】:
-
您的代码没有分析(编译)。这不是minimal reproducible example。副手 6 位的 debcnt(0 到 63)不足以消除具有 100MHz 时钟的按钮,计数应在 10 毫秒范围内或更长,具体取决于按钮(开关)。 this picture 中的 btnu_i 有什么问题? (它被用作使用相同时钟的 testc 计数器的启用。您希望启用单个时钟长。)对于模拟 debcnt 应在 63 时分配 0。
标签: vhdl