|
此程式為一個每按一次TACT SW就會進行累加1的程式,並且LED亮度會每累加一次
0 u) ^* I; U' b* f9 |' Q) [; R4 R就會增加,共8段亮度(0~7),此程式這些功能都可以了,但是會有開關彈跳的問題,
1 p) L& W7 G. J& O4 g& r希望能有高手幫我解決此問題7 R5 Y# J4 k4 `/ ~' S( O
: B8 V% ]; u6 E- D& @. f* m! y4 N8 Q2 j9 Y
library ieee;
0 F% @% l: C- ause ieee.std_logic_1164.all;
; c! J% j9 w; k, V B" {use ieee.std_logic_arith.all;
0 ]3 {3 s: B+ A' J" luse ieee.std_logic_unsigned.all; ~, |" |0 Z; U+ P7 V# i4 h* e2 f
1 V" \+ m7 I$ o" p1 ]; d
entity pwm8 is Port (0 e/ N( c0 s5 t
CLK : in std_logic;--clock 1KHZ6 w/ m+ m! x' A" l
RST : in std_logic;--reset
- h4 Y' ~1 s) j5 A6 ~& \' A# T SW : in std_logic;--switch in* D7 n; Q# v# \& u
SEG7 : out std_logic_vector(6 downto 0));--1 J9 _2 e, n, r1 M- [5 c7 b
end pwm8;- B/ s7 E. V: I7 U4 F! ]
" e. a: X ?- |* A% x) p, @! ?
architecture arch of pwm8 is' U, t5 o l& z/ l# @
* {+ Q4 r! p9 i! h. `) `signal SWCNT : std_logic_vector(2 downto 0);
7 ^; G; e( ?; i2 @( isignal PWMCNT : std_logic_vector(2 downto 0);
9 I* M7 H! L3 E+ b) m- K, `# ^signal DISP : std_logic;) I# u! \1 Y# a2 |2 i5 Z
' E) L: h1 t$ |) ~0 w% u
begin6 o/ ]3 P0 \) V& ^2 V+ W6 j; D
/ G: l8 Q) t2 ` C" m8 v( |! t
--toggle switch input counter
8 v# S9 }# t& Eprocess(RST,SW)
4 ~, ]% c4 q# {0 m9 Cbegin
' \9 @( r4 M9 ^( ?$ T if RST='1' then
( A5 }8 w% p1 d SWCNT<="000";
2 \5 ?, n8 n* S$ g$ U& S6 m elsif rising_edge(SW) then
j H7 M$ l; }% c. x) ~ SWCNT<=SWCNT+'1';
6 {- h4 r; {, j$ V end if;
* T& }/ Z" H3 }% B$ s* j: }# p+ Mend process;
, ]( e+ _2 R" b" D$ r4 C) A0 { o1 j/ m# y
--pwm counter
4 F5 M! O( j( C0 o. zprocess(RST,CLK)
7 ^8 F& ?" B) N0 E9 R) gbegin
, V/ C- ?1 ^: N- ~. ?( ` if RST='1' then
# l! D- O4 [& x/ q* g, W PWMCNT<="000";
# y, u9 c3 ]5 m# C% } DISP<='0';
' Z% O) L0 G7 x/ q X- ~ elsif rising_edge(CLK) then! U! z0 a' ?. c/ ?
PWMCNT<=PWMCNT+'1';
, q9 L G1 Y% {( I& o# }4 H9 \ if (PWMCNT="111") then
4 h2 F0 S' t( d' ?" H# N: [ DISP<='1';- t3 u$ u( q0 S$ b
elsif (PWMCNT=SWCNT) then' x6 I5 c3 d6 ^9 q$ K$ @
DISP<='0';
1 s/ ^6 I, }' N2 u' O6 R! Y! P end if;/ j1 z' O( t% I& D; o
end if;6 G) [+ r& K+ N' a( f: {
end process;2 A# j- L( R* y* O& {1 }0 c1 P
" l) v8 L3 y( E" `
--7-segment display decoder
; d% \ @1 b: jprocess(DISP,SWCNT)
6 I( {0 ~5 E$ x/ S8 {" ?! nvariable DISPEN : std_logic_vector(3 downto 0);
; ^5 W) R3 k7 }4 Ebegin9 R4 s8 b9 X; R
DISPEN := DISP SWCNT;' M& O0 Y$ \1 h4 b. }3 w6 b
case DISPEN is --SEG7<="abcdefg"9 Q! |, M8 I2 \5 l! g
when "1000"=>SEG7<="1111110";% Y4 U: c! K4 Z3 A5 h4 H) e% r/ c
when "1001"=>SEG7<="0110000";3 ^/ K0 w) O8 A2 |
when "1010"=>SEG7<="1101101";) _+ o# c( |8 g3 X
when "1011"=>SEG7<="1111001";5 @1 x* U, q+ L' A
when "1100"=>SEG7<="0110011";% U) B; @. {% P6 m: K
when "1101"=>SEG7<="1011011";# _. t! R0 p" M, f$ D- Z% L
when "1110"=>SEG7<="1011111";
2 J! N9 B- n! D- x; s when "1111"=>SEG7<="1110000";
& S9 `7 Q$ O c0 `( s when others=>SEG7<="0000000";
& G! `. S# u8 `0 r) g+ K; y4 T3 b end case;$ G# T# k6 {$ y# l# v6 }/ X
end process;
; I. N8 X1 h; `, }5 s2 Q: }+ aend arch; |
|