集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1012|回复: 1

按键计数器求助?VHDL

[复制链接]
yhpp 发表于 2011-12-2 09:46:53 | 显示全部楼层 |阅读模式
输入:clk,reset,b1,b2: std_logic;其中,b1,b2表示两个按键,b1没按下一次,计数器加1,b2没按下一次,计数器减一。
该如何实现?消抖部分一坐处理,这里不用考虑。

下面是我代码的一部分:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity fbdr is
        port(
        clkin:                in                        std_logic;        --input clock,here is 50MHz
        rstin:                in                        std_logic;        --system reset in
       
        keyfi_n:                in                        std_logic;        --key for frequency increase
        keyfd_n:                in                        std_logic;        --key for frequency decrease
       
------signals for test Elimination-of-key-jitter----------
        clkj:                        buffer        std_logic;        --clock for jitter elimination,here is 100Hz
        keyfio_n:        buffer        std_logic;        --key input after jitter elimination
        keyfdo_n:        buffer        std_logic;        --key input after jitter elimination
----------------------------------------------------------
        clks:                        buffer        std_logic;        --clock for driving signal
        cnt1:                        buffer          std_logic_vector(4 downto 0);        --using to check the press button
----------------------------------------------------------       

        fbdr1:                out                std_logic;        --output driving signal       
        fbdr2:                out                std_logic;        --output driving signal
        fbdr3:                out                std_logic;        --output driving signal
        fbdr4:                out                std_logic;        --output driving signal
        fbdr5:                out                std_logic;        --output driving signal
        fbdr6:                out                std_logic);        --output driving signal
end fbdr;

architecture behave of fbdr is
signal d0,d1,d2,d3:std_logic;                --signal for jitter elimination


begin

process(rstin,clkin,keyfio_n,keyfdo_n)                        --this process is using to produce 100Hz clkj
variable tmpj: integer range 0 to 250000;
variable tmps,tmpfq: integer range 0 to 5000;
begin
                if keyfio_n'event and keyfio_n='0' then
                        tmpfq:=tmpfq+100;
                end if;
               
                if rstin='0' then
                        tmpfq:=399;
                end if;
       
        if rising_edge(clkin) then
                tmpj:=tmpj+1;
                if tmpj>249999 then
                        clkj<=not clkj;
                        tmpj:=0;
                end if;
                tmps:=tmps+1;
                if tmps>tmpfq then
                        clks<=not clks;
                        tmps:=0;
                end if;
        end if;
end process;


process(clkj,keyfi_n,keyfd_n)                --this process is using to eliminate jitter
begin
       
        if rising_edge(clkj) then
                d0<=keyfi_n;
                d1<=d0;
                d2<=keyfd_n;
                d3<=d2;
                keyfio_n<=d0 or d1;
                keyfdo_n<=d2 or d3;
        end if;
end process;

我的问题是,当我只用一个按键控制分频数增大时,是可以实现的。但是按照现在这种方式,如果再增加一个按键来控制分频数减小,如下:
                if keyfio_n'event and keyfio_n='0' then
                        tmpfq:=tmpfq+100;
                elsif keyfdo_n'event and keyfdo_n='0' then
                        tmpfq:=tmpfq-100;
                end if;
编译时就会出错,根本通不过。希望有经验的朋友指点。3x
I2C 发表于 2011-12-3 03:51:18 | 显示全部楼层
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-5-4 14:31 , Processed in 0.062934 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表