język vhdl, studia zaoczne ivr, wykład 1

63
VHDL Ernest Jamro, Paweł Russek C3 p. 504 [email protected] [email protected] www.fpga.agh.edu.pl

Upload: vuongtruc

Post on 11-Jan-2017

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL

Ernest Jamro, Paweł RussekC3 p. 504

[email protected]@agh.edu.pl

www.fpga.agh.edu.pl

Page 2: Język VHDL, Studia Zaoczne IVr, Wykład 1
Page 3: Język VHDL, Studia Zaoczne IVr, Wykład 1

Potrzeba narzędzia:

• 1970 - INTEL 4004 4 projektantów 1 tys. tranzystorów

• 1982 - INTEL 80286 20 projektantów 100 tys. tranzystorów

• 1992 - INTEL PENTIUM 100 projektantów 3 mln tranzystorów

• 2008 1000 projektantów 150 mln tranzystorów

• 200??? ???? projektantów ???? mln tranzystorów

Współczesne wymagania:hardware-software codesign !!!

Języki Opisu Sprzętu – po co?

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 4: Język VHDL, Studia Zaoczne IVr, Wykład 1

Języki Opisu Sprzętu – po co?

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 5: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – co to jest? Definicja

VHDL - VHSIC Hardware Description LanguageVery High Speed Integrated Circuit

It is "a formal notation intended for use in all phases of the creation of

electronic systems. ... it supports the development, verification, synthesis, and testing of hardware designs, the communication of hardware design

data ..."

[IEEE Standard VHDL Language Reference Manual]

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 6: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – jak, gdzie, kiedy? Zakres stosowania

Modelowanie

A=”01” ?A(1..0) Z

Z <= ’1’ when A = ”01” else ’0’;

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 7: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – jak, gdzie, kiedy? Zakres stosowania

Symulacja

A(1)

A(0)

Z

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 8: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – jak, gdzie, kiedy? Zakres stosowania

Synteza

(automatyczna) translacja opisu w języku HDL na strukturę w postacilisty połączeń elementarnych bloków funkcyjnych docelowej platformysprzętowej (bramek, przerzutników, pamięci i innych)

A(0)

A(1)Z

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 9: Język VHDL, Studia Zaoczne IVr, Wykład 1

entityname

architecturestyle of name

VHDL – jak, gdzie, kiedy? Jednostki projektowe

entity COMPARE is port (A,B: in bit;

C: out bit);end COMPARE;

architecture BEHAVIORAL of COMPARE is

begin C <=‘1’ when A=B else ‘0’;end behavioral;

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 10: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – przykłady Dekoder

entity DECODER is port(D: in bit_vector (0 downto 3); ZERO: out bit; ONE: out bit; EIGHT: out bit; NINE: out bit);end DECODER;

architecture FIRST of DECODER isbegin NINE <= '1' when D="1001" else '0'; EIGHT <= '1' when D="1000" else '0'; ONE <= '1' when D="0001" else '0'; ZERO <= '1' when D="0001" else '0';end FIRST;

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 11: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – przykłady Komparator

entity COMPARE is port(A,B: in bit_vector (0 to 7); EQL: out bit_vector (0 to 7));end COMPARE;

architecture SECOND of COMPARE isbegin EQL <= not (A xor B);end SECOND;

Gdzie na tym schemaciejest błąd?

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 12: Język VHDL, Studia Zaoczne IVr, Wykład 1

Multiplekser

In0

In1

Out

Sel

0

1

1100

SelwhenInSelwhenIn

OutMux 2:1

In0

Out

Sel

0 In1 In2 In3

1 2 3

3322

1100

SelwhenInSelwhenInSelwhenInSelwhenIn

Out Mux 4:1

Page 13: Język VHDL, Studia Zaoczne IVr, Wykład 1

Multiplekser 2:1 na bramkach

In0

In1

Out

Sel

0

1

Sel\In1, In0 00 01 11 10

0 0 1 1 0

1 0 0 1 1

Out= SelIn0 + Sel In1

Y <= (not Sel and In0) or (Sel and In1); --VHDL

In0

In1

Sel

Out

Page 14: Język VHDL, Studia Zaoczne IVr, Wykład 1

Multiplekser na bramkach – postać ogólna

In0

Out

Sel

In1

Inn

In0

In1

Sel

Out

Dekoder kodu binarnego na 1 z n

Inn

In0

In1

Sel1

Out

In2

In3

Sel0

Mux 4:1

VHDLSeli <= conv_integer(Sel);Y <= X(Seli); -- Out i In słowa kluczowe

Page 15: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – przykłady Multiplekser

entity MPLEXER is port(D: in std_logic_vector (7 downto 0); A: in std_logic_vector (2 downto 0); X: out std_logic);end MPLEXER;

architecture MYARCH of MPLEXER is signal Ai: integer range 7 downto 0;begin Ai <= conv_integer(A); X <= D(Ai);end MYARCH;

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 16: Język VHDL, Studia Zaoczne IVr, Wykład 1

Multiplekser na buforach trójstanowych

I n 0

I n 1

S e l

Y

D e k o d e r k o d u b i n a r n e g o n a 1 z n

I n n

I n

T

O u t

01

TwhenHiZTwhenIn

Out

In0

In1

Sel0

Sel1

Out

Możliwa równoczesny stan niskiej impedancji dla dwóch buforów trójstanowych wynikający z czasów propagacji

Aby uniknąć krótkotrwałego zwierania buforów stosuje się krótki czas martwy w którym wszystkie bufory są w stanie wysokiej impedancji. Wymaga to użycia automatu zamiast prostego dekodera kodu binarnego na 1 z n.

VHDL (wewnątrz FPGA):

Ch(1)<= In1 when Tn(1)=‘1’ else ‘Z’;

Ch(2)<= In2 when Tn(2)=‘1’ else ‘Z’;

VHDL (testbench):

Y<= ch(1);

Y<= ch(2);

Page 17: Język VHDL, Studia Zaoczne IVr, Wykład 1

Przykład: package STANDARD -- This is Package STANDARD as defined in the VHDL 1992 Language Reference Manual.package standard is

type boolean is (false,true); type bit is ('0', '1'); type character is (

nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb,

................

'đ', 'ń', 'ň', 'ó', 'ô', 'ő', 'ö', '÷','ř', 'ů', 'ú', 'ű', 'ü', 'ý', 'ţ', '˙' );

type severity_level is (note, warning, error, failure); type integer is range -2147483647 to 2147483647; type real is range -1.0E308 to 1.0E308; type time is range -2147483647 to 2147483647

units fs;ps = 1000 fs;ns = 1000 ps;us = 1000 ns; ms = 1000 us; sec = 1000 ms; min = 60 sec; hr = 60 min;

end units; subtype delay_length is time range 0 fs to time'high;impure function now return delay_length; subtype natural is integer range 0 to integer'high; subtype positive is integer range 1 to integer'high; type string is array (positive range <>) of character; type bit_vector is array (natural range <>) of bit; type file_open_kind is (

read_mode,write_mode,append_mode);

type file_open_status is (open_ok,status_error,name_error,mode_error);

attribute foreign : string;end standard;

Page 18: Język VHDL, Studia Zaoczne IVr, Wykład 1

Pojęcia leksykalne - literały

Literały pojedyncze (skalary)

character - pojedynczy znak objęty apostrofami, np: ‘A’ lub ‘a’bit - reprezentuje wartość binarną ‘1’ lub ‘0’

std_logic - reprezentuje wartość sygnałów wg. IEEE 1164:U niezainicjalizowanyX nieznany (forcing an unknown)0 silne zero (forcing 0)1 silne jeden (forcing 1)Z wysoka impedancjaW słaby nieznany (weak unknown)L słabe zero (weak 0)H słabe jeden (weak 1)- nieistotny (don’t care)

Poza pakietem STANDARD

Należy dodać przed entity:library IEEE;

use IEEE.STD_LOGIC_1164.all;E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 19: Język VHDL, Studia Zaoczne IVr, Wykład 1

Biblioteka std_logic.vhd

----------------------------------------------------------------- -- resolution function ----------------------------------------------------------------- CONSTANT resolution_table : stdlogic_table := ( -- --------------------------------------------------------- -- | U X 0 1 Z W L H - | | -- --------------------------------------------------------- ( 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U' ), -- | U | ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ), -- | X | ( 'U', 'X', '0', 'X', '0', '0', '0', '0', 'X' ), -- | 0 | ( 'U', 'X', 'X', '1', '1', '1', '1', '1', 'X' ), -- | 1 | ( 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', 'X' ), -- | Z | ( 'U', 'X', '0', '1', 'W', 'W', 'W', 'W', 'X' ), -- | W | ( 'U', 'X', '0', '1', 'L', 'W', 'L', 'W', 'X' ), -- | L | ( 'U', 'X', '0', '1', 'H', 'W', 'W', 'H', 'X' ), -- | H | ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ) -- | - | );

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 20: Język VHDL, Studia Zaoczne IVr, Wykład 1

Pojęcia leksykalne – wyrażenia

Operatory wyrażeń:

logiczne and or nand nor xor notrelacji = /= < <= > >=połączenia &arytmetyczne + - * / **

mod rem absVHDL’92 sll srl sla sra rol ror xnor

Typy argumentów:

takie same : and or nand nor xor not = /= < <= > >= + - * /

integer : mod reminteger exp : **numeryczny : abs

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 21: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – przykłady Sumator

library IEEE;use IEEE.STD_LOGIC_1164.all;use IEEE.STD_LOGIC_UNSIGNED.all;

entity SUM is port(A,B: in std_logic_vector (2 downto 0);

Cin: in std_logic; S: out std_logic_vector (2 downto 0);

Cout: out std_logic);end SUM;

architecture FOURTH of SUM is signal V: std_logic_vector (3 downto 0);begin V <= A + B + Cin; S <= V(2 downto 2); Cout <= V(3);end FOURTH;

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 22: Język VHDL, Studia Zaoczne IVr, Wykład 1

Process

Składnia:

[etykieta:]process [(lista sygnałów aktywujących)] [is] [podprogram][typ][stała][zmienna][inne deklaracje]begin instrukcje sekwencyjneend process [etykieta];

Instrukcja przypisania wartości dla zmiennychzmienna := wyrażenie;

Instrukcja przypisania wartości dla sygnałówsygnał <= wyrażenie [after delay];

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 23: Język VHDL, Studia Zaoczne IVr, Wykład 1

Process / brak process Powielanie logikientity loop_stmt isport (a: bit_vector (3 downto 0); m: out bit_vector (3 downto 0));end loop_stmt;

architecture example1 of loop_stmt is signal b: bit_vector(3 downto 0);begin b(0)<= a(0); label: for i in 1 to 3 generate b(i)<= b(i-1) and a(3-i); end generate; m<= b;end example1;

architecture example2 of loop_stmt isbeginprocess (a) variable b: bit; begin b := '1'; for i in 0 to 3 loop b := a(3-i) and b; m(i) <= b; end loop;end process;end example2;

Page 24: Język VHDL, Studia Zaoczne IVr, Wykład 1

Alternatywne rozwiązanie Multiplekser

Mux_out<= A when sel = "00" else

B when sel = "01" else

C when sel = "10" else '-';

LUB

with sel select

Mux_out <= A when "00",

B when "01",

C when "10",

'-' when others;

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 25: Język VHDL, Studia Zaoczne IVr, Wykład 1

Transkoder kodu hex na siedmiosegmentowy

with HEX select

LED<= "1111001" when "0001", --1

"0100100" when "0010", --2

"0110000" when "0011", --3

"0011001" when "0100", --4

"0010010" when "0101", --5

"0000010" when "0110", --6

"1111000" when "0111", --7

"0000000" when "1000", --8

"0010000" when "1001", --9

"0001000" when "1010", --A

"0000011" when "1011", --b

"1000110" when "1100", --C

"0100001" when "1101", --d

"0000110" when "1110", --E

"0001110" when "1111", --F

"1000000" when others; --0

A

B

C

D E

F

G

Page 26: Język VHDL, Studia Zaoczne IVr, Wykład 1

Przerzutnik typu Dprocess (CLK)begin

if (CLK'event and CLK='1') then if reset=‘1’ then -- reset synchroniczny

DOUT <= '0'; else DOUT <= DIN;

end if; end if;end process ;

process (CLK, RESET) begin

if RESET='1' then – reset asynchronicznyDOUT <= '0'; elsif (CLK'event and CLK='1') then

DOUT <= DIN; end if;

end process ;

Page 27: Język VHDL, Studia Zaoczne IVr, Wykład 1

Przerzutnik typu D z multiplekserem i Clock Enable (CE)

process (CLK)begin

if (CLK'event and CLK='1') then if ce= ‘1’ then

if sel=‘0’ then DOUT <= DIN0; else DOUT <= DIN1;

end if; -- sel end if; -- ce end if; -- clk

end process;

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 28: Język VHDL, Studia Zaoczne IVr, Wykład 1

sensivity listPytanie:

Jaka jest różnica w zachowaniu się dwóch poniższych procesów ?

Odpowiedź:

Lewy: Symulacja jednokrotna.Użycie poprzednich wartości S i T dla obliczenia wartości V.

Prawy: Symulacja dwukrotna.Uaktualni wartości S i T dla obliczenia wartości V w dwóchcyklach delta.

process (A, B)– częsty błądbeginS <= A;T <= B;V <= S or T;end process;

process (A, B, S, T)beginS <= A;T <= B;V <= S or T;end process;

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 29: Język VHDL, Studia Zaoczne IVr, Wykład 1

SIPO (Serial-In Parallel-Out)(Deserializer)

process(clk) begin

if clk'event and clk=‘1' then

Q(N-1 downto 0)<= Q(N-2 downto 0) & Din;

end if;

end process;

D Q C

D Q C

D Q C

Clk

Din Q1 Q2 Q3

Page 30: Język VHDL, Studia Zaoczne IVr, Wykład 1

Parallel-In Serial-Out (PISO) – Serializer

D Q Clk

D Q Clk

D1

Clk

0 1

D Q Clk

D2

Clk

0 1

D Q Clk

D3

Clk

0 1

Load

D0

Clk

Q3/Qout

Q0

Q1

Q2

0 1

Din

D0/Din

Clk

D1

D2

D3

Load

Q3 D3(t=0)

0 1 2 3 4 5

D2(t=0) D1(t=0) D0(t=0) Din(t=1) D3(t=5)

Din

Q0 D0(t=0) Din(t=1) Din(t=2) Din(t=3) Din(t=4) D0(t=5)

Q1 D1(t=0) D0(t=0) Din(t=1) Din(t=2) Din(t=3) D1(t=5)

Q2 D2(t=0) D1(t=0) D0(t=0) Din(t=1) Din(t=2) D2(t=5)

Page 31: Język VHDL, Studia Zaoczne IVr, Wykład 1

PISO - VHDL

D Q Clk

D Q Clk

D1

Clk

0 1

D Q Clk

D2

Clk

0 1

D Q Clk

D3

Clk

0 1

Load

D0

Clk

Q3/Qout

Q0

Q1

Q2

0 1

Din

process(clk) begin

if clk'event and clk1=‘1' then

if load=‘1’ then

Q <= D;

else

Q(N-1 downto 0)<= Q(N-2 downto 0) & Din;

end if;

end if;

end process;

Qout<= Q(N-1);

Page 32: Język VHDL, Studia Zaoczne IVr, Wykład 1

Przesyłanie danych szeregowoSerDeser

PISO

Clk

SIPO

Dclktakt

Sposób 1

Sposób 2

In0

Sel

In1

Inn

Mux

Licznik modulo n

Out0

Dserial Out1

Outn Sel

Licznik modulo n

Rejestr

Clk

D Mux

In0

Sel

In1

Inn

Mux

mod n counter

Dserial

mod n one hot counter Clk

D CE

D CE

D CE

Page 33: Język VHDL, Studia Zaoczne IVr, Wykład 1

Incrementator (S=A+1)

HA Half Adder

a0

HA Half Adder

HA Half Adder

HA Half Adder

a1 a2 a3

s0

c0

s1

c2

s2

c3

s3

1

s4

ci-1\ai 0 1

0 0 1

1 1 0

ci-1\ai 0 1

0 0 0

1 0 1

Si Ci

si = ai ci-1

ci= ai ci-1

HAHalf Adder

Page 34: Język VHDL, Studia Zaoczne IVr, Wykład 1

Incrementator: Example

HA Half Adder

a0

HA Half Adder

HA Half Adder

HA Half Adder

a1 a2 a3

s0

c0

s1

c2

s2

c3

s3

1

s4

1

1

1

1 0

0 0 1

0 1

1 0

A=10112= 1110=0xB

S=A+1= 11002=1210=0xC

Page 35: Język VHDL, Studia Zaoczne IVr, Wykład 1

Dodawanie z szeregową propagacją przeniesienia(Ripple Carry) Adder: S= A+B

HA Half Adder

a0 b0

FA Full Adder

FA Full Adder

FA Full Adder

a1 b1 a2 b2 a3 b3

s0

c0

s1

c1

s2

c2

s3

ci-1\ai,bi 00 01 11 10

0 0 1 0 1

1 1 0 1 0

ci-1\ai,bi 00 01 11 10

0 0 0 1 0

1 0 1 1 1

si

ci

ai + bi+ci-1 = si + 2·ci

si = ai bi ci-1

ci= ai bi + ai ci-1 + bi ci-1= ai bi + ci-1 (ai bi)

011

iii

iiii baifa

baifcc

Propagate

Generate

Page 36: Język VHDL, Studia Zaoczne IVr, Wykład 1

Odejmowanie / Subtraction (a-b)

ci-1\ai,bi 00 01 11 10

0 0 1 0 1

1 1 0 1 0

ci-1\ai,bi 00 01 11 10

0 0 1 0 0

1 1 1 1 0

si

ci

ai - bi-ci-1 = si - 2·ci

si = ai bi ci-1

Red color – difference between addition and subtraction

iiiiiii bcacbac 11

Two’s Complement (2C)

1221

0

N

ii

iN

N bbbb

Sign bit negation

DirectAdd 1 to the

LSB

(Least Significant Bit)

Instead of employing dedicated subtraction we can use a standard adder convert B to 2C code

Example: 1111 in 2C=

0000+1= 0001 (minus one)

Page 37: Język VHDL, Studia Zaoczne IVr, Wykład 1

Add/Subtract Logic

FA Full Adder

a0 b0

FA Full Adder

FA Full Adder

FA Full Adder

a1 b1 a2 b2 a3 b3

s0

c0

s1

c1

s2

c2

s3

Sub

10

SubwhenBASubwhenBA

S

Convert B to Two’s Complement when Sub=1

1

0

SelwhenA

SelwhenASelxorAY

S<= A+B when Sub=‘0’ else A-B;

Page 38: Język VHDL, Studia Zaoczne IVr, Wykład 1

Counter mod 2N

HA Half Adder

Q3

1

D Q C

HA Half Adder

Q2 D Q C

HA Half Adder

Q1 D Q C

HA Half Adder

Q0 D Q C

Clk

Increamentator

Registers

Qn+1= Qn+1

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity counter_2N is

port(clk, reset_asynch: in std_logic;

count : out std_logic_vector (3 downto 0));

end counter_2N;

architecture Beh of counter_2N is

signal Q: std_logic_vector(3 downto 0):= "0000";

begin

process(clk, reset_asynch) begin

if reset_asynch=‘1’ then

Q<= (others=>’0’);

elsif clk’event and clk=‘1’ then

Q<= Q + 1;

end if;

end process;

Count<= Q

end Beh;

Page 39: Język VHDL, Studia Zaoczne IVr, Wykład 1

Counter mod N

D Q Reset C

Clk

+1

=N-1

11

1_10NQwhenQ

synchresetorNQwhenD

architecture Beh of counter_N is

signal Q: std_logic_vector(3 downto 0):= "0000";

begin

process(clk) begin

if clk’event and clk=‘1’ then

if reset_synch=‘1’ or Q=N-1 then

Q<= (others=>’0’);

else

Q<= Q + 1;

end if; -- not reset

end if; -- clk

end process;

end Beh;

Page 40: Język VHDL, Studia Zaoczne IVr, Wykład 1

Up/Down Counter mod 2N

D Q C

Clk

+/-1 Up/DownN

1101

UpwhenQUpwhenQ

D

architecture Beh of counter_up_down is

signal Q: std_logic_vector(3 downto 0);

begin

process(clk) begin

if clk’event and clk=‘1’ then

if Up_DownN=‘1’ then

Q<= Q + 1;

else

Q<= Q - 1;

end if; -- up / downN

end if; -- clk

end process;

Count <= Q;

end Beh;

Page 41: Język VHDL, Studia Zaoczne IVr, Wykład 1

Up/Down Counter mod N

D Q Load C

Clk

+/-1

Comp =N-1 or =0

U/DN

N-1 0

001111

001110

UpandQwhenQUpandNQwhenQ

UpandQwhenNUpandNQwhen

D

process(clk) begin

if clk’event and clk=‘1’ then

if Up_DownN=‘1’ then

if Q = N-1 then

Q<= (others=>’0’)

else

Q<= Q + 1;

end if;

else -- counting down

if Q = 0 then

Q<= conv_std_logic_vector(N-1, vec_width);

else

Q<= Q - 1;

end if;

end if; -- up / downN

end if; -- clk

end process;

Page 42: Język VHDL, Studia Zaoczne IVr, Wykład 1

Rejestr przesuwny w prawo i w lewo z wpisem równoległym

D Q Clk Clk

D Q Clk Clk

D Q Clk Clk

D Q Clk Clk

0 1 23

Q2 Q1 Q0/QRIGHT Q3/QLEFT

DLEFT

S

DRIGHT

0 1 23 0 1 23 0 1 23

D3 D2 D1 D0

S= 0 - przesuń w prawo

S=1 - przesuń w lewo

S=2 - wpis równoległy

S=3 - wpis równoległy

process(clk) begin

if clk’event and clk=‘1’ then

if S(1)= ‘1’ then -- load

Q<= D;

elsif S(0)= ‘0’ then – shift right

Q<= Dleft & Q(3 downto 1);

else -- shift left

Q<= Q(2 downto 0) & Drigth;

end if; end if; end process;

Page 43: Język VHDL, Studia Zaoczne IVr, Wykład 1

Automat Moore’a--Insert the following in the architecture before the begin keyword

--Use descriptive names for the states, like st1_reset, st2_search

type state_type is (st1_<name_state>, st2_<name_state>, ...);

signal state, next_state : state_type;

--Declare internal signals for all outputs of the state-machine

signal <output>_i : std_logic; -- example output signal

--other outputs

--Insert the following in the architecture after the begin keyword

SYNC_PROC: process (<clock>)

begin

if (<clock>'event and <clock> = '1') then

if (<reset> = '1') then

state <= st1_<name_state>;

<output> <= '0';

else

state <= next_state;

<output> <= <output>_i;

-- assign other outputs to internal signals

end if;

end if;

end process;

Page 44: Język VHDL, Studia Zaoczne IVr, Wykład 1

Automat Mealy’egoMEALY State-Machine - Outputs based on state and inputs

OUTPUT_DECODE: process (state, <input1>, <input2>, ...)

begin

--insert statements to decode internal output signals

--below is simple example

if (state = st3_<name> and <input1> = '1') then

<output>_i <= '1';

else

<output>_i <= '0';

end if;

end process;

NEXT_STATE_DECODE: process (state, <input1>, <input2>, ...)

begin

--declare default state for next_state to avoid latches

next_state <= state; --default is to stay in current state

--insert statements to decode next_state

--below is a simple example

case (state) is

when st1_<name> =>

if <input_1> = '1' then

next_state <= st2_<name>;

end if;

when st2_<name> =>

if <input_2> = '1' then

next_state <= st3_<name>;

end if;

when st3_<name> =>

next_state <= st1_<name>;

when others =>

next_state <= st1_<name>;

end case;

end process;

Page 45: Język VHDL, Studia Zaoczne IVr, Wykład 1

Styl projektowania

Modelowa struktura projektu:• Jeden sygnał zegarowy• Wszystkie przerzutniki wyzwalane tym samym zboczem

Problemy przy dwóch aktywnych zboczach:• Zależność od współczynnika wypełnienia (tolerancja na

zmiany duty cycle w dokumentacji projektu!)• Problemy z metodą testowania typu ścieżka brzegowa

(JTAG 1149)

CLK

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 46: Język VHDL, Studia Zaoczne IVr, Wykład 1

Styl projektowania

Asynchroniczne kluczowanie zegara - same problemy! (niewykorzystanie zasobów dystrybucji sygnałów zegarowych,problemy z testowaniem, gorsze parametry czasowe itp.)

Rozwiązanie – stosowanie wejść CE – kodowanie przez warunek: if ce=‘1’ po sekwencji if clk’event and clk=‘1’.

CLK

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 47: Język VHDL, Studia Zaoczne IVr, Wykład 1

Styl projektowania

CLK

Nie należy stosować wewnętrznie (asynchronicznie!) generowanychsygnałów zegarowych.

Należy natomiast projektować układy synchroniczne lub używaćkilku sygnałów zegarowych (patrz: DLL).

CLK

CE

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 48: Język VHDL, Studia Zaoczne IVr, Wykład 1

Deklaracja sygnałów w entity

W deklaracji sygnału jako portu dla entity należy wyszczególnić: nazwę sygnału, jego kierunek, typ i opcjonalnie jego wartość początkową.

Składnia:

port (names: direction type [:= expression] [; more_ports]);

Przykład:

port (DATA_IN: in bit:= ‘0’;

DATA_OUT: out bit);port (B, A: in std_logic_vector);

Kierunek sygnału

Użycie in Prawa strona przypisania wartości zmiennej lub sygnałowi out Lewa strona przypisania wartości sygnałowi inout Obydwa powyższe buffer Sygnał wyjściowy (ale wykorzystywany wewnątrz entity)

Page 49: Język VHDL, Studia Zaoczne IVr, Wykład 1

Deklaracja sygnałów w VHDL

Pytanie: Jaki jest najprawdopodobniej kierunek sygnału DATA_OUT ?

Odpowiedź: buffer

Ze względu na to że buffer propaguje do nadrzędnych modułów nie zaleca się go używać. Lepiej jest użyć wewnętrznego dodatkowego sygnału.

MUX logikaDATA_IN

SELECT

DATA_OUT

Page 50: Język VHDL, Studia Zaoczne IVr, Wykład 1

Generic

library IEEE;use IEEE.STD_LOGIC_1164.all;

entity MY_ADDER

generic (width: integer; operacja: integer);

port ( a, b: in std_logic_vector(width-1 downto 0);

s: out std_logic_vector(width-1 downto 0));

end MY_ADDER;

architecture arch of MY_ADDER is

gplus: if operacja = 0 generate

s<= a + b;

end generate;

gminus: if operacja=1 generate

s<= a-b;

end generate;

end arch;

Page 51: Język VHDL, Studia Zaoczne IVr, Wykład 1

Dodawanie biblioteklibrary ieee;

use ieee.std_logic_1164.all; -- użycie std_logic

use ieee.std_logic_unsigned.all; -- każda wartość std_logic_vector jest traktowana jako integer bez znaku

use ieee.std_logic_signed.all; -- każda wartość std_logic_vector jest traktowana jako integer ze znaku

Nie można równocześnie użyć obu bibliotek: std_logic_unsigned oraz std_logic_signed. W tym wypadku należy użyć biblioteki:

use ieee.std_logic_arith.all;

oraz zamiast słowa kluczowego std_logic_vector należy użyć słów

unsigned lub signed (wada: konieczność używania konwersji std_logic_vector unsigned (lub signed))

Page 52: Język VHDL, Studia Zaoczne IVr, Wykład 1

Umiejscawianie komponentów

entity FULL_ADDER is

port

( a, b, cin: in std_logic;

s, cout: out std_logic);

end FULL_ADDER;

architecture arch of FULL_ADDER is

begin

s<= a xor b xor c;

cout<= a when a=b else cin;

end arch;

entity MY_ADDER is

generic (width: integer);

port ( a, b: in std_logic_vector(width-1 downto 0);

s: out std_logic_vector(width-1downto 0);

end MY_ADDER;

architecture arch of MY_ADDER is

component FULL_ADDER -- deklaracja komponentu

port ( a, b, cin: in std_logic;

s, cout: out std_logic);

end component;

signal carry: std_logic_vector(0 to dwidth);

begin

carry(0)<= ‘0’;

gi: for i in 0 to width-1 generate

fa: full_adder

Port map (a=> a(i), b=>b(i), cin=> carry(i), s=> s(i), cout=> carry(i+1));

end generate;

end arch;

Page 53: Język VHDL, Studia Zaoczne IVr, Wykład 1

Przykład pamięci ROM w VHDLlibrary ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity rom is

port ( ADDR : in std_logic_vector(5 downto 0);

DATA : out std_logic_vector(19 downto 0));

end rom;

architecture syn of rom is

type rom_type is array (63 downto 0) of std_logic_vector (19 downto 0);

signal ROM : rom_type:=

(X"0200A", X"00300", X"08101", X"04000", X"08601", X"0233A",

X"00300", X"08602", X"02310", X"0203B", X"08300", X"04002",

X"08201", X"00500", X"04001", X"02500", X"00340", X"00241",

X"04002", X"08300", X"08201", X"00500", X"08101", X"00602",

X"04003", X"0241E", X"00301", X"00102", X"02122", X"02021",

X"00301", X"00102", X"02222", X"04001", X"00342", X"0232B",

X"00900", X"00302", X"00102", X"04002", X"00900", X"08201",

X"02023", X"00303", X"02433", X"00301", X"04004", X"00301",

X"00102", X"02137", X"02036", X"00301", X"00102", X"02237",

X"04004", X"00304", X"04040", X"02500", X"02500", X"02500",

X"0030D", X"02341", X"08201", X"0400D");

begin

data <= ROM(conv_integer(ADDR));

end syn;

Page 54: Język VHDL, Studia Zaoczne IVr, Wykład 1

RAM: Synch. zapis / asynch. odczytprocess (<clock>)

begin

if (<clock>'event and <clock> = '1') then

if (<write_enable> = '1') then

<ram_name>(conv_integer(<address>)) <= <input_data>;

end if;

end if;

end process;

<ram_output> <= <ram_name>(conv_integer(<address>));

Page 55: Język VHDL, Studia Zaoczne IVr, Wykład 1

First-In First-Out (FIFO)Wejście: A, B, - ,C, - , D, E

Wyjście: - , A, - , B, - , - , C, - , D , Eempty

full

In

Out Mux

Up/Down Counter

Shift register LUT SRL

D Q clk

Pamięć dwuportowa

Licznik wyjściowy

Licznik wejściowy

We Wy

adrA

adrB

DaneA DaneB

Page 56: Język VHDL, Studia Zaoczne IVr, Wykład 1

TESTBENCH – połączenie Process/Component

Rodzaje procesów testujących• Ad Hoc

Zbiór wektorów testowych do podstawowych testów funkcjonalnych.• Algorytmiczny

Prosty algorytm generujący wymuszenia, np. pętla zwiększająca zmienną przez cały jej zakres do testowania dekodera lub ALU.

• Plik wektorówRozwiązanie strukturalne: proces czytający plik z wektorami do testowania.

Process Component

Signals UUTTestBench

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 57: Język VHDL, Studia Zaoczne IVr, Wykład 1

Przykład symulacjientity my_adder_tb is

end my_adder_tb;

Architecture sim of my_adder_tb is

component my_adder ........ end component;

constant width: integer:= 4;

signal a, b, s: std_logic_vector(width-1 downto 0):= (others=>’0’); -- to działa tylko dla symulacji

signal error: bit; -- sygnalizuje błąd podczas obliczeń

begin

UUT: my_adder -- testowany moduł

port map(a=> a, b=>b, s=>s);

wymus: process begin -- generacja wszystkich możliwych wektorów wejściowych a, b

wait for 10ns;

a<= a + 1;

if a="1111” then b<= b+1; end if;

end process;

error<= ‘1’ when a+b/=s else ‘0’;

end sim;

Page 58: Język VHDL, Studia Zaoczne IVr, Wykład 1

Metody wymuszania stanów sygnałówprocess begin

wait for 5ns;

clk<= not clk;

end process;

CE<= ‘1’;

first<= '0', '1' after 201ns, '0' after 211ns;

process begin

a<= ‘0’; b<= ‘0’;

wait for 10ns;

a<= ‘1’;

wait for 50ns;

a<=‘0’; b<= ‘1’;

wait; -- czekaj w nieskończoność

end process;

Page 59: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – literatura

„A Guide to VHDL”, S. Mazor, P. Langstraat„VHDL Analysis and Modelling of Digital Systems”, Z. Navabi„VHDL Hardware Description and Design”,

R. Lipsett, C. Schaefer, C. Ussery„The VHDL Cookbook”, P. J. Ashenden„VHDL programming: with advanced topics”, L. Baker„VHDL starter's guide”, S. Yalamanchili „VHDL for designers”, S. Sjoholm, L. Lindh„VHDL made easy!”, D. Pellerin, D. Taylor„VHDL answers to frequently asked questions”, B. Cohen„VHDL and AHDL digital systems implementation”, F. A. Scarpino„VHDL: język opisu i projektowania układów cyfrowych”, W. Wrona„Active-VHDL Series BOOK#2 – EVITA Interactive Tutorial”,

J. Mirkowski, M. Kapustka, Z. Skowroński, A. Biniszkiewicz„VHDL: a logic synthesis approach”, D. Naylor, S. Jones

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 60: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – literatura

Marek Zwoliński Włodzimierz Wrona

Kevin Skahill Józef Kalisz

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 61: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – zasoby w Internecie

• http://fpga.elektro.agh.edu.pl• VHDL: http://www.vhdl.org/• Grupa dyskusyjna: comp.lang.vhdl (FAQ - 4części)• Accellera: http://www.accellera.org/• EDA Industry Working Groups homepage: http://www.eda.org/• FPGA Journal http://www.fpgajournal.com/ - (ładne lekcje ChalkTalk )• Design Automation Cafe: http://www.dacafe.com/• Doulos High Level Design Web site: http://www.doulos.com/• VHDL-online, University of Erlangen-Nürnberg: http://www.vhdl-online.de/• VHDL info pages of the Microelectronics Department (University of Ulm,

Germany): http://mikro.e-technik.uni-ulm.de/vhdl/vhdl_infos.html

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 62: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – tutoriale

• Evita Interactive VHDL Tutorial from Aldec, Inc.: • http://www.aldec.com • Doulos High Level Design Web site; A Hardware Engineers Guide to VHDL: http://www.doulos

.com/hegv/index.htm• An Introductory VHDL Tutorial, Green Mountain Computing Systems: http://www.gmvhdl.com

/VHDL.html• VHDL Tutorial by Ulrich Heinkel, Thomas Bürner and Martin Padeffke (in English and

German): http://www.vhdl-online.de/~vhdl/TUTORIAL/• VHDL-FSM-Tutorial by Martin Padeffke: http://www.vhdl-online.de/FSM/• VHDL Verification Course by Stefan Doll: http://www.stefanVHDL.com/

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

Page 63: Język VHDL, Studia Zaoczne IVr, Wykład 1

VHDL – free IP cores

• OpenIP home page: http://www.opencores.org • System On Chip http://www.soccentral.com/

• Free behavioral models from Alatek: http://www.alatek.com/• The Hamburg VHDL archive:

http://tams-www.informatik.uni-hamburg.de/research/vlsi/vhdl/• Rapid Prototyping of Application Specific Signal Processors (RASSP)

www site: http://www.eda.org/rassp/ • Doulos High Level Design Web site; Monthly-updated Original Models (developed

by Doulos): http://www.doulos.com/fi/ • A VHDL synthesizable model for the MICROCHIP PIC 16C5X microcontroller by

Tom Coonan: http://www.mindspring.com/~tcoonan/ • VHDL Library of Arithmetic Units developed by R. Zimmermann: http://www.iis.ee.

ethz.ch/~zimmi/arith_lib.html

E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków