AAT 发表于 2010-6-26 23:40:10

我以前的消抖程序是在MAXPLUS2用图形化的门电路搭建的,效果还不错。

encounter 发表于 2010-6-27 00:51:18

我的消抖程序是用比较法做的

CHA 发表于 2010-6-27 02:24:19

原帖由 totocool 于 2007-2-4 11:10 发表<br>
这是一个防斗程序,可以详细解释下吗,我看不懂<br>
library ieee;<br>
use ieee.std_logic_1164.all;<br>
<br>
entity dou is<br>
port(din,clk:in std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;dout
        http://bbs.vibesic.com/images/smilies/default/shocked.gif
ut std_logic);<br>
end dou;<br>
<br>
architecture beha of&nbsp;&nbsp;... 挺有意思

HANG 发表于 2010-6-27 02:45:56

應該是指debounce 電路及one pulse 吧,上述的code應該是一個clock 寬的pulse 產生電路,將Level 轉為pulse,也能作些微的debounce,但如果訊號來源是外接按鍵,由於彈跳效應明顯,所以debounce 的情形就會時間上的選擇,意即sample clock的頻率會不同

ngtim 发表于 2010-6-27 04:41:10

不错 很详尽 顶顶******!!

VVIC 发表于 2010-6-27 05:23:40

拜读。。。。。不错

HDL 发表于 2010-6-27 06:48:23

你用的是轻触开关吧,是独立式的吧!这是按键程序,你再加分频一个快的时钟做一个有同步使能信号的计数器就行了,我用的外部时钟是250K.<br>
LIBRARY IEEE;<br>
USE IEEE.STD_LOGIC_1164.ALL;<br>
ENTITY DULI_KEY IS<br>
PORT(CLR,CLK: IN STD_LOGIC;<br>
&nbsp; &nbsp;&nbsp;&nbsp;KEYIN: IN STD_LOGIC;--按键输入<br>
&nbsp; &nbsp;&nbsp;&nbsp;KEYOUT: OUT STD_LOGIC);--按键输出<br>
END ENTITY DULI_KEY;<br>
ARCHITECTURE ART OF DULI_KEY IS<br>
TYPE ST IS(S0,S1,S2,S3,S4,S5,S6,S7);<br>
SIGNAL S: ST;<br>
SIGNAL CLK1K: STD_LOGIC;<br>
SIGNAL EN: STD_LOGIC;<br>
SIGNAL CO: STD_LOGIC;<br>
BEGIN<br>
CLKDIV_1MS
        http://bbs.vibesic.com/images/smilies/default/tongue.gif
ROCESS(CLR,CLK)--分频<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;VARIABLE CNT: INTEGER RANGE 0 TO 249;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;VARIABLE NEWCLK: STD_LOGIC;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;BEGIN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; IF CLR='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; CNT:=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; NEWCLK:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ELSIF CLK'EVENT AND CLK='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;IF CNT=249 THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;CNT:=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;NEWCLK:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;CNT:=CNT+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;NEWCLK:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;CLK1K&lt;=NEWCLK;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END PROCESS CLKDIV_1MS;<br>
DLEY_20MS
        http://bbs.vibesic.com/images/smilies/default/tongue.gif
ROCESS(CLR,EN,CLK1K)--延时<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;VARIABLE CNT: INTEGER RANGE 0 TO 19;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;VARIABLE C: STD_LOGIC;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;BEGIN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF CLR='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;CNT:=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;C:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSIF EN='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;CNT:=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;C:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSIF CLK1K'EVENT AND CLK1K='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; IF CNT=19 THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; CNT:=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; C:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; CNT:=CNT+1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; C:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;CO&lt;=C;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END PROCESS DLEY_20MS;<br>
KEY
        http://bbs.vibesic.com/images/smilies/default/tongue.gif
ROCESS(CLR,CLK,CO)<br>
&nbsp; &nbsp;&nbsp;&nbsp;VARIABLE N: STD_LOGIC;<br>
&nbsp; &nbsp;&nbsp;&nbsp;VARIABLE KEYO: STD_LOGIC;<br>
&nbsp; &nbsp;&nbsp;&nbsp;BEGIN<br>
&nbsp; &nbsp;&nbsp; &nbsp;IF CLR='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;N:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;KEYO:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;ELSIF CLK'EVENT AND CLK='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp; CASE S IS<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN S0=&gt;N:='1';KEYO:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF KEYIN='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN S1=&gt;N:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF CO='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S2;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN S2=&gt;N:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF KEYIN='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S3;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN S3=&gt;N:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF KEYIN='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;KEYO:=KEYIN;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S4;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN S4=&gt;N:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF KEYIN='0' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S5;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S4;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;WHEN S5=&gt;N:='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;IF CO='1' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S6;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;S&lt;=S5;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp; WHEN S6=&gt;N:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;IF KEYIN='0' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;S&lt;=S7;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;S&lt;=S4;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp; WHEN S7=&gt;N:='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;IF KEYIN='0' THEN<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;S&lt;=S0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;S&lt;=S4;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END CASE;<br>
&nbsp; &nbsp;&nbsp; &nbsp; END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;EN&lt;=N;<br>
&nbsp; &nbsp;&nbsp; &nbsp;KEYOUT&lt;=KEYO;<br>
&nbsp; &nbsp;&nbsp; &nbsp;END PROCESS KEY;<br>
END ARCHITECTURE ART;

Sunlife 发表于 2015-6-25 11:08:21

这实际上是一个滤波器,也有防抖的作用,通过两级的移位寄存器实现<br>
假设din输入的信号中间有跳变的时候<br>
则x和y的值会不一样,<br>
如果x=0,y = 1,则dout= 0,也就是把din上的高电平毛刺滤除了;<br>
如果x=1,y=0,则dout=1,也就是把din上的低电平毛刺滤出了。
页: 1 2 [3]
查看完整版本: fpga防抖程序的原理是什么?脉冲?时钟周期?