|
回復 #1 tom218 的帖子
問題不夠清楚哦?????要VHDL還是Verilog??? 8bit的count有很多種,要up count還是down count?????要有加reset還是....????" N% b% W; K* z: M1 B; X' W6 r; f
我給你幾個參考.
5 n! Y d V5 K. h5 h. r: n3 _
! d y0 n. h) D! V7 _' NVHDL count( V$ I! @ b% z, y
# S# D; g6 {, L# G z
process (clock, reset)
) s" M4 k4 r: ^begin+ t6 k- v( h8 K! ^
if reset='1' then
( p- }$ r" K5 w! d+ J4 t8 G count <= (others => '0');
& e7 d# b' k9 J- V; r elsif clock='1' and clock'event then$ t0 [& |' O8 [( V5 ?/ z% O
if clock_enable='1' then
) Z* a5 y% ^+ U& H+ V count <= count + 1;6 b# }5 n1 P, d" }" S
end if;/ t, M6 ^7 M+ A( a+ [2 V
end if;
o& j4 s) J$ K( q1 fend process;6 B( Z& \: A4 p6 S( ?
2 a3 g0 s) @5 Y8 H
Verilog count
* D; H% S1 {" z; P& f( u$ B* J0 w2 a! O2 ]7 w' y7 l+ G% K$ A8 I5 N8 J" m
reg [7:0] count;
+ H& g% C4 Z# |) h6 r `$ Y1 |
0 M) s- i( J2 a0 I always @(posedge clk) c# D/ L) A- `+ V0 d8 o1 T6 N1 b( k
if (clock_enable)
! m" B$ L" h& O3 I8 u9 W9 E count <= count + 1;: V, Z7 d( j0 u4 w
3 b* Z H1 M8 Z- l6 Y9 l9 [
VHDL比較器8 h( c q: P, h e0 }8 g. w" n8 h
process(clock)
5 ]7 V7 m; l; n i; a7 _begin9 U9 u) R9 S B7 ^. K K
if (clock'event and clock ='1') then
; y* y2 r$ j# a, P& x" ? d ? if ( input1 > input2 ) then
8 |5 `9 o8 k4 a `& ` output <= '1';5 O4 w* m3 S1 X1 J3 j3 \
else , a$ R3 o! A, o7 Q4 N7 H
output <= '0';+ f' I$ c& _3 | G
end if;
7 c' v F' J# \4 r end if;
1 c; F+ u O; B* c+ `$ cend process;
/ p- X- c2 {# F# N3 o
' o0 u! `8 y& j. }, n3 C) nprocess(clock)
, k' k6 w9 u- F- m ?begin k5 O: i- k& F' K J2 ?
if (clock'event and clock ='1') then
M# P, H4 [& u; y% u if ( input1 < input2 ) then 7 X- |4 e& j! z2 \
output <= '1';
% Z% i( @; t) _ else
% n X0 s8 B/ ]& u' i output <= '0';
0 D+ _; B7 P( B: h2 O end if;9 Y6 L m- ?$ l$ d/ c
end if;
' w T% \: U' |; i4 `- {end process;
7 }6 s% d1 o$ @4 w: U* X) r! |3 P( x! `
Verilog比較器
1 |: o N3 N4 rreg output;
! l5 Z+ V. k8 m7 Y2 n& b5 T" V
always @(posedge clock)
0 V/ b/ C; w" B5 e if (input1 > input2)$ V8 U7 r# Q d5 B) R/ T
output <= 1'b1;; H/ [: w/ u A& R5 [: T
else* j1 T* l+ @6 }
output <= 1'b0;0 v% W+ y4 d& Z8 P9 |6 {4 f: @
; i' v, L! Q; D: O1 C/ f
reg output;
# K/ R H# V" i" g
' E& P$ b: u* R/ H always @(posedge clock)
: ]& Q# j0 O( I7 m y' a8 ] if (input1 < input2)
+ H( @5 J5 r; i5 { output <= 1'b1;9 d/ M; {! n5 w6 h
else
8 X0 {' H; Z, l. F+ w% l$ ]5 s2 K output <= 1'b0;% ]! z: ]$ J/ B7 A! n( x+ @7 Y
0 f: q/ Q3 a; _+ Q希望有幫助^_^ |
評分
-
查看全部評分
|