EDA365电子工程师网

标题: 数码管倒计时和蜂鸣器同步的问题,麻烦大神们进来看看,指教一二。 [打印本页]

作者: zhangsong123    时间: 2016-4-13 18:01
标题: 数码管倒计时和蜂鸣器同步的问题,麻烦大神们进来看看,指教一二。
通过Verilog HDL用数码管设计了一个40s的倒计时,想在10s之后加上一个蜂鸣器,无奈本人初学FPGA,苦试多次无果,故来此请教各位大神,能帮我在40s倒计时上面加上一个蜂鸣器吗,跪求了,谢谢!!!!module led_rxd(clk,rst_n,SOS_En_Sig,led,led_seg);
  _3 b/ v, M( ]: {( N2 D- w: oinput clk,rst_n;( c% i( t! b2 l- K0 W$ p
output [7:0]led;
& j- b8 ^! ^* W; w# m1 eoutput [5:0]led_seg;; q( P3 y  i9 U1 p
output SOS_En_Sig;* _* R& q5 W! A  d
parameter seg_num0=8'hc0,, a9 @0 x% x& M$ T5 I$ w6 g- Y; I4 F
          seg_num1=8'hf9,# n( G2 U+ u" N" y- s
             seg_num2=8'ha4,5 X) e1 K% ^' u" @$ j
             seg_num3=8'hb0,. q1 J; U! d: F5 w6 {; R
             seg_num4=8'h99,
) ^0 n6 h) [: p, c             seg_num5=8'h92,; f1 W1 m. \5 @, t9 _% l
             seg_num6=8'h82,
; c* l. Z' Z. f6 T5 p             seg_num7=8'hf8,8 P/ u! J1 a) w0 X4 N: I
             seg_num8=8'h80," O/ z( X5 a) c$ h- ]' Y  d
             seg_num9=8'h90;0 D8 I8 \6 m: @# K
parameter seg_en0=6'b111110,
0 k( L) \2 Y/ l/ ~4 ~5 _          seg_en1=6'b111101,
. E& a7 o- \% ~8 Z' e             seg_en2=6'b111011,5 `; [6 i3 Y# N- i3 y$ F- s
             seg_en3=6'b110111,
( l+ D( y3 M  p! j+ q" f2 q             seg_en4=6'b101111,
  l: y0 L" M/ _9 ?# ]             seg_en5=6'b011111;
7 q7 R. I2 F" @; p2 H9 m* ]( V* jreg [26:0]count;
2 [* m- s$ C0 o6 T/ M- {  Ureg [3:0] count1;  B( H8 Z: q* l% L# R* v
reg [3:0] count2;
8 ?$ J* X4 f3 L# _reg [7:0] led_reg;# e* H( h5 Q$ A
reg [5:0] led_seg_reg;
6 _9 N4 |8 C0 B% x5 j& ^$ d3 Lalways@(posedge clk or negedge rst_n)
& P$ K# m4 O. B6 _# T: c5 @# z2 hif(!rst_n) count<=27'd0;
% H" I; p: ]' z0 R& Z( L" _6 Pelse if(count==27'd49_999_999) count<=27'd0;+ b$ `7 l- q- Y
else count<=count+1'b1;3 K, E" O. d1 o* T
wire clk_div=(count==27'd49_999_999);
7 [+ s6 r: ^1 }3 ?' j- Nalways@(posedge clk_div or negedge rst_n)
4 w9 s/ s7 O& C8 N# }: S2 _+ E0 Xif(!rst_n)
1 W6 d7 e" R. p' x) @5 Y+ pbegin" U: b2 M4 H; u( o7 |' ~
count1<=4'd0;) o. T6 ?" F! ^1 X, w3 N6 o: U" E
count2<=4'd4;) \) W4 V; G8 r  Z( y, P
end
0 B4 Z! ^  F: Y' Qelse if((count1==4'd0)&&(count2==4'd0)); c. a& w' p6 R* ^9 d% a! W) i
begin4 K. d  f; V3 ]  G. ?1 l! Y# r
count1<=4'd0;
" z  {  W. j7 p+ vcount2<=4'd4;
( r$ s; s( e# D6 A' H: U- z& ^end3 o/ c* p. o. }3 Z' P7 O; R
else if(count1==4'd0)4 \- A* L& B" ^1 I1 [5 m' e
begin* ]) s) n' e. J
count2<= count2-1'b1;; F3 X& E4 k- d* w1 y9 x
count1<=4'd9;
" N. ^' w* o# b3 D9 D+ z/ b+ Oend6 L- E4 \) K) c, s! J
else count1<=count1-1'b1;
" N% X" K* Q+ ]reg [26:0]count_1ms;//6 a( `# u/ E1 y3 `7 K  Q) Y9 o& c
always@(posedge clk or negedge rst_n)
( k& P7 X1 [5 |6 Z5 Iif(!rst_n) count_1ms<=27'd0;  
" r/ h& p- ?  v* l& z: P- Yelse if(count_1ms==27'd49_999) count_1ms<=27'd0;0 n) W3 R% C! c  L$ O: \
else count_1ms<=count_1ms+1'b1;
7 w: i" `5 f- l1 jwire clk_dis=(count_1ms==27'd49_999);//
: e+ j3 G, i) j0 n2 |% e//
! F& K, ]" W3 l2 z& Greg [1:0]state;
) j" w0 ^1 j3 Z% Walways@(posedge clk_dis or negedge rst_n)
$ {3 m) F: c& v! G6 x/ l8 dif(!rst_n)" c4 u& g% U! I0 j2 c9 e( d
begin/ m% H8 f, I& a7 x$ f1 P: a# t) g6 G
led_reg<=8'hff;- q% X+ k% J! Q0 r; B+ ?
led_seg_reg<=6'b111111;5 X  \3 D3 p1 E' @# T7 k8 d  Y
state<=2'b00;
. {  e4 b7 O2 \end
7 I1 w2 c8 n9 R2 ^7 telse if(state==2'b00)
9 o( Z/ A& w) qbegin, x! _9 }2 L2 i6 M- t9 f5 \
state<=2'b01;
5 E; a# @( c2 Hled_seg_reg<=6'b111101;0 ^+ Y" a+ U- K6 P% D7 X& P
case(count2)( b4 C6 a( B) q
4'd0: led_reg<=seg_num0;  
6 ?% Z# q6 v) Y, d& P& O4'd1: led_reg<=seg_num1;  7 y. }" A5 @* J( w6 V1 A
4'd2:led_reg<=seg_num2;
  K+ Q! c8 P  Y7 C' G* w4'd3: led_reg<=seg_num3;  
7 j. X) w% n5 p( Z: `4'd4: led_reg<=seg_num4;  - o$ u7 E; i# D* x2 n! j7 p" _
4'd5: led_reg<=seg_num5;  2 T' ]! U* P3 ?* a0 p$ D
4'd6: led_reg<=seg_num6;  
& X3 g# Y5 @8 v6 s1 w) q4'd7: led_reg<=seg_num7;  : h6 V: b' a; m4 B
4'd8: led_reg<=seg_num8;   2 S+ A/ ^" U0 O9 s7 [$ j# p
4'd9: led_reg<=seg_num9;  
  V# Z, }! _! U! ^& b6 ]6 W$ udefault: led_reg<=seg_num0;  . u8 r: k8 B4 d+ m& p( a
endcase
6 r* _+ U+ B/ v, N* s% w" S) wend
8 v$ {# S5 O( }; U4 }& ^: V# belse if(state==2'b01)
' h6 s! I0 v4 H4 Cbegin
4 z) G* h- f2 G7 Z4 H" `+ Nstate<=2'b00;
) G1 O$ N, p% O9 Aled_seg_reg<=6'b111110;
+ e$ i$ e' f1 K: ?$ Tcase(count1)
8 H7 M4 n9 ?9 c4 f: A4'd0:led_reg<=seg_num0;
9 ?* Z: d+ O" E+ u4'd1:led_reg<=seg_num1;7 K5 n* V" O# W$ ^7 I- F# O# `' {/ i
4'd2:led_reg<=seg_num2;
5 S! v  `0 [% g9 q4'd3:led_reg<=seg_num3;
2 K9 B# J/ Y; T% C4'd4:led_reg<=seg_num4;" `# Y1 X3 p& V9 H+ ~2 a' @) f
4'd5:led_reg<=seg_num5;5 z# O9 ~; p( F$ Y: f: @
4'd6:led_reg<=seg_num6;, j' o. L0 m  ^2 g
4'd7:led_reg<=seg_num7;
/ u. Y5 k* E3 v. I- V" D4'd8:led_reg<=seg_num8;4 {' L2 S4 b# y! J- L; P1 N, e
4'd9:led_reg<=seg_num9;0 E/ P& T3 X! t1 P; h! Q% O
default:led_reg<=seg_num0;% e! u$ A2 e" p8 B- p. m
endcase; {) @0 i3 a5 n. w0 ?* K1 v
end% }9 @) a! u! ^" Y4 F2 ^3 P
reg isEn;
3 u% v, `$ M9 Y& f# f/ Dalways@(posedge clk or negedge rst_n)
1 m5 J8 b: P& m1 ]7 z9 @if(!rst_n)
& M& ~: l5 P& h- j) I5 z! x' Tbegin3 W. Y. m5 d8 ^7 C
isEn<=1'b0;' [0 N4 _# a  D
end$ |: |8 e( H' A, ]8 `& `. y. j2 [/ I
else( w$ w; t1 [" T. h3 P9 M$ F
begin! R  L7 q+ T0 Y1 N% {. o" m
isEn<=1'b1;. x* w6 R1 a6 f6 g* p( j! a5 p
end% l" `  ?* \, b. o. Q: I
assign led=led_reg;
8 i( ?/ {* t% w$ K0 n/ z8 {2 p3 qassign led_seg=led_seg_reg;
. R, @! E: q7 B# Sassign SOS_En_Sig=isEn;
/ |* R' J  C& b3 h8 M: q/ ^endmodule+ }4 _3 }8 u+ q6 r$ a

3 v; f+ D! i+ k3 R8 |$ {




欢迎光临 EDA365电子工程师网 (https://bbs.elecnest.cn/) Powered by Discuz! X3.2