Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

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

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2009-1-18 22:06:27 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
此程式為一個每按一次TACT SW就會進行累加1的程式,並且LED亮度會每累加一次, ~8 Z# q- b/ a& q( d
就會增加,共8段亮度(0~7),此程式這些功能都可以了,但是會有開關彈跳的問題,6 |( r+ L, M- F+ c6 `
希望能有高手幫我解決此問題7 D. Z" ?! Q! F  I! {: V% x
: E( O2 h1 q9 j2 \6 }0 u
! S/ m4 f/ ?9 [: ^% d! i
library ieee;
8 |/ w, S: i3 K( K! {. Guse ieee.std_logic_1164.all;
8 p8 K6 B  n2 `0 y* z# Q# Yuse ieee.std_logic_arith.all;
- U2 P) q& C4 n- d+ N! i2 P+ Zuse ieee.std_logic_unsigned.all;
. j: ~: i5 F: E0 F2 ]' d+ R+ z0 G- Z" d: p6 l
entity pwm8 is Port (
: m3 d: H% a! v% s& S( i. D    CLK : in std_logic;--clock 1KHZ# D! b0 G" G- Q5 t! {& t) d% H
    RST : in std_logic;--reset' \! u) B" ?9 x' c
    SW  : in std_logic;--switch in
0 _+ ~; v: A8 ?    SEG7 : out std_logic_vector(6 downto 0));--
( @0 q8 A/ {( F* R1 V) C$ `end pwm8;: P2 F. u9 v% g+ t

5 O. `  O7 Q7 h$ [4 l) varchitecture arch of pwm8 is" o. F3 O. v+ g, m& {

: G( a+ o' W, W! C/ U; msignal  SWCNT : std_logic_vector(2 downto 0);- \# L$ V& Z- P) `4 K' A
signal  PWMCNT : std_logic_vector(2 downto 0);8 `( ^- r9 Z7 y3 @2 W7 L4 K
signal  DISP : std_logic;9 }& K5 J) |+ `. v  C: t% ~- B

7 T4 O$ i: T9 Z% v; tbegin
% F6 x* X9 v, `8 R: I9 j
# F& Y2 p/ y  N2 J# _* J--toggle switch input counter
# z) P" J; m/ C0 zprocess(RST,SW)
0 _9 \1 e1 F% P  b; [begin
# d6 v- H$ I7 }( B    if RST='1' then
6 ]; L  }$ r8 P        SWCNT<="000";
' ]9 \9 o- w, p- E( Y    elsif rising_edge(SW) then
8 g( A/ M4 @- B" Q7 _' E        SWCNT<=SWCNT+'1';$ U' F: x8 o! j- F1 Y6 ?9 [
    end if;2 }: A9 I/ y7 R( L
end process;& \7 I5 t. M8 ^- x4 k7 D4 G
6 p+ W2 t! k6 n( N$ h% W
--pwm counter, j2 v# E" k- ?3 h, O" u9 I$ f$ I
process(RST,CLK)
+ s5 L" V  H* ?" v( Wbegin
0 x0 ]  l. F+ J- K8 I+ [- @    if RST='1' then
9 k  R( }: v5 V2 z' I! i, Y4 M        PWMCNT<="000";
9 U* F/ l& F& s! a$ n2 J1 d        DISP<='0';. m7 @# d. S# P, b
    elsif rising_edge(CLK) then
' R$ Y1 G; D9 E* X. V  Y% L! B        PWMCNT<=PWMCNT+'1';
* d( _( H7 R# Y9 \4 E" P        if (PWMCNT="111") then
2 {, }: {" D# W            DISP<='1';9 ~4 l  I9 Y) u0 `
        elsif (PWMCNT=SWCNT) then
) {1 [: [0 Q% I/ M            DISP<='0';
% h$ y1 t( K8 }        end if;! U+ P9 N0 F  U" G
    end if;8 K! }0 c, }8 u8 h& z" m
end process;' H% n9 {5 g8 v' m3 E

, a" P# c& Q4 y--7-segment display decoder
) j* y# O) B: v# [* u- ~1 zprocess(DISP,SWCNT)/ \& D: B! f( S. ~6 ]" s
variable DISPEN : std_logic_vector(3 downto 0);' O0 a% A1 g% Y
begin! Q' H. V8 e0 v+ t
    DISPEN := DISP SWCNT;2 r6 \' u1 L/ N5 n' U) X' B
    case DISPEN is --SEG7<="abcdefg"
( j: Q* Z  |& o        when "1000"=>SEG7<="1111110";
  e" N) i1 Q! ~7 b5 ^* s        when "1001"=>SEG7<="0110000";
: J8 \9 c2 o4 {1 i2 O1 [        when "1010"=>SEG7<="1101101";
/ [  h' |0 K9 K9 W# z3 i9 O        when "1011"=>SEG7<="1111001";
' A5 g# ]7 |. R$ U- Q3 Y% C8 g        when "1100"=>SEG7<="0110011";5 [4 [, |0 [0 B9 G  }
        when "1101"=>SEG7<="1011011";
' ]  @! I6 w+ r7 K# A        when "1110"=>SEG7<="1011111";) |. S  g; L$ V5 M: N$ `/ W
        when "1111"=>SEG7<="1110000";
. B* t/ o0 o4 @" V6 f        when others=>SEG7<="0000000";
# g3 i/ t6 [& i  [9 _    end case;
6 U; l/ A! v* T* C  x# k) Send process;5 K. O0 `# b8 @
end arch;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
發表於 2009-2-2 13:02:01 | 只看該作者
process(RST,SW)  Q+ W) U1 C0 J8 ]0 N% D
begin* r$ x; H% g% i7 u1 ]. R
    if RST='1' then
) K4 ]; s- T& `- B5 G% r        SWCNT<="000";
9 U" a: x9 w+ e0 W. t    elsif rising_edge(SW) then2 G2 V& Z1 m2 f
        SWCNT<=SWCNT+'1';  L1 H6 f( n) X. T
    end if;
4 N6 ]( ?  c# I2 W! I  yend process;
2 h2 o. G* s* W6 B( i& f! Z- z將 SW 以 數ms~數十ms 的取樣率取到穩定的 High/Low 才當成上述的 clock 信號就可以解決
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-5-15 11:20 PM , Processed in 0.101512 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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