Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 6923|回復: 1
打印 上一主題 下一主題

[問題求助] 此VHDL程式中的TACT SW要如何加才能防止開關彈跳

[複製鏈接]
跳轉到指定樓層
1#
發表於 2009-1-18 22:06:27 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
此程式為一個每按一次TACT SW就會進行累加1的程式,並且LED亮度會每累加一次
; C! l9 ^# J* r' n+ o5 f就會增加,共8段亮度(0~7),此程式這些功能都可以了,但是會有開關彈跳的問題,
1 _5 p: s2 A- U, c4 a3 A希望能有高手幫我解決此問題
* G" Y8 Z- r+ a  c. p% E) ?& X
8 `( A. X& W, h. f" n
$ |1 c; b8 F; {# D6 ]6 Wlibrary ieee;
+ n0 D8 q. d+ t3 i( ^use ieee.std_logic_1164.all;  f4 \9 e2 l7 s' h3 a- [
use ieee.std_logic_arith.all;
% X9 D0 p, [7 ]4 e+ B  ?! }use ieee.std_logic_unsigned.all;
0 V$ a- `' V+ F* b
9 Q! z9 {  x7 ?% U( Q, [entity pwm8 is Port (
' `8 ^6 u* M# l; g% w    CLK : in std_logic;--clock 1KHZ) H) `% t0 l. B: r# N5 j
    RST : in std_logic;--reset
. K* o$ n( D; v/ S' Q" {    SW  : in std_logic;--switch in
2 \% g0 w" R  }3 M( i! n$ m5 b) K8 W    SEG7 : out std_logic_vector(6 downto 0));--0 [  ?( ]: E, z3 S) p" r$ P3 p+ i6 h) k
end pwm8;
' K4 h6 Y, a0 n, v) @  a! @
$ [. L5 O! B0 v( \/ d" n  k7 s/ }architecture arch of pwm8 is
4 X7 \2 V% V/ f, W# N7 W
) h7 v# y- X1 bsignal  SWCNT : std_logic_vector(2 downto 0);
* \! o, k1 m# @/ D+ Rsignal  PWMCNT : std_logic_vector(2 downto 0);
" Z7 C. f4 f# d- C. Esignal  DISP : std_logic;
8 v' E, [3 b$ \" w7 L( Q; G2 E' w7 {$ p+ }$ S$ K% T1 s
begin
% t) {. L8 e: I* ~$ w  {" |7 t+ f$ _0 o1 _/ p& z  Z' W" K0 T+ y
--toggle switch input counter
3 C" y4 i0 J9 {process(RST,SW); z) X- |, x) S% d7 E' U1 {4 Z
begin8 z- h# n' O- n7 U! s. a) i
    if RST='1' then" A1 b. \& D+ d& Q6 J, z3 ~; }% T) z
        SWCNT<="000";
8 H' f* ~- L$ y2 \/ Z* f5 R2 q    elsif rising_edge(SW) then
! I# w! G9 c! B8 w0 X" r* O5 M        SWCNT<=SWCNT+'1';2 O2 y- n  y7 Z( ?5 E0 X" D
    end if;
. c5 h/ u, \5 ^9 f; o4 K& _1 L5 `end process;
% h/ x! R- A) c1 |8 Q
- E6 u: n( I& D. E& f( E--pwm counter6 s  |# L6 T1 b0 v2 S
process(RST,CLK)0 b  B  R5 I3 H
begin
6 o5 G- O8 ~! v8 E5 X5 X- E4 d: k    if RST='1' then) T5 @2 M2 n3 x, Q' s  ]
        PWMCNT<="000";1 B* ?. W) E8 {  ~' n$ E. ]/ O: c
        DISP<='0';- s+ J$ g  `/ ~% E1 k) f# ~  T2 ^
    elsif rising_edge(CLK) then
5 D/ s# e3 M* A" B2 U        PWMCNT<=PWMCNT+'1';9 u0 D  T7 Y) a9 D. o
        if (PWMCNT="111") then' Y+ g0 P2 V; G
            DISP<='1';
  a" a! X* }" L+ t& I2 |        elsif (PWMCNT=SWCNT) then0 [. |5 _! i- j. l+ L% t
            DISP<='0';
) V( J2 ]( g& D) `/ l        end if;
" @( w" ~+ [6 z, k% p2 Q    end if;9 J' p1 ^* [8 S  a2 F' C
end process;
6 [4 |6 _- I% W3 z4 \, `  ^
$ b9 k+ S' w5 ]7 C  W" }--7-segment display decoder7 R: M: Q" A( s8 u; g9 L% D
process(DISP,SWCNT)
+ [$ l( l' L( {7 Ovariable DISPEN : std_logic_vector(3 downto 0);; p4 _: j6 c) I
begin, s# i% d- |( q) \
    DISPEN := DISP SWCNT;
) P; ?) c- I7 }4 ?( [9 J+ e( c    case DISPEN is --SEG7<="abcdefg"
+ v, X7 c; y5 `' z- {        when "1000"=>SEG7<="1111110";
- o. N% m! u- H2 Y9 e' F& k/ O4 h        when "1001"=>SEG7<="0110000";7 \& d: r0 K6 w3 h$ P* M* x( L/ j
        when "1010"=>SEG7<="1101101";
/ `% D! b& ]: ]; \" j        when "1011"=>SEG7<="1111001";
! b( t1 E$ Y% J# l% p* U        when "1100"=>SEG7<="0110011";+ I. t  C5 Q7 ^
        when "1101"=>SEG7<="1011011";7 \3 C$ L& o( n
        when "1110"=>SEG7<="1011111";
6 t* S) d# ]+ m0 I7 e) f        when "1111"=>SEG7<="1110000";
1 y- r* s* l- m( X4 h- j        when others=>SEG7<="0000000";2 G& K; {2 D+ @, h
    end case;
7 z. S5 Z, p3 f8 Uend process;
8 y( a# M5 d9 @8 W; g. V' D0 Nend arch;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
發表於 2009-2-2 13:02:01 | 只看該作者
process(RST,SW)
$ r" Y2 v4 V: K3 i9 U* Ybegin( x' p( I' [* u  e5 h" Q3 y3 _
    if RST='1' then
! r- b; b8 V: g5 r- K0 Y# b        SWCNT<="000";
2 _6 ^6 |3 B! G+ |" U6 \! i    elsif rising_edge(SW) then6 }2 B& U- d/ P+ i; z
        SWCNT<=SWCNT+'1';8 n& M% K; y& V9 a2 g' W: o# V
    end if;
' ?$ g2 Z; Y# ]2 f2 i* fend process;
" I- _+ w8 n/ b& O2 H! A; t將 SW 以 數ms~數十ms 的取樣率取到穩定的 High/Low 才當成上述的 clock 信號就可以解決
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

首頁|手機版|Chip123 科技應用創新平台 |新契機國際商機整合股份有限公司

GMT+8, 2024-5-18 04:19 AM , Processed in 0.114015 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表