Escolar Documentos
Profissional Documentos
Cultura Documentos
__ a r c h i t e c t u r e body
20 a r c h i t e c t u r e demo-arch of bin-counter i s
-- c o n s t a n t declaration
c o n s t a n t M A X : integer : = ( 2 * * N - 1 ) ;
_- i n t e r n a l s i g n a l d e c l a r a t i o n
s i g n a l r - r e g : u n s i g n e d ( N - 1 downto 0 ) ;
25 s i g n a l r-next : u n s i g n e d ( N - 1 downto 0 ) ;
begin
__
_- component i n s t a n t i a t i o n
__
30 -- no i n s t a n t i a t i o n in t h i s code
--
-- memory e l e m e n t s
__
35 -- r e g i s t e r
p r o c e s s (clk,reset)
begin
i f (reset=’l’) then
r - r e g <= ( o t h e r s = > ’ O ’ ) ;
40 e l s i f ( c l k ’ e v e n t and c l k = ’ l ’ ) t h e n
r - r e g <= r - n e x t ;
end i f ;
end p r o c e s s ;
45 --
__ c o m b i n a t i o n a l circuits
__
-- next-state logic
r-next <= ( o t h e r s = > ’ O ’ ) when s y n - c l r = ’ l ’ e l s e
so unsigned(d) when l o a d = ’ 1 e l s e
r-reg + 1 when en = ’ 1 ’ else
r-reg ;
_- o u t p u t l o g i c
q <= s t d - l o g i c - v e c t o r ( r - r e g ) ;
55 m a x - t i c k <= ’ 1 ’ when r - r e g = M A X e l s e > O ’ ;
end d e m o - a r c h ;
a r c h i t e c t u r e arch of f ixed-shift-demo i s
begin
-_ s h i f t l e f t 3 p o s i t i o n s
shl <= a(4 downto 0 ) & " 0 0 0 " ;
15 -- s h i f t r i g h t 3 p o s i t i o n s ( l o g i c a l s h i f t )
sh2 <= " 0 0 0 " & a(7 downto 3);
-- s h i f t r i g h t 3 p o s i t i o n s and s h i f t i n g i n s i g n bit
__ ( a r i t h m e t i c s h i f t )
sh3 <= a(7) & a(7) & a(7)& a(7 downto 3);
20 -- r o t a t e r i g h t 3 p o s i t i o n s
rot <= a(2 downto 0 ) & a(7 downto 3);
-- swap t w o n i b b l e s
swap <= a(3 downto 0 ) & a(7 downto 4);
end arch;
a r c h i t e c t u r e concurrent-arch of decoderl i s
s i g n a l s : std-logic-vector ( 2 downto 0 ) ;
begin
___________-_____________________________-_-_
_________________________________________-_
COMBINATIONAL CIRCUITS 423
end concurrent-arch;
a r c h i t e c t u r e s e q - a r c h of d e c o d e r 2 i s
s i g n a l s : s t d - l o g i c - v e c t o r (2 downto 0 ) ;
begin
____________________---------_---------------
____________________--------_----_---------
15 -- i f statement
____________________-----------------------
--__________________-__----------------------
p r o c e s s ( e n , a)
begin
i f (en='O') t h e n
y l <= "0000";
e l s i f (a='lOOll) t h e n
y l <= "0001";
e I s i f ( a = "0 1 'I ) t h e n
yl <= "0010";
e l s i f (a=!!10 ) t h e n
yl <= "0100";
else
y l <= " 1 0 0 0 " ;
424 SAMPLE VHDL TEMPLATES
end i f ;
30 end p r o c e s s ;
__
__ case statement
__
35 s <= en L! a ;
process ( s )
begin
case s is
when l l O O O 1 t I l t O O 1 l t I l t O l o l l I "o111t =>
40 y 2 <= " 0 0 0 1 " ;
when " 1 0 0 " = >
y 2 <= " 0 0 0 1 " ;
when l t l ~ => llp
y 2 <= " 0 0 1 0 " ;
45 when l l l l O t ' = >
y 2 <= " 0 1 0 0 " ;
when o t h e r s =>
y2 <= " 1 0 0 0 " ;
end c a s e ;
jn end p r o c e s s ;
end s e q - a r c h ;
a r c h i t e c t u r e arch of comb-proc i s
begin
_--------------------------------------------
15 -- w i t h o u t default output signal assignment
__-------------------------------------------
-- m u s t i n c l u d e e l s e b r a n c h
__ o u t p u t s i g n a l m u s t b e a s s i g n e d in all branches
p r o c e s s (a,b,data-in)
20 begin
i f a > b then
xa-out <= d a t a - i n ;
xb-out <= ( o t h e r s = > ' O ' ) ;
e l s i f a < b then
MEMORY COMPONENTS 425
architecture a r c h of r e g - t e m p l a t e is
15 begin
__
__ register without reset
__
p r o c e s s (clk)
20 begin
i f ( c l k ’ e v e n t and c l k = ’ l ’ ) t h e n
ql-reg <= q l - n e x t ;
end i f ;
426 SAMPLE VHDL TEMPLATES
end p r o c e s s ;
25
__-------------------------------------------
__ r e g i s t e r w i t h a s y n c h r o n o u s r e s e t
__-------------------------------------------
p r o c e s s (clk , r e s e t )
30 begin
if (reset=’l’) then
q 2 - r e g < = ( o t h e r s = >’ 0 ’ ) ;
e l s i f ( c l k ’ e v e n t and c l k = ’ l ’ ) t h e n
q 2 - r e g <= q 2 - n e x t ;
35 end i f ;
end p r o c e s s ;
__-------------------------------------------
__ r e g i s t e r w i t h e n a b l e a n d a s y n c h r o n o u s r e s e t
40
...........................................
--______________________________________-----
p r o c e s s (clk, reset)
begin
i f (reset=’l ’ ) then
q3-reg < = ( o t h e r s = > ’ O ’ ) ;
45 e l s i f ( c l k ’ e v e n t and c l k = ’ l ’ ) t h e n
if (en=’l’) then
q 3 - r e g <= q 3 - n e x t ;
end i f ;
end i f ;
50 end p r o c e s s ;
end a r c h ;
a r c h i t e c t u r e a r c h of r e g - f i l e i s
t y p e r e g - f i l e - t y p e i s a r r a y (2**W-1 downto 0 ) of
REGULAR SEQUENTIALCIRCUITS 427
20 std-logic-vector ( B - 1 downto 0 ) ;
s i g n a l array-reg : reg-f ile-type ;
begin
p r o c e s s (clk,reset)
begin
25 i f (reset=’l’) t h e n
array-reg <= ( o t h e r s = > ( o t h e r s = > ’ O ’ ) ) ;
e l s i f (clk’event and clk=’l’) t h e n
i f wr-en=’l ’ t h e n
array-reg(to-integer(unsigned(w-addr))) <= w-data;
30 end i f ;
end i f ;
end p r o c e s s ;
__ r e a d p o r t
r-data <= array-reg(to-integer(unsigned(r-addr)));
35end arch;
IS a r c h i t e c t u r e demo-arch of bin-counter i s
c o n s t a n t M A X : integer : = (2**N-1) ;
s i g n a l r-reg: unsigned(N-1 downto 0 ) ;
s i g n a l r-next : unsigned (N-1 downto 0 ) ;
20 begin
__
__ register
__
p r o c e s s (clk,reset)
25 begin
i f (reset=’l’) t h e n
r-reg <= ( o t h e r s = > ’ O ’ ) ;
e l s i f (clk’event a n d clk=’l’) t h e n
r-reg < = r-next;
30 end i f ;
428 SAMPLE VHDL TEMPLATES
end p r o c e s s ;
__ n e x t - s t a t e logic
40 -- output logic
q <= s t d - l o g i c - v e c t o r ( r - r e g ) ;
m a x - t i c k <= ’1’ when r-reg=MAX else ’0’;
end d e m o - a r c h ;
A.5 FSM
a r c h i t e c t u r e t w o - s e g - a r c h of f s m - e g i s
type e g - s t a t e - t y p e i s (SO, sl, s 2 ) ;
signal s t a t e - r e g , state-next : eg-state-type;
15 begin
__ state register
p r o c e s s ( c l k ,r e s e t
20 begin
i f ( r e s e t = ’ l ’ ) then
s t a t e - r e g <= S O ;
e l s i f ( c l k ’ e v e n t and c l k = ’ l ’ ) t h e n
s t a t e - r e g <= s t a t e - n e x t ;
25 end i f ;
end p r o c e s s ;
__
__ next-state /output logic
__
30 process ( s t a t e - r e g , a , b )
begin
s t a t e - n e x t <= s t a t e - r e g , ; -- d e f a u l t b a c k t o same s t a t e
FSM 429
lb
, ..........................................
y l c= 1
6+ I
I-
...................
, ...................
ylc-I
..........
.....,.....
I.........
r F
y o <= ’ 0 ’ ; -- d e f a u l t 0
y l <= ’ 0 ’ ; -- d e f a u l t 0
35 case s t a t e - r e g is
when S O = >
if a = ’ l J then
if b = ’ l ’ then
s t a t e - n e x t <= s 2 ;
40 yo <= ’ 1 ’ ;
else
s t a t e - n e x t <= s l ;
end i f ;
-- no e l s e b r a n c h , u s e d e f a u l t
45 end i f ;
when sl = >
y 1 <= ’ 1 ’ ;
if ( a = ’ l ’ ) then
s t a t e - n e x t <= S O ;
50 -- n o e l s e b r a n c h , u s e d e f a u l t
end i f ;
when s 2 =>
s t a t e - n e x t <= S O ;
end c a s e ;
55 end p r o c e s s ;
end t w o - s e g - a r c h ;
A.6 FSMD
15 a r c h i t e c t u r e a r c h of f i b i s
type s t a t e - t y p e is ( i d l e , o p , d o n e ) ;
signal state-reg , state-next : state-type ;
signal to-reg , to-next , t l - r e g , t l - n e x t :
u n s i g n e d ( 1 9 downto 0 ) ;
20 s i g n a l n - r e g , n - n e x t : u n s i g n e d ( 4 downto 0 ) ;
begin
-------------------------===========-----====
FSMD 431
(7)
start=l
2
t l t I
........................................
................................................................
s t a t e - r e g <= s t a t e - n e x t ;
t o - r e g <= t o - n e x t ;
15 t l - r e g <= t l - n e x t ;
n - r e g <= n - n e x t ;
end i f ;
end p r o c e s s ;
________________________________________---
--_______________________--______-__---__----
40 -- n e x t - s t a t e l o g i c and d a t a p a t h f u n c t i o n a l u n i t s
.............................................
process ( s t a t e - r e g , n - r e g , to-reg , t l - r e g , start , i ,n-next)
begin
ready <=’O’;
45 d o n e - t i c k <= ’ 0 ’ ;
s t a t e - n e x t <= s t a t e - r e g ; -- d e f a u l t b a c k t o s a m e s t a t e
t o - n e x t <= t o - r e g ; -- d e f a u l t k e e p p r e v i o u s v a l u e
t l - n e x t <= t l - r e g ; __ d e f a u l t k e e p p r e v i o u s v a l u e
n - n e x t <= n - r e g ; __ d e f a u l t k e e p p r e v i o u s v a l u e
50 case s t a t e - r e g i s
when i d l e =>
r e a d y <= ’ 1 ) ;
i f s t a r t = ’ l ’ then
t o - n e x t <= ( o t h e r s = > ’ O ’ ) ;
55 t i - n e x t <= ( 0 = > ’ 1 ’ , o t h e r s = > ’ O ’ ) ;
n - n e x t <= u n s i g n e d ( i );
s t a t e - n e x t <= o p ;
end i f ;
when o p = >
60 i f n - r e g = O then
t i - n e x t <= ( o t h e r s = > ’ O ’ ) ;
state-next <= d o n e ;
e l s i f n - r e g = l then
s t a t e - n e x t <= d o n e ;
65 else
t l - n e x t <= t l - r e g + t o - r e g ;
t o - n e x t <= t l - r e g ;
n - n e x t <= n - r e g - 1 ;
end i f ;
70 when d o n e =>
d o n e - t i c k <= ’ 1 ’ ;
s t a t e - n e x t <= i d l e ;
end c a s e ;
end p r o c e s s ;
75 -- o u t p u t
53 BOARD CONSTRAINT FILE (S3 .UCF) 433
f <= s t d - l o g i c - v e c t o r ( t l - r e g ) ;
end a r c h ;
#
# Pin assignment f o r Xilinx
# Spartan-3 S t a r t e r board
#
#
# clock and r e s e t
#:
NET " c l k " LOC = " T 9 " ;
NET " r e s e t " LOC = " L 1 4 " ;
#
# buttons & switches
#
# 4 push buttons
NET " b t n < O > " LOC = "M13";
NET " b t n < l > " LOC = "M14";
NET " b t n < 2 > " LOC = "L13";
#NET " b t n < 3 > " LOC = "L14"; #btn<3> also used a s r e s e t
# 8 s l i d e switches
NET "sw<O>" LOC = "F12";
NET "sw<l>" LOC = "G12";
NET " s w < 2 > " LOC = "H14";
NET "sw<3>" LOC = "H13";
NET " s w < 4 > " LOC = "514";
NET "sw<5>" LOC = "513";
NET " s w < 6 > " LOC = "K14";
NET " s w < 7 > " LOC = "K13";
#
# RS232
#
NET " r x " LOC = " T 1 3 " I D R I V E = 8 I SLEW=SLOW;
NET " t x " LOC = " R 1 3 " I D R I V E = 8 1 SLEW=SLOW;
#
# 4-digit time-multiplexed 7-segment LED d i s p l a y
#
# d i g i t enable
NET " a n < O > " LOC = "D14";
NET " a n < l > " LOC = "G14";
NET " a n < 2 > " LOC = "F14";
NET " a n < 3 > " LOC = "E13":
# 7-segment l e d segments
434 SAMPLE VHDL TEMPLATES
#
# 8 d i s c r e t e LEDs
#
NET "led<O>" LOC = "K12";
NET "led<l>" LOC = "P14";
NET "led<2>" LOC = "L12";
NET "led<3>" LOC = "N14";
NET "led<4>" LOC = "P13";
NET "led<5>" LOC = "N12";
NET "led<6>" LOC = "P12";
NET "led<7>" LOC = "P11";
#
# VGA outputs
#
NET "rgb<2>" LOC = "R12" I DRIVE=8 I SLEW=FAST;
NET "rgb<l>" LOC = "T12" I DRIVE=8 I SLEW=FAST;
NET "rgb<O>" LOC = "Rl1" I DRIVE=8 I SLEW=FAST;
NET "vsync" LOC = "T10" I DRIVE=8 1 SLEW=FAST;
NET "hsync" LOC = "R9" I DRIVE=8 I SLEW=FAST;
#
# PS2 p o r t
#
NET " p s 2 c " L O C = " M 1 6 " I D R I V E = 8 I SLEW=SLOW;
NET " p s 2 d " L O C = " M 1 5 " I D R I V E = 8 1 SLEW=SLOW;
#
# two SRAM c h i p s
#:
# s h a r e d 1 8 - b i t memory address
NET " a d < 1 7 > " L O C = " L 3 " I IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 1 6 > " LOC="K5" 1 IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 1 5 > " L O C = " K 3 " I IOSTANDARD = LVCMOS33 1 SLEW=FAST;
NET " a d < 1 4 > " LOC=" 5 3 " I IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 1 3 > " L O C = I ' J 4 " 1 IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 1 2 > " L O C = " H 4 " 1 IOSTANDARD = LVCMOS33 1 SLEW=FAST;
NET " a d < l l > " LOC="H3" I IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < l O > " LOC="G5" 1 IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 9 > " LOC="E4" I IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 8 > " LOC="E3" I IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 7 > " LOC="F4" I IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 6 > " LOC="F3" I IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET " a d < 5 > " LOC="G4" I IOSTANDARD = LVCMOS33 I SLEW=FAST;
53 BOARD CONSTRAINT FILE (S3.UCF) 435
# shared oe, we
NET "oe-n" LOC="K4" I IOSTANDARD = LVCMOS33 I SLEW=FAST;
NET "we-n" LOC="G3" I IOSTANDARD = LVCMOS33 I SLEW=FAST;