输入: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 |