ucyf lab6 2009


Przykład realizacji ćwiczenia nr 6
Opracował: dr Piotr Sapiecha
Spis treści
1 Wstęp 2
1.1 Algorytm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Sekwencyjna specyfikacja algorytmu w języku CPP . . . . . . . . . . . . 2
1.3 Specyfikacja algorytmu w języku VHDL . . . . . . . . . . . . . . . . . . 3
2 Implementacja 4
2.1 Moduł Data Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Komponenty modułu Data Path . . . . . . . . . . . . . . . . . . . . . . 8
2.2.1 Sumator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.2 Komparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.3 Dekrementator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.4 Multiplekser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.5 Rejestr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3 Moduł FSM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4 Integracja modułów FSM i Data Path . . . . . . . . . . . . . . . . . . . 15
3 Wyniki kompilacji i symulacji 18
3.1 Kompilacja . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2 Symulacja . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1
Rozdział 1
Wstęp
1.1 Algorytm
Realizacja algorytmu wyznaczania wyrazów ciągu w języku VHDL z zastosowaniem
podziału projektu na moduły: FSM i Data Path.
Definicja 1. Niech będzie dany ciąg:
dla
Dla i będzie to ciąg Fibonacciego.
Uwaga 1. Fibonacci  Leonardo z Pizy żył w latach 1170-1250. Jacques Philippe Maria
Binet (1786-1856) podał wzór jawny służący do wyznaczania n tego wyrazu ciągu:
1.2 Sekwencyjna specyfikacja algorytmu w języku CPP
void f i b ( int count , int x , int y ) {
int f i r s t = y , second = x ; // r e j e s t r y , mul tipleksery
while ( count ) // dekrementacja , porównanie z 0
{ int tmp = f i r s t+second ; // sumator
f i r s t = second ; // multiple ksery
second = tmp ; // multiple ksery
p r i n t f (  %d ,  , second ) ;
}
}
Uwaga 2. Implementacja ta ma złożoność czasową . Istnieje inna, bardziej efek-
tywna metoda wyznaczania n tego elementu ciągu, w czasie .
2
1.3 Specyfikacja algorytmu w języku VHDL
library IEEE ;
use IEEE . std_logic_1164 . a l l ;
use IEEE . s t d _ l o g i c _ a r i t h . a l l ;
entity f i b o n a c c i i s
generic (N : i n t e g e r : = 1 6 ) ;
port ( clk , r s t : in b i t ;
fibo_s : out i n t e g e r range 0 to 2 N 1
) ;
end f i b o n a c c i ;
architecture fib_arc of f i b o n a c c i i s
signal a : i n t e g e r range 0 to 2 N 1 := 0 ;
signal b : i n t e g e r range 0 to 2 N 1 := 1 ;
signal c : i n t e g e r range 0 to 2 N 1 := 0 ;
begin
process ( clk , r s t , b , c )
begin
i f ( r s t =  1  ) then
b <= 1 ;
c <= 0 ;
a <= 0 ;
e l s i f ( clk  event and c l k =  1  ) then
c <= b ;
b <= a ;
end i f ;
a <= b + c ;
end process ;
fibo_s <= a ;
end fib_arc ;
3
Rozdział 2
Implementacja
W implementacji dokładamy możliwość swobodnego zdefiniowania wartości elementów
początkowych i .
Wstępny projekt modułu Data Path
Input: x_i, y_i - wartości początkowe F(0) i F(1)
c_i - odpowiednik wartości count
rst, clk - reset, zegar
Output: z_o - odpowiednik wartości tmp
4
Rysunek 1 Schemat modułu Data Path.
5
2.1 Moduł Data Path
library i e e e ;
use i e e e . std_logic_1164 . a l l ;
use i e e e . s t d _ l o g i c _ a r i t h . a l l ;
use i e e e . std_logic_unsigned . a l l ;
use work . a l l ;
entity dp i s
port (
r s t , c l k : in s t d _ l o g i c ;
x_i , y_i , c_i : in std_logic_vector (3 downto 0 ) ;
comp : out s t d _ l o g i c ;
x s e l , y s e l : in s t d _ l o g i c ;
x_ld , y_ld : in s t d _ l o g i c ;
c_ld : in s t d _ l o g i c ;
z_o : out std_logic_vector (3 downto 0)
) ;
end dp ;
architecture dp_arc of dp i s
component mux i s
port ( r s t , sLine : in s t d _ l o g i c ;
load , r e s u l t : in std_logic_vector (3 downto 0 ) ;
output : out std_logic_vector (3 downto 0)
) ;
end component ;
component com i s
port ( r s t : in s t d _ l o g i c ;
x : in std_logic_vector (3 downto 0 ) ;
output : out s t d _ l o g i c
) ;
end component ;
component add i s
port ( r s t : in s t d _ l o g i c ;
x , y : in std_logic_vector (3 downto 0 ) ;
output : out std_logic_vector (3 downto 0)
6
) ;
end component ;
component dec i s
port ( r s t , c l k : in s t d _ l o g i c ;
input : in std_logic_vector (3 downto 0 ) ;
dec_load : in s t d _ l o g i c ;
output : out std_logic_vector (3 downto 0)
) ;
end component ;
component r e g i s i s
port ( r s t , clk , load : in s t d _ l o g i c ;
input : in std_logic_vector (3 downto 0 ) ;
output : out std_logic_vector (3 downto 0)
) ;
end component ;
signal x , y , xmux , ymux , xreg , yreg , zreg , r e s u l t , cc
: std_logic_vector (3 downto 0 ) ;
signal compp : s t d _ l o g i c ;
begin
X_MUX: mult port map( r s t , x s e l , x_i , r e s u l t , xmux ) ;
Y_MUX: mult port map( r s t , y s e l , y_i , xreg , ymux ) ;
X_REG: r e g i s port map( r s t , clk , x_ld , xmux , xreg ) ;
Y_REG: r e g i s port map( r s t , clk , y_ld , ymux , yreg ) ;
Z_ADD: add port map( r s t , xreg , yreg , r e s u l t ) ;
z_o <= r e s u l t ;
X_DEC: dec port map( r s t , clk , c_i , c_ld , cc ) ;
X_COM: com port map( r s t , cc , compp ) ;
comp <= compp ;
end dp_arc ;
7
2.2 Komponenty modułu Data Path
Komponentami są następujące moduły: sumator, komparator, dekremantator, multi-
plekser, rejestr.
2.2.1 Sumator
library i e e e ;
use i e e e . std_logic_1164 . a l l ;
use i e e e . s t d _ l o g i c _ a r i t h . a l l ;
use i e e e . std_logic_unsigned . a l l ;
entity add i s
port ( r s t : in s t d _ l o g i c ;
x , y : in std_logic_vector (3 downto 0 ) ;
output : out std_logic_vector (3 downto 0)
) ;
end add ;
architecture add_arc of add i s
begin
process ( r s t , x , y )
begin
i f ( r s t =  1  ) then
output <= " 0000 " ;
else
output <= ( x+y ) ;
end i f ;
end process ;
end add_arc ;
2.2.2 Komparator
library i e e e ;
use i e e e . std_logic_1164 . a l l ;
use i e e e . s t d _ l o g i c _ a r i t h . a l l ;
use i e e e . std_logic_unsigned . a l l ;
entity com i s
port ( r s t : in s t d _ l o g i c ;
x : in std_logic_vector (3 downto 0 ) ;
output : out s t d _ l o g i c
8
) ;
end com ;
architecture com_arc of com i s
begin
process ( x , r s t )
begin
i f ( r s t =  1  ) then
output <=  0  ;
e l s i f ( x>0) then
output <=  1  ;
else output <=  0  ;
end i f ;
end process ;
end com_arc ;
2.2.3 Dekrementator
library i e e e ;
use i e e e . std_logic_1164 . a l l ;
use i e e e . s t d _ l o g i c _ a r i t h . a l l ;
use i e e e . std_logic_unsigned . a l l ;
entity dec i s
port ( r s t , c l k : in s t d _ l o g i c ;
input : in std_logic_vector (3 downto 0 ) ;
dec_load : in s t d _ l o g i c ;
output : out std_logic_vector (3 downto 0)
) ;
end dec ;
architecture dec_arc of dec i s
signal count : std_logic_vector (3 downto 0 ) ;
begin
process ( r s t , clk , dec_load , count )
begin
i f ( r s t =  1  ) then
count <=" 0000 " ;
e l s i f ( clk  event and c l k =  1  and dec_load =  1  ) then
count <= input ;
e l s i f ( clk  event and c l k =  1  and count > 0) then
count <= count 1 ;
9
else count <= count ;
end i f ;
end process ;
output<=count ;
end dec_arc ;
2.2.4 Multiplekser
library i e e e ;
use i e e e . std_logic_1164 . a l l ;
use i e e e . s t d _ l o g i c _ a r i t h . a l l ;
use i e e e . std_logic_unsigned . a l l ;
use work . a l l ;
entity mult i s
port ( r s t , sLine : in s t d _ l o g i c ;
load , r e s u l t : in std_logic_vector (3 downto 0 ) ;
output : out std_logic_vector (3 downto 0)
) ;
end mult ;
architecture mult_arc of mult i s
begin
process ( r s t , sLine , load , r e s u l t )
begin
i f ( r s t =  1  ) then
output <=" 0000 " ;
e l s i f sLine=  0  then
output<=load ;
else output<=r e s u l t ;
end i f ;
end process ;
end mult_arc ;
2.2.5 Rejestr
library i e e e ;
use i e e e . std_logic_1164 . a l l ;
use i e e e . s t d _ l o g i c _ a r i t h . a l l ;
use i e e e . std_logic_unsigned . a l l ;
entity r e g i s i s
10
port ( r s t , clk , load : in s t d _ l o g i c ;
input : in std_logic_vector (3 downto 0 ) ;
output : out std_logic_vector (3 downto 0)
) ;
end r e g i s ;
architecture r e g i s _ a r c of r e g i s i s
begin
process ( r s t , clk , load , input )
begin
i f ( r s t =  1  ) then
output <=" 0000 " ;
e l s i f ( clk  event and c l k =  1  ) then
i f ( load =  1  ) then
output<=input ;
end i f ;
end i f ;
end process ;
end r e g i s _ a r c ;
2.3 Moduł FSM
Wstępny projekt modułu FSM
Input:
proceed - wywołuje uruchomienie maszyny stanów
comp - podaje informacje czy licznik jest dodatni
rst, clk
Output:
xsel, ysel - wybiera dane na wejście
x_ld, y_ld, c_ld - steruje załadowaniem danych
11
Rysunek 2 Schemat modułu FSM.
12
library i e e e ;
use i e e e . std_logic_1164 . a l l ;
use i e e e . s t d _ l o g i c _ a r i t h . a l l ;
use i e e e . std_logic_unsigned . a l l ;
entity fsm i s
port ( r s t , clk , proceed : in s t d _ l o g i c ;
comp : in s t d _ l o g i c ;
x s e l , y s e l , xld , yld , c l d : out s t d _ l o g i c
) ;
end fsm ;
architecture fsm_arc of fsm i s
type s t a t e s i s ( i n i t , s1 , s2 ) ;
signal nState , c S t a t e : s t a t e s ;
begin
process ( r s t , c l k )
begin
i f ( r s t =  1  ) then
c S t a t e <= i n i t ;
e l s i f ( clk  event and c l k =  1  ) then
c S t a t e <= nState ;
end i f ;
end process ;
process ( proceed , comp , c S t a t e )
begin
case c S t a t e i s
when i n i t => x s e l <=  0  ;
y s e l <=  0  ;
xld <=  0  ;
yld <=  0  ;
c l d <=  0  ;
i f ( proceed =  0  ) then nState <= i n i t ;
else nState <= s1 ;
end i f ;
when s1 => x s e l <=  0  ;
13
y s e l <=  0  ;
xld <=  1  ;
yld <=  1  ;
c l d <=  1  ;
nState <= s2 ;
when s2 => x s e l <=  1  ;
y s e l <=  1  ;
xld <=  1  ;
yld <=  1  ;
c l d <=  0  ;
i f (comp=  1  ) then nState <= s2 ;
else nState <= i n i t ;
end i f ;
when others => nState <= i n i t ;
end case ;
end process ;
end fsm_arc ;
14
2.4 Integracja modułów FSM i Data Path
Rysunek 3 Integracja modułów FSM i Data Path.
15
library i e e e ;
use i e e e . std_logic_1164 . a l l ;
use i e e e . s t d _ l o g i c _ a r i t h . a l l ;
use i e e e . std_logic_unsigned . a l l ;
entity f i b i s
port ( r s t , clk , go_i : in s t d _ l o g i c ;
x_i , y_i , c_i : in std_logic_vector (3 downto 0 ) ;
d_o : out std_logic_vector (3 downto 0)
) ;
end f i b ;
architecture fib_arc of f i b i s
component fsm i s
port ( r s t , clk , proceed : in s t d _ l o g i c ;
comp : in s t d _ l o g i c ;
x s e l , y s e l , xld , yld , c l d : out s t d _ l o g i c
) ;
end component ;
component dp i s
port ( r s t , c l k : in s t d _ l o g i c ;
x_i , y_i , c_i : in std_logic_vector (3 downto 0 ) ;
comp : out s t d _ l o g i c ;
x s e l , y s e l : in s t d _ l o g i c ;
x_ld , y_ld : in s t d _ l o g i c ;
c_ld : in s t d _ l o g i c ;
z_o : out std_logic_vector (3 downto 0)
) ;
end component ;
signal xld , yld , cld , x s e l , y s e l , compp : s t d _ l o g i c ;
begin
TOFSM: fsm port map( r s t , clk , go_i ,
compp , x s e l , y s e l , xld , yld , c l d ) ;
TODP: dp port map( r s t , clk , x_i , y_i , c_i ,
16
compp , x s e l , y s e l , xld , yld , cld , d_o ) ;
end fib_arc ;
17
Rozdział 3
Wyniki kompilacji i symulacji
3.1 Kompilacja
Rysunek 4 Schemat zintegrowanego układu Fibonacci.
Układ: Cyclone II
Zegar: 50 MHz
18
Rysunek 5 Schemat modułu Data Path.
Rysunek 6 Schemat modułu FSM.
19
Rysunek 7 Wyniki kompilacji
20
3.2 Symulacja
Rysunek 8 Wyniki symulacji
Powodzenia !
21


Wyszukiwarka

Podobne podstrony:
ucyf lab6 09 title
ucyf lab7 09 przyklad
pref 09
amd102 io pl09
2002 09 Creating Virtual Worlds with Pov Ray and the Right Front End
Analiza?N Ocena dzialan na rzecz?zpieczenstwa energetycznego dostawy gazu listopad 09
2003 09 Genialne schematy
09 islam
GM Kalendarz 09 hum
06 11 09 (28)

więcej podobnych podstron