EDA365电子工程师网
标题:
六十进制计数器错误
[打印本页]
作者:
淼森
时间:
2011-10-12 15:43
标题:
六十进制计数器错误
六十进制计数器
+ r# m1 I( i. G* \9 k. H3 H
library ieee;
8 C9 C/ }0 I* S
use ieee.std_logic_1164.all;
9 X/ L( h5 p! Y* m, |
use ieee.std_logic_unsigned.all;
0 }0 Z6 U, f! n
- V! C, Q# N [& I3 f7 g' |6 M; G
entity counter_60 is
+ v/ f6 d' r3 n1 `; {7 j
port(clk,bcd1wr,bcd10wr,cin:in std_logic;
0 n; _+ \& F2 ]/ j* ?4 |
co: out std_logic;
; O& @1 {/ v6 [6 @/ {
datain: in std_logic_vector(3 downto 0);
: v6 g* ~; M2 \( g
bcd1: out std_logic_vector(3 downto 0);
! \5 y5 b! k: H' g1 C# S# e
bcd10: out std_logic_vector(2 downto 0));
. a @' [: s6 p1 P$ c4 f2 K2 Q V
end counter_60;
8 y& a2 v+ p- |8 N2 ~% h
4 E4 V! g* X4 i* |
architecture rtl of counter_60 is
! K7 r2 \! \$ S% B3 t! w6 o
signal bcd1n:std_logic_vector(3 downto 0);
/ s$ e7 H" o; k7 j5 B* l/ N
signal bcd10n:std_logic_vector(2 downto 0);
+ d" y2 b1 J$ k- Q! I+ Z& N3 k& I0 U
begin
$ K+ V- W3 \8 G" o
bcd1<=bcd1n;
& g: m7 o5 R( @6 x; c
bcd10<=bcd10n;
9 I3 P, `: ^, H7 }6 S, p! V
process(clk,bcd1wr,datain) is
) [) x' w" Y3 _+ e* T
begin
7 K( q9 f0 B5 v3 B8 F
if(bcd1wr='1') then
& S4 T8 S( J4 x# A/ I
bcd1n<=datain;
1 i4 F4 J. h; z8 @7 l( [
elsif(clk'event and clk='1') then
; r+ E* F$ s' C/ j, k1 v l
if(cin='1') then
+ i, [' S& S y" {: {( [/ t
if(bcd1n=9) then
; Q+ z( T5 c) F) q+ w
bcd1n<="0000";
, T) X7 q! \% q( I% v
else
\3 n5 ^ R3 t1 Y& M4 O! _
bcd1n<=bcd1n+'1';
& E* ~3 g8 z8 c& t3 L3 p
end if;
. z% g+ g7 ~0 O m' G0 w
end if;
$ _3 w) r; ]$ M8 _$ s6 V3 c
end if;
8 Y" a$ Y: ]$ V$ X: ]
end process;
& B& N& y: d o( i( c( \$ }/ n- L5 @2 Z
/ e0 C; w/ H/ c9 G5 | ?4 E
process(clk,bcd10wr,datain) is
7 ]# m2 p1 B9 P" [0 N. d
begin
. j! X4 {4 h, K& I4 R5 D
if(bcd10wr='1') then
! F( I5 y- ?" _- _% t% Z3 Q, u
bcd10n<=datain(2 downto 0);
1 o+ X0 H. G6 [: q* t
elsif(clk'event and clk='1') then
$ X( T8 W( w* f1 f6 e/ A% J. I
if(cin='1' and bcd1n=9) then
/ L# }7 z4 A+ a' t+ @
if(bcd10n=5) then
7 b6 N# P! Q2 K. T: Z8 C
bcd10n<="000";
- Z' |- r i4 @& ~. Y
else
% i- ?' S. k8 @/ a
bcd10n<=bcd10n+'1';
2 W+ G) t- N" `- U. T
end if;
5 Z4 G- P- P6 Y! P, ~
end if;
3 \8 q$ C) Q& P; _3 c+ S" E
end if;
! J8 _+ E! X7 D+ H9 {
end process;
2 O# k) X5 C+ F9 D
& }2 D3 p5 k% j2 I7 _/ V; b) [6 q
process(bcd10n,bcd1n,cin) is
4 @6 Z% |$ z* G! a8 t! F6 x; D, t
begin
9 i% @5 k9 b. o; k2 P
if((cin='1') and (bcd1n=9) and (bcd10n=5)) then
; F# B: j/ u4 @$ I4 K2 f1 O) K
co<='1';
) c9 l d, N3 F
else
8 S6 i* P3 d5 [* z9 Z3 M, U
co<='0';
8 e& ~ i" G( p" \' M* d3 I
end if;
t' E5 ]3 P! i9 q& S
end process;
9 T5 f& B4 {4 l5 i
end rtl;
$ }8 h, t" r# j4 ~" U5 E
可以编译,但是仿真不合适,仿真不计数,请各位老师同仁指正,万分感谢
作者:
alec4050
时间:
2012-2-24 17:12
把赋值放到前面去,怎么会变, bcd1<=bcd1n;
( D# o4 I0 B6 e1 ^# s
bcd10<=bcd10n;放在最后
4 g% @* i7 @' b" Y0 u- R5 q
欢迎光临 EDA365电子工程师网 (https://bbs.elecnest.cn/)
Powered by Discuz! X3.2