Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

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

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2009-1-18 22:06:27 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
此程式為一個每按一次TACT SW就會進行累加1的程式,並且LED亮度會每累加一次: [8 N7 c" y3 Q! `( y. K3 [
就會增加,共8段亮度(0~7),此程式這些功能都可以了,但是會有開關彈跳的問題,& k) E+ W: Q! N2 b, ^
希望能有高手幫我解決此問題) T2 g6 T$ m6 ?. Q: t" O6 R& l

5 l  w4 n3 H8 I, E* X* w0 t' M" P
library ieee;6 f) n) i" W& H+ Y) Z
use ieee.std_logic_1164.all;
7 y0 I; k* [- K$ K& _, u  B# kuse ieee.std_logic_arith.all;3 {1 x( r! B  r. B& j2 i& Q7 Z( b
use ieee.std_logic_unsigned.all;7 K3 N( K. c2 t1 W1 G- M2 D: x9 S
4 U7 Q) l4 h# T  j! B2 Q
entity pwm8 is Port (
: r0 ]: N4 l- r) Q# D7 A    CLK : in std_logic;--clock 1KHZ: o7 Q$ P; p" M; ?4 {- ^( G
    RST : in std_logic;--reset3 k$ x7 k. O0 u- H+ F6 j
    SW  : in std_logic;--switch in! ?5 J0 W0 W% O
    SEG7 : out std_logic_vector(6 downto 0));--
( V) P, R; q( O- K) s/ y/ Yend pwm8;# U8 \% k- D0 X: W1 D

' r. ]4 n+ ^9 e$ \3 harchitecture arch of pwm8 is
4 q8 h& L* W( b( A) E- ?/ c. s+ z' C
5 t4 k" ?3 K' u2 Y  X0 gsignal  SWCNT : std_logic_vector(2 downto 0);
( R* B* `+ Z3 Q9 R$ msignal  PWMCNT : std_logic_vector(2 downto 0);
$ x6 s) q% S1 a) U0 d* O& g1 Z5 b: w; msignal  DISP : std_logic;
9 N5 P) t: E3 q4 a
+ L' R0 b, O7 j3 Tbegin
/ p/ a  y! L/ ^2 u1 L; N' m/ l, l6 }1 G) A
--toggle switch input counter
# n9 D9 n$ u2 I: o8 ]process(RST,SW)3 _' Z. E6 n5 w, a- ^  ~
begin
  Y* K3 M' V% ], G0 r    if RST='1' then
* m) `* j) A# h- I0 u        SWCNT<="000";
: P+ o& E: N; F! H    elsif rising_edge(SW) then
! ~! s9 x7 U& n  r        SWCNT<=SWCNT+'1';
) @2 c- g8 Z  u+ [% ]/ D% p- B    end if;' c. F; a1 l) G
end process;7 W$ Z2 ~7 Z5 k% Y

& c- ~  U$ W# f( d, w. ?--pwm counter
5 L$ L  P# L& M3 [. s" [0 Iprocess(RST,CLK)3 h& M4 t9 `1 b6 U5 M: _: @
begin# [( s2 G) @% p
    if RST='1' then1 t% S( x7 z+ g& _
        PWMCNT<="000";
+ K# p4 _$ b& X" S$ W% p9 ?- z$ c        DISP<='0';' U% A8 k3 o4 Y3 B
    elsif rising_edge(CLK) then+ v9 N0 D. Q7 q/ F" a6 E
        PWMCNT<=PWMCNT+'1';9 ]! r1 d9 ?3 O
        if (PWMCNT="111") then
- `% R( o# ~; B1 o  q& ]$ t0 w            DISP<='1';
0 s' |/ Y8 }0 W2 J" E        elsif (PWMCNT=SWCNT) then+ p5 u4 H" i" @& `
            DISP<='0';8 m2 N0 I- [2 X, }
        end if;
$ m! `6 m9 R. Z2 F1 b* ?. `! }; G    end if;
( L! K6 o* J, v8 U: ]/ Oend process;
4 P" r2 x' D! h( n$ G; W1 H. }3 _. Z  _+ X* ?0 N4 c
--7-segment display decoder
8 ]1 [5 u( g) |+ {+ r/ ~process(DISP,SWCNT)
* \$ a8 n( A9 n8 Uvariable DISPEN : std_logic_vector(3 downto 0);. d: D  ?! R) ^' e3 h1 H
begin
, X+ M% N2 x3 {1 g) w5 s. ]4 U2 G    DISPEN := DISP SWCNT;
3 K8 g2 l4 }7 ~7 U: L    case DISPEN is --SEG7<="abcdefg"% t2 J4 w) c: F0 {! K( S& \
        when "1000"=>SEG7<="1111110";
  ?9 p' e9 @, u5 W( J        when "1001"=>SEG7<="0110000";
" }# R$ X6 w) u( _6 S9 e8 e) b        when "1010"=>SEG7<="1101101";. |7 k5 e7 e( u7 F! L4 F* ~
        when "1011"=>SEG7<="1111001";
# b5 |% c+ k! j$ R        when "1100"=>SEG7<="0110011";  }* V7 x5 J# g. P
        when "1101"=>SEG7<="1011011";
' L& d- b/ q& I1 M" \  m        when "1110"=>SEG7<="1011111";1 `& J+ |6 ?" M: O( g0 W
        when "1111"=>SEG7<="1110000";
$ M0 [) [# E$ `  U. L8 p  X# ^" R1 C7 s        when others=>SEG7<="0000000";
! {0 z) D$ M" M! _7 T    end case;4 [6 c' w9 j! |" @! s* J
end process;
; t6 ?3 o1 U/ J3 K! M+ Eend arch;
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
發表於 2009-2-2 13:02:01 | 只看該作者
process(RST,SW)3 G5 k. S  V. d, E
begin# D- l* y5 u1 d3 d. F( ^: A2 P; C
    if RST='1' then
3 _4 I4 S# F5 o8 w1 _        SWCNT<="000";0 v. q1 O0 L# o; m- f$ d" q; c
    elsif rising_edge(SW) then1 L2 u  F) ?* P" ?
        SWCNT<=SWCNT+'1';. i* d; c* b( R: i  s* i. O
    end if;, G' G0 s' z' |9 v, G% e, j
end process;
0 D. q7 a$ ~" `' U% v將 SW 以 數ms~數十ms 的取樣率取到穩定的 High/Low 才當成上述的 clock 信號就可以解決
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-6-8 07:38 PM , Processed in 0.143518 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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