微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > vhdl按键计数器

vhdl按键计数器

时间:10-02 整理:3721RD 点击:
输入:clk,reset,b1,b2: std_logic;其中,b1,b2表示两个按键,b1没按下一次,计数器加1,b2没按下一次,计数器减一。
该如何实现?消抖部分一坐处理,这里不用考虑。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;
entity VHDL is
generic
        (
                DATA_WIDTH : natural := 8
        );
        port
        (
                b1           : in std_logic;
                b2           : in std_logic;
                result : out std_logic_vector((DATA_WIDTH-1) downto 0)
        );
end entity;
architecture rtl of VHDL is
signal result_l :std_logic_vector((DATA_WIDTH-1) downto 0);
begin
        process(b1,b2)
        begin
         if (b1='1') then
         result_l<=result_l+'1';
         elsif (b2='1') then
         result_l <=result_l-'1';
         end if;
end process;
result<=result_l;
end rtl;

没有验证,只是使用quartus ii10.1编译综合了一下,没有问题,很简单的功能,应该没问题!

我试了,貌似检测不到上升沿。

把2楼的改成同步时序就可以了
if  clk'event and clk='1' then
         if (b1='1') then
         result_l<=result_l+'1';
         elsif (b2='1') then
         result_l <=result_l-'1';
         end if;
end if

把2楼的改成同步时序就可以了
if  clk'event and clk='1' then
         if (b1='1') then
         result_l<=result_l+'1';
         elsif (b2='1') then
         result_l <=result_l-'1';
         end if;
end if

5楼对的,在输入端口添加clk和reset后,在if (b1='1') then 前面还要添加复位信号控制。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top