cxlspp 发表于 2011-5-17 13:10:45

一个只能计数到500的计数器,带使能和消抖,为啥不对呢??

要实现的功能:
一个只能计数到100的计数器,按键经过消抖处理,
如果按键一直按着不放,则只计数一次
如果AJ_EN='0';则按键按下后不计数
...
Key:in std_logic;
...
signal clk_1khz,clk_1hz,clk_2hz,clk_5hz:std_logic;--分频后的时钟
signal Key_QD:std_logic;--消抖后的按键信息
signal AJ_EN:std_logic:='1';--按键使能

signal AA_1 : std_logic_vector(3 DOWNTO 0):="0000"; --百位
signal AA_2 : std_logic_vector(3 DOWNTO 0):="0000"; --十位
signal AA_3 : std_logic_vector(3 DOWNTO 0):="0000"; --个位

process(clk_1khz,Key)
variable count:integer range 0 to 11;
begin
if(clk_1khz'event and clk_1khz='1')then
   if(Key='1')then
    count:=0;      
   else
    if(count<10)then count:=count+1;
   elsif(count=10)then
      Key_QD<='0';
   else count:=11;
    end if;
   end if;   
end if;
end process;

process(clk_1khz)
begin
if(AA_1>="0001")then AJ_EN<='0';
   else AJ_EN<='1';
end if;
end process;

process(Key_SF_100_QD,AJ_EN)
begin
   if(AJ_EN='1')then
   if(Key_QD='0')then
      if(AA_3<"1001")then AA_3<=AA_3+1;
       elsif(AA_2<"1001")then AA_2<=AA_2+1;AA_3<="0000";
      else AA_1<=AA_1+1;AA_2<="0000";AA_3<="0000";
      end if;
   end if;
   end if;
end process;


-----------------------------------------------------------
上面这些代码,折腾了不少时间,求高手指点.....

cxlspp 发表于 2011-5-17 13:11:46

标题有误,是100...不小心了一把

qwic 发表于 2011-5-19 08:52:56

大概改下,试试
.......
    if(count<10)then
   count:=count+1;
   Key_QD<='1';
    elsif(count=10)then
   Key_QD<='0';
    else count:=11;
   Key_QD<='1';
    end if;
.........
if(clk_1khz'event and clk_1khz=1)then
   if(AJ_EN='1')then
   if(Key_QD='0')then
      if(AA_3<"1001")then AA_3<=AA_3+1;
       elsif(AA_2<"1001")then AA_2<=AA_2+1;AA_3<="0000";
      else AA_1<=AA_1+1;AA_2<="0000";AA_3<="0000";
      end if;
   end if;
   end if;
end if;
...........
页: [1]
查看完整版本: 一个只能计数到500的计数器,带使能和消抖,为啥不对呢??