Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

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

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2009-1-18 22:06:27 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
此程式為一個每按一次TACT SW就會進行累加1的程式,並且LED亮度會每累加一次9 m# k  x! H5 y. v" Q0 o( |& w5 T1 F
就會增加,共8段亮度(0~7),此程式這些功能都可以了,但是會有開關彈跳的問題,+ W. b# s' \) x7 r& y9 A
希望能有高手幫我解決此問題4 k$ d0 \  F% W6 c* r5 q

' Z5 `. B4 @/ U. z# k1 a
0 K9 P$ ]& E7 _( |$ Glibrary ieee;* f% {# g. t  ]; ]0 A
use ieee.std_logic_1164.all;
2 |% J4 d# g" m, I0 Euse ieee.std_logic_arith.all;
: @. |% t( p, U6 Z1 X  j3 M" Juse ieee.std_logic_unsigned.all;& _* O+ W; t0 M& c

2 z4 `& Y- g! i+ m! D$ F" @entity pwm8 is Port (
+ L  e5 N8 x) C. j/ C2 ?1 O0 l+ n    CLK : in std_logic;--clock 1KHZ
8 @% c3 F( G- C0 |    RST : in std_logic;--reset9 Y3 c0 {) ?4 ~) j
    SW  : in std_logic;--switch in2 U/ Q9 l" T! s8 R: {& O& b( W
    SEG7 : out std_logic_vector(6 downto 0));--3 X2 b, y, E6 V7 v1 o& N9 M* y$ b6 d
end pwm8;
7 l/ P* x4 W$ x* o
8 q/ K( l$ j* T; o# {architecture arch of pwm8 is
( U2 Q# B! y$ G6 U* w1 _% X0 f' d: [! d8 x6 I! W  u7 U( P0 e
signal  SWCNT : std_logic_vector(2 downto 0);
8 Z  B7 l+ O" u) x  _! P8 ?& N* ?. usignal  PWMCNT : std_logic_vector(2 downto 0);2 e( p- ~' z5 I8 C( q
signal  DISP : std_logic;
$ `3 n: T# w; Z7 `' c2 N) M" L  v2 k( G
begin
) ?; L1 Q4 a% }3 q8 z
( L/ \( i% C% u" n3 z--toggle switch input counter
& T5 {$ ]. z2 l/ ?! ^, k8 _process(RST,SW)
% w* \" k' x7 @; ~4 H6 Nbegin# p3 l4 `" \* D; S$ c: H: A
    if RST='1' then; j# ?" E# r  F! x: N' _
        SWCNT<="000";$ e3 g; z4 n6 P! i9 u7 j0 d
    elsif rising_edge(SW) then
: s, |$ O* P: d# K        SWCNT<=SWCNT+'1';
* x+ T: B2 Z8 J    end if;/ `* ^6 n0 h/ A& ~! q. k; K& E
end process;9 }5 ~; k) ]- |4 c* Q

# w' i; \7 p6 p; ^--pwm counter
0 Q0 z& K8 b: n2 W) Hprocess(RST,CLK)( W, ]9 p+ u  \' h" a4 ^( Z1 F
begin
8 _% _2 G5 ~/ h7 V    if RST='1' then
- T+ V% p+ |4 c: I        PWMCNT<="000";- B( F6 t! t# @1 z
        DISP<='0';/ t+ m8 a$ X/ r5 x& K* `
    elsif rising_edge(CLK) then+ V4 |% `/ ?5 s: f+ a8 I
        PWMCNT<=PWMCNT+'1';' f8 B' r* }! {5 l; T- o
        if (PWMCNT="111") then2 F1 L8 N) C) o! J  D" e
            DISP<='1';: l1 G% V/ y: b; z. F4 o  `
        elsif (PWMCNT=SWCNT) then% Y  A5 g# ~1 z' k/ w2 V# e
            DISP<='0';
% x3 G2 H& Z, r        end if;; ~$ x9 o/ A. w$ b6 R9 A1 K
    end if;
& @8 p; ^: v# O# N& Xend process;$ _, y* N! M* B$ B
' P, d% n6 _/ |  Y
--7-segment display decoder
; G% \# V( i9 o. A5 o) kprocess(DISP,SWCNT)7 \! _: a8 w& t. E  Y
variable DISPEN : std_logic_vector(3 downto 0);
' z; a. U# R9 g: a, Abegin# m. q' C0 P% U# C
    DISPEN := DISP SWCNT;
3 c2 S" Z" ?3 Z/ o$ q( X    case DISPEN is --SEG7<="abcdefg"2 {# o8 t$ O6 g
        when "1000"=>SEG7<="1111110";1 }. Z7 S) v' i" s& `5 t2 z
        when "1001"=>SEG7<="0110000";9 P: E! C$ _5 e* M% ]
        when "1010"=>SEG7<="1101101";
1 c- x0 [3 [; t' t        when "1011"=>SEG7<="1111001";
9 g0 G- L( L6 H, q- ?/ V        when "1100"=>SEG7<="0110011";
: _/ G$ M$ C0 _        when "1101"=>SEG7<="1011011";+ f$ G$ @( W( k
        when "1110"=>SEG7<="1011111";
3 \! Y; ~$ ?* ~( v. Q" ]* K: R        when "1111"=>SEG7<="1110000";
5 l. T$ ]6 z6 ]4 w5 D% v        when others=>SEG7<="0000000";
! I, A2 B& E+ q  W! V6 j    end case;
7 a9 W/ R% F; S& w; G; r3 W  B* X3 Cend process;' \0 I9 h  A% B6 A) w. a; a1 i0 Q( w
end arch;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
發表於 2009-2-2 13:02:01 | 只看該作者
process(RST,SW)
3 H9 y3 ~3 P2 J+ ^) \. }begin% o' d! n7 c# z+ A0 b
    if RST='1' then. s  [' l" S. P& C( V
        SWCNT<="000";5 Q5 \# ^1 _' M0 M
    elsif rising_edge(SW) then0 q) C; q6 U, T
        SWCNT<=SWCNT+'1';! y( E8 v, V8 L% d  Q8 J
    end if;
' m6 ^# U! H8 c5 R8 S- Bend process;7 U4 n  B* S  N& X* x/ W" B7 E2 Z
將 SW 以 數ms~數十ms 的取樣率取到穩定的 High/Low 才當成上述的 clock 信號就可以解決
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-6-4 01:03 PM , Processed in 0.114015 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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