ucsw1 vhdl

ucsw1 vhdl
JS UCiSW 1
JS UCiSW 1
Literatura
Układy Cyfrowe i Systemy Wbudowane 1
• Język VHDL: M. Zwoliński(…) / K. Skahill(…) / IEEE Standard 1076
(PWr!)
• Architektury układów PLD, CPLD: www…; www.xilinx.com
• J. Kalisz „Podstawy elektroniki cyfrowej”, WKiŁ
Język VHDL
• C. Zieliński „Podstawy projektowania układów cyfrowych”, PWN
• J. Baranowski, B. Kalinowski, Z. Nosal „Układy elektroniczne. Cz. 3:
Układy i systemy cyfrowe”, WNT 1994
dr inż. Jarosław Sugier
[email protected]
IIAR, pok. 227 C-3
• J. Pasierbiński, P. Zbysiński „Układy programowalne w praktyce”, WKiŁ
• T. Łuba (red.) „Synteza układów cyfrowych”, WKiŁ
• Pong P. Chu „RTL hardware design using VHDL”, J. Wiley
Jednostki i architektury
1
2
JS UCiSW 1
JS UCiSW 1
architecture Behavioral of HalfAdder is
begin
library UNISIM;
use UNISIM.VComponents.all;
process( A, B )
begin
-- Sum
if A /= B then
S <= '1';
else
S <= '0';
end if;
-- Carry
if A = '1' and B = '1' then
C <= '1';
else
C <= '0';
end if;
end process;
entity HalfAdder is
port ( A : in STD_LOGIC;
B : in STD_LOGIC;
S : out STD_LOGIC;
C : out STD_LOGIC);
end entity HalfAdder;
architecture Structural of HalfAdder is
begin
XOR_gate : XOR2 port map ( A, B, S );
AND_gate : AND2 port map ( A, B, C );
end architecture Structural;
architecture Dataflow of HalfAdder is
begin
S <= A xor B;
C <= A and B;
end architecture Dataflow;
end architecture Behavioral;
3
Porty i sygnały: tryby pracy portów
JS UCiSW 1
Synteza:
1)
in – READ ONLY
2)
out – WRITE ONLY
3)
inout – bidirectional (3-state buffers, etc.)
4)
buffer – „out with read capability”
!!
4
Porty i sygnały: sygnały wewnętrzne
entity AndNand is
port ( A : in
B : in
C : in
WY_And
WY_Nand
end AndNand;
JS UCiSW 1
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
: out STD_LOGIC;
: out STD_LOGIC);
architecture DataflowBad of AndNand is
begin
WY_And <= A and B and C;
WY_Nand <= not WY_And;
end DataflowBad;
Compilation:
HDLParsers:1401 - Object WY_And of mode OUT can not be read.
architecture DataflowOK of AndNand is
signal Int_And : STD_LOGIC;
begin
Int_And <= A and B and C;
WY_And <= Int_And;
WY_Nand <= not Int_And;
end DataflowOK;
5
6
1
JS UCiSW 1
Wektory i napisy bitowe
Standardowy typ z biblioteki STD_LOGIC_1164:
type STD_LOGIC_VECTOR is array (NATURAL range <>)
of STD_LOGIC;
Użycie:
(...)
signal DataBus : STD_LOGIC_VECTOR( 7 downto 0);
(...)
DataBus
DataBus
DataBus
DataBus
DataBus
DataBus
<=
<=
<=
<=
<=
<=
JS UCiSW 1
Operator ‘&’
signal ASCII : STD_LOGIC_VECTOR( 7 downto 0 );
signal Digit : STD_LOGIC_VECTOR( 3 downto 0 );
(...)
ASCII <= "0011" & Digit;
-- X"3" & Digit;
ASCII <= X"3" & Digit ( 3 ) & Digit ( 2 ) &
Digit ( 1 ) & Digit ( 0 );
"10000000";
B"1000_0000";
X"80";
( '1', '0', '0', '0', '0', '0', '0', '0' );
( '1', others => '0' );
( 7 => '1', others => '0' );
(...)
-- These must be synchronous:
-...shift right
ASCII <= '0' & ASCII( 7 downto 1 );
-...arithmetic shift right:
ASCII <= ASCII( 7 ) & ASCII( 7 downto 1 );
DataBus <= ( others => '0' );
HalfByte <= DataBus( 7 downto 4 );
-...rotate left:
ASCII <= ASCII( 6 downto 0 ) & ASCII( 7 );
MSB <= DataBus( 7 );
7
JS UCiSW 1
Klauzula generic
8
JS UCiSW 1
Przypisanie sygnału
y <= x;
y <= ( x1 and x2 ) or ( ( x3 nand x4 ) xor x5 );
entity identifier is
generic ( parameter_declarations ); -- optional
port ( port_declarations );
-- optional
[ declarations ]
-- optional
begin
\__ optional
[ statements ]
/
end entity identifier ;
x;
<2>
5 y <= inertial x after 4 ns;
y <= transport x after 4 ns;
entity Buf is
generic ( N : POSITIVE := 8;
-- data width
Delay : DELAY_LENGTH := 2.5 ns );
port ( Input : in STD_LOGIC_VECTOR( N-1 downto 0 );
OE
: in STD_LOGIC;
Output : out STD_LOGIC_VECTOR( N-1 downto 0 ) );
end entity Buf;
-- Domyślnie:
y <= x;
y <= x after 4 ns;
<=>
<=>
y <= inertial x after 0 ns;
y <= inertial x after 4 ns;
-- Wielokrotna zmiana w reakcji na pojedyńczą
-- zmianę sygnału:
y <= x after 4 ns, not x after 8 ns;
-- W opisach sekwencyjnych (np. powtarzanych w pętlach):
Clk <= '1', '0' after ClkPeriod / 2;
Przypisanie warunkowe when...else
9
10
JS UCiSW 1
JS UCiSW 1
entity MUX_4 is
port( A, B, C, D : in STD_LOGIC;
Sel : in STD_LOGIC_VECTOR( 1 downto 0 );
Y : out STD_LOGIC );
end MUX_4;
architecture Dataflow of MUX_4 is
begin
Y <= A when Sel = "00" else
B when Sel = "01" else
C when Sel = "10" else
... lub ...
D;
D when Sel = "11" else
'X';
end Dataflow;
•
UWAGA!
Y <= ‘1’ when A = ‘1’ and B = ‘1’ else
‘0’ when A = ‘0’ and B = ‘0’;
???
WARNING:Xst:737 - Found 1-bit latch for signal <Y>. Latches may be generated
from incomplete case or if statements. We do not recommend the use of
latches in FPGA/CPLD designs, as they may lead to timing problems.
11
Przypisanie selektywne with ... select
entity MUX_4 is
port( A, B, C, D : in STD_LOGIC;
Sel : in STD_LOGIC_VECTOR( 1 downto 0 );
Y : out STD_LOGIC );
end MUX_4;
architecture Dataflow2 of MUX_4 is
begin
with Sel select
Y <= A when "00",
B when "01",
C when "10",
D when others;
end Dataflow2;
12
2
JS UCiSW 1
Instancje komponentów
entity XOR_2WE is
generic( Tp : DELAY_LENGTH );
port ( I1, I2 : in STD_LOGIC;
O : out STD_LOGIC);
end XOR_2WE;
architecture A of XOR_2WE is
begin
O <= I1 xor I2 after Tp;
end A;
component FD_1
port ( C : in
D : in
Q : out
end component;
Np.: Plik vhf na podstawie sch (ISE)
entity AND_2WE is
generic( Tp : DELAY_LENGTH );
port (I1, I2 : in STD_LOGIC;
O : out STD_LOGIC);
end AND_2WE;
architecture A of AND_2WE is
begin
O <= I1 and I2 after Tp;
end A;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library UNISIM;
use UNISIM.Vcomponents.all;
entity CntAsync
port ( CE :
Clk :
Q0 :
Q1 :
Q2 :
end CntAsync;
entity HalfAdder is
(...)
architecture Structural of HalfAdder is
component XOR_2WE is
generic( Tp : DELAY_LENGTH );
port ( I1, I2 : in STD_LOGIC; O : out STD_LOGIC);
end component;
component AND_2WE is
generic( Tp : DELAY_LENGTH );
port ( I1, I2 : in STD_LOGIC; O : out STD_LOGIC);
end component;
begin
XOR_gate : XOR_2WE generic map( 5 ns ) port map( A, B, S );
AND_gate : AND_2WE generic map( Tp => 3 ns )
port map( O=>C, I1=>A, I2=>B );
end architecture Structural;
is
in
in
out
out
out
XLXI_1 : FDE
port map (C=>Clk,
CE=>CE,
D=>XLXN_1,
Q=>Q0_DUMMY);
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC);
XLXN_1
XLXN_2
XLXN_3
Q0_DUMMY
Q1_DUMMY
Q2_DUMMY
:
:
:
:
:
:
XLXI_2 : INV
port map (I=>Q0_DUMMY,
O=>XLXN_1);
component INV
port ( I : in
O : out
end component;
component FDE
port ( C :
CE :
D :
Q :
end component;
in
in
in
out
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
XLXI_3 : FD_1
port map (C=>Q0_DUMMY,
D=>XLXN_2,
Q=>Q1_DUMMY);
XLXI_4 : INV
port map (I=>Q1_DUMMY,
O=>XLXN_2);
STD_LOGIC;
STD_LOGIC);
XLXI_5 : FD_1
port map (C=>Q1_DUMMY,
D=>XLXN_3,
Q=>Q2_DUMMY);
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC);
13
Instrukcja generacji
begin
Q0 <= Q0_DUMMY;
Q1 <= Q1_DUMMY;
Q2 <= Q2_DUMMY;
architecture BEHAVIORAL of CntAsync is
signal
signal
signal
signal
signal
signal
JS UCiSW 1
STD_LOGIC;
STD_LOGIC;
STD_LOGIC);
XLXI_6 : INV
port map (I=>Q2_DUMMY,
O=>XLXN_3);
end BEHAVIORAL;
JS UCiSW 1
14
JS UCiSW 1
a) for … generate
b) if … generate
entity FullAdder is
port ( A, B : in STD_LOGIC_VECTOR( 7 downto 0 );
CI
: in STD_LOGIC;
S
: out STD_LOGIC_VECTOR( 7 downto 0 );
CO
: out STD_LOGIC);
end FullAdder;
architecture Dataflow of FullAdder is
signal Cint : STD_LOGIC_VECTOR( 8 downto 0 );
begin
lb: for i in 0 to 7 generate
S(i) <= A(i) xor B(i) xor Cint(i);
Cint(i + 1) <= ( A(i) and B(i) ) or
( A(i) and Cint(i) ) or ( B(i) and Cint(i) );
end generate;
label: if condition generate
-- label required
block_declarative_items \__ optional
begin
/
concurrent_statements
end generate label;
Cint( 0 ) <= CI;
CO <= Cint( 8 );
end Dataflow;
15
JS UCiSW 1
Instrukcja procesu
[label:] process [ ( sensitivity_list ) ] [ is ]
[ declarative_items ]
begin
sequential_statements
end process [ label ];
JS UCiSW 1
Instrukcje sekwencyjne
Instrukcja wait:
wait
wait
wait
wait
Np. było:
process( A, B ) is
begin
if A /= B then
S <= '1';
else
S <= '0';
end if;
if A = '1' and B = '1' then
C <= '1';
else
C <= '0';
end if;
end process;
16
for 10 ns;
-until clk = '1';
-until A > B and ( S1 or S2
on sig1, sig2;
--
timeout
warunek logiczny
);
lista wrażliwości
wait until ... – czeka na zdarzenie, tj. zmianę sygnału (zawsze
wstrzyma wykonanie procesu!); jeśli nie o to chodzi
to trzeba np. dodać warunek:
if Busy /= ’0’ then
wait until Busy = ’0’;
end if;
17
18
3
condition1 then
statements
elsif condition2 then
statements
...
else
statements
end if [ label ] ;
JS UCiSW 1
[ label: ] if
architecture DF of MUX_4
begin
Y <= A when Sel = "00"
B when Sel = "01"
C when Sel = "10"
D when Sel = "11"
'X';
end DF;
is
else
else
else
else
JS UCiSW 1
[ label: ] case expression is
when choice1 =>
statements
when choice2 => \_ opt.
statements
/
...
when others =>
\_ opt. if all choices
statements
/ covered
end case [ label ] ;
\_ optional
/
\_ optional
/
architecture DF_Eq of MUX_4 is
begin
process ( Sel, A, B, C, D )
begin
if Sel = "00" then
Y <= A;
elsif Sel = "01" then
Y <= B;
elsif Sel = "10" then
Y <= C;
elsif Sel = "11" then
Y <= D;
else
Y <= 'X';
end if;
end process;
end DF_Eq;
architecture DF2 of MUX is
begin
with Sel select
Y <= A when "00",
B when "01",
C when "10",
D when "11",
'X'when others;
end DF2;
19
JS UCiSW 1
[ label: ] loop
statements
-- use exit to abort
end loop [ label ] ;
[ label: ] for variable in range loop
statements
end loop [ label ] ;
[ label: ] while
condition loop
statements
end loop [ label ] ;
next;
next outer_loop; -- label of loop instr.
next when A > B;
next this_loop when C = D or A > B;
architecture DF2_Eq of
begin
process ( Sel, A, B,
begin
case Sel is
when "00" =>
Y
when "01" =>
Y
when "10" =>
Y
when "11" =>
Y
when others => Y
end case;
end process;
end DF2_Eq;
architecture RTL of DFF_E is
begin
process ( Clk )
begin
if rising_edge( Clk ) then
if CE = '1' then
Q <= D;
end if;
end if;
end process;
end architecture;
20
entity DFF is
port ( D
: in STD_LOGIC;
Clk : in STD_LOGIC;
Q
: out STD_LOGIC );
end DFF;
entity TFF is
port ( T
: in STD_LOGIC;
Clk : in STD_LOGIC;
Q
: out STD_LOGIC );
end TFF;
architecture RTL of DFF is
begin
process ( Clk )
begin
if Clk'Event and Clk = '1' then
Q <= D;
end if;
end process;
end architecture;
architecture RTL of TFF is
signal Q_int : STD_LOGIC := '0';
begin
Q <= Q_int;
process ( Clk )
begin
if Clk'Event and Clk = '1' then
if T = '1' then
Q_int <= not Q_int;
end if;
end if;
end process;
end architecture;
function rising_edge (signal s : STD_ULOGIC) return BOOLEAN;
function falling_edge (signal s : STD_ULOGIC) return BOOLEAN;
if Clk'Event and Clk = '1' then...
is
in
in
in
in
out
=>
if rising_edge(Clk) then...
22
JS UCiSW 1
entity DFF_CE
port( D
:
Clr :
CE :
Clk :
Q
:
end DFF_CE;
A;
B;
C;
D;
'X';
• Pakiet STD_LOGIC_1164:
Asynchronous Clear + Enable:
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC );
<=
<=
<=
<=
<=
JS UCiSW 1
21
entity DFF_E is
port( D
: in
CE : in
Clk : in
Q
: out
end DFF_E;
C, D )
Sygnały synchroniczne
• S'Event = TRUE: w danym cyklu
symulacji sygnał S zmienił wartość
exit;
exit outer_loop;
exit when A > B;
exit this_loop when C = D or A > B;
Clock Enable:
MUX_4 is
JS UCiSW 1
Synchronous Reset + Enable:
entity DFF_RE
port( D
:
Rst :
CE :
Clk :
Q
:
end DFF_RE;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC );
architecture RTL of DFF_CE is
begin
process ( Clk, Clr )
begin
if Clr = '1' then
Q <= '0';
elsif rising_edge(Clk) then
if CE = '1' then
Q <= D;
end if;
end if;
end process;
end architecture;
23
is
in
in
in
in
out
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC;
STD_LOGIC );
architecture RTL of DFF_RE is
begin
process ( Clk )
begin
if rising_edge( Clk ) then
if Rst = '1' then
Q <= '0';
elsif CE = '1' then
Q <= D;
end if;
end if;
end process;
end architecture;
24
4
JS UCiSW 1
JS UCiSW 1
Rejestr przesuwny:
Np.
entity SReg8b is
port ( Din : in STD_LOGIC;
Clk : in STD_LOGIC;
Q
: out STD_LOGIC_VECTOR( 7 downto 0 ) );
end SReg8b;
architecture RTL of SimpleSch is
signal D, Q : STD_LOGIC;
begin
D <= ( E1 and E2 ) xor Q;
architecture RTL of SReg8b is
signal iQ : STD_LOGIC_VECTOR( 7 downto 0 );
begin
Q <= iQ;
process ( Clk )
begin
if rising_edge( Clk ) then
iQ( 7 downto 0 ) <= iQ( 6 downto 0 ) & Din;
end if;
end process;
end architecture;
Licznik z asynchronicznym kasowaniem:
process( Clk )
begin
if rising_edge( Clk ) then
if Reset = '1' then
Q <= '0';
else
Q <= D;
end if;
end if;
end process;
Y <= Q;
end RTL;
25
26
JS UCiSW 1
JS UCiSW 1
Licznik modulo (i z sygnałem zezwalającym):
process ( Clk, Clr )
begin
if Clr = '1 then
Cnt4b <= "0000";
elsif rising_edge( Clk ) and CE = '1' then
if Cnt4b = "1011" then
Cnt4b <= "0000";
else
Cnt4b <= Cnt4b + 1;
end if;
end if;
end process;
!
27
28
JS UCiSW 1
JS UCiSW 1
Licznik rewersyjny:
Licznik ładowalny:
29
30
5
JS UCiSW 1
Zatrzask:
JS UCiSW 1
Zatrzask z asynchronicznym kasowaniem:
31
32
JS UCiSW 1
JS UCiSW 1
Bufor trójstanowy:
Maszyny stanów
33
entity SequenceDet is
port ( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
x : in STD_LOGIC;
z : out STD_LOGIC);
end SequenceDet;
JS UCiSW 1
1/0
0/0
A
1/0
B
1/0
C
0/0
0/1
architecture Behavioral of SequenceDet is
type state_type is ( A, B, C, D );
signal state, next_state : state_type;
begin
process1 : process( Clk )
begin
if rising_edge( Clk ) then
if Reset = '1' then
state <= A;
else
state <= next_state;
end if;
end if;
end process process1;
process2 : process( state, x )
begin
next_state <= state;
-- by default
case state is
when A =>
if x = '1' then
next_state <= B;
end if;
JS UCiSW 1
Pakiet STANDARD
1/0
0/0
34
D
X/Z
when B =>
if x = '1' then
next_state <= C;
else
next_state <= A;
end if;
when C =>
if x = '0' then
next_state <= D;
end if;
when D =>
if x = '0' then
next_state <= A;
else
next_state <= B;
end if;
end case;
end process process2;
-- In place of process3:
z <= '1' when state = D and x = '0'
else '0';
end Behavioral;
35
type INTEGER is range --usually typical INTEGER-- ;
subtype NATURAL is INTEGER range 0 to INTEGER'HIGH;
subtype POSITIVE is INTEGER range 1 to INTEGER'HIGH;
type REAL is range --usually double precision f.p.-- ;
type BOOLEAN is (FALSE, TRUE);
type CHARACTER is ( --256 characters-- );
type STRING is array (POSITIVE range <>) of CHARACTER;
type BIT is ('0', '1');
type TIME is range --implementation defined-- ;
units
fs;
-- femtosecond
ps = 1000 fs; -- picosecond
ns = 1000 ps; -- nanosecond
us = 1000 ns; -- microsecond
ms = 1000 us; -- millisecond
sec = 1000 ms; -- second
min = 60 sec; -- minute
hr = 60 min; -- hour
end units;
subtype DELAY_LENGTH is TIME range 0 fs to TIME'HIGH;
36
6
JS UCiSW 1
Operatory
**
abs
not
exponentiation,
absolute value,
complement,
numeric ** integer,
result numeric
abs numeric,
result numeric
not logic or boolean, result same
*
/
mod
rem
multiplication,
division,
modulo,
remainder,
numeric
numeric
integer
integer
+
-
unary plus,
unary minus,
+ numeric,
- numeric,
result numeric
result numeric
+
&
addition,
subtraction,
concatenation,
numeric + numeric,
numeric - numeric,
array or element,
result numeric
result numeric
result array
* numeric,
/ numeric,
mod integer,
rem integer,
result
result
result
result
numeric
numeric
integer
integer
Pakiet STD_LOGIC_1164
JS UCiSW 1
sll
srl
sla
sra
rol
ror
shift left logical,
shift right log.,
shift left arith.,
shift right arith.,
rotate left,
rotate right,
=
/=
<
<=
>
>=
equality,
inequality,
less than,
less than or equal,
greater than,
greater than or equal,
and
or
nand
nor
xor
xnor
logical
logical
logical
logical
logical
logical
and,
or,
nand,
nor,
xor,
xnor,
log.
log.
log.
log.
log.
log.
array
array
array
array
array
array
sll
srl
sla
sra
rol
ror
integer,
integer,
integer,
integer,
integer,
integer,
result
result
result
result
result
result
log.
log.
log.
log.
log.
log.
array
array
array
array
array
array
or
or
or
or
or
or
boolean,
boolean,
boolean,
boolean,
boolean,
boolean,
result
result
result
result
result
result
same
same
same
same
same
same
boolean
boolean
boolean
boolean
boolean
boolean
result
result
result
result
result
result
same
same
same
same
same
same
37
38
JS UCiSW 1
JS UCiSW 1
function resolved ( s : STD_ULOGIC_VECTOR ) return STD_ULOGIC;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
type STD_ULOGIC is ( 'U',
'X',
'0',
'1',
'Z',
'W',
'L',
'H',
'-'
);
U!
type STD_ULOGIC_VECTOR
STD_ULOGIC;
is
----------
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' ) -- | - |
);
(...)
Uninitialized
Forcing Unknown
Forcing 0
Forcing 1
High Impedance
Weak
Unknown
Weak
0
Weak
1
Don't care
array
(
NATURAL
range
<>
)
-------------------------------------------------------------------- *** industry standard logic type ***
------------------------------------------------------------------subtype STD_LOGIC is resolved STD_ULOGIC;
type STD_LOGIC_VECTOR is array ( NATURAL range <>) of STD_LOGIC;
of
39
constant and_table : stdlogic_table := (
-----------------------------------------------------| U
X
0
1
Z
W
L
H
( 'U', 'U', '0', 'U', 'U', 'U', '0', 'U', 'U' ), -( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ), -( '0', '0', '0', '0', '0', '0', '0', '0', '0' ), -( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ), -( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ), -( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ), -( '0', '0', '0', '0', '0', '0', '0', '0', '0' ), -( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ), -( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' )
-);
constant or_table : stdlogic_table := (
-----------------------------------------------------| U
X
0
1
Z
W
L
H
( 'U', 'U', 'U', '1', 'U', 'U', 'U', '1', 'U' ), -( 'U', 'X', 'X', '1', 'X', 'X', 'X', '1', 'X' ), -( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ), -( '1', '1', '1', '1', '1', '1', '1', '1', '1' ), -( 'U', 'X', 'X', '1', 'X', 'X', 'X', '1', 'X' ), -( 'U', 'X', 'X', '1', 'X', 'X', 'X', '1', 'X' ), -( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ), -( '1', '1', '1', '1', '1', '1', '1', '1', '1' ), -( 'U', 'X', 'X', '1', 'X', 'X', 'X', '1', 'X' )
-);
JS UCiSW 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
U
X
0
1
Z
W
L
H
-
U
X
0
1
Z
W
L
H
-
40
entity Ex1 is
port(
A, B : in STD_LOGIC;
Y : out );
end entity;
|
|
|
|
|
|
|
|
|
|
Cykl:
(...)
10ns
41
A
B
S
Y
'0' '0' '0' '0'
'1' '0' '0' '0'
architecture DFlow of Ex1 is
signal S : STD_LOGIC;
begin
S <= A or B;
Y <= B xor S;
end architecture;
Opis:
(a) A←1 (b) A’event, wyk. S<=... :
trans. ‘1’/10ns → POW_S
∆
'1' '0' '1' '0'
(a) S←1 (b) S’event, wyk. Y<=... :
trans. ‘1’/10ns → POW_Y
10ns + 2∆
'1' '0' '1' '1'
(a) Y←1 (b) Y'event
(koniec)
10ns +
|
|
|
|
|
|
|
|
|
|
JS UCiSW 1
Cykle symulacji
process (A, B, S)
begin
S <= A or B;
Y <= B xor S;
end process;
?
42
7
process ( Clk )
begin
if rising_edge( Clk ) then
Q0 <= Din;
Q1 <= Q0;
end if;
end process;
Cykl
(...)
10ns
Clk Din Q0 Q1
'0' '1' '0' '0'
'1' '1' '0' '0'
10ns + ∆
'1' '1' '1' '0'
JS UCiSW 1
Q0
Din
D
Q
Q1
D
FSM_SendByte
DI
DO
Q
Clk
'1' '1' '1' '0'
DIRdy
DORdy
Busy
TxBusy
Reset
Clk
Opis:
entity FSM_SendByte is
port ( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
DI : in STD_LOGIC_VECTOR (7 downto 0);
DIRdy : in STD_LOGIC;
TxBusy : in STD_LOGIC;
DO : out STD_LOGIC_VECTOR (7 downto 0);
DORdy : out STD_LOGIC;
Busy : out STD_LOGIC );
end FSM_SendByte;
(a) Clk ← 1
(b) Clk’event, wykonanie procesu:
trans. ‘1’/10ns → POW_Q0,
trans. ‘0’/10ns → POW_Q1
(a) Q0 ← 1, Q1 ← 0
(b) Q0’event, Q1 tylko active
(koniec)
process( Clk, Din, Q0, Q1 )...?
(...)
10ns + ∆
JS UCiSW 1
Przykład:
Moduł transkodujący otrzymany bajt na dwa znaki ASCII
architecture RTL of FSM_SendByte is
(a) Q0 ← 1, Q1 ← 0
(b) Q0’event, wykonanie procesu:
warunek if niespełniony
(koniec)
type state_type is ( sReset, sReady, sWaitH, sSendH,
sWaitL, sSendL );
signal State, NextState : state_type;
signal regDI : STD_LOGIC_VECTOR (7 downto 0);
signal HalfByte : STD_LOGIC_VECTOR (3 downto 0);
43
JS UCiSW 1
(...)
begin
JS UCiSW 1
(...)
-- Next state decoding = process1
process ( State, DIRdy, TxBusy )
begin
-- Input register (with CE)
regDI <= DI when rising_edge( Clk ) and State = sReady;
-- SKRÓT PROCESU!
NextState <= State; -- default
case State is
when sReset =>
NextState <= sReady;
-- HalfByte selection
HalfByte <= regDI( 7 downto 4 ) when State = sSendH or
State = sWaitL
else regDI( 3 downto 0 );
when sReady =>
if DIRdy = '1' then
NextState <= sWaitH;
end if;
-- State register (with asynchronous reset) = process1
process ( Clk, Reset )
begin
if Reset = '1' then
State <= sReset;
elsif rising_edge( Clk ) then
State <= NextState;
end if;
end process;
when sWaitL =>
if TxBusy = '0' then
NextState <= sSendL;
end if;
when sWaitH =>
if TxBusy = '0' then
NextState <= sSendH;
end if;
when sSendL =>
NextState <= sReady;
end case;
end process;
when sSendH =>
NextState <= sWaitL;
(...)
(...)
45
(...)
-- Outputs = process3
with HalfByte select
DO <= X"30" when "0000",
X"31" when "0001",
X"32" when "0010",
X"33" when "0011",
X"34" when "0100",
X"35" when "0101",
X"36" when "0110",
X"37" when "0111",
X"38" when "1000",
X"39" when "1001",
X"41" when "1010",
X"42" when "1011",
X"43" when "1100",
X"44" when "1101",
X"45" when "1110",
X"46" when others;
JS UCiSW 1
-- 0-15 => ASCII '0'-'F'
end RTL;
46
Testbench
JS UCiSW 1
entity Test_vhd is
end Test_vhd;
architecture behavior of Test_vhd is
-- component Declaration for the Unit Under Test (UUT)
component FSM_SendByte
port(
Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
DI : in STD_LOGIC_VECTOR(7 downto 0);
DIRdy : in STD_LOGIC;
TxBusy : in STD_LOGIC;
DO : out STD_LOGIC_VECTOR(7 downto 0);
DORdy : out STD_LOGIC;
Busy : out STD_LOGIC
);
end component;
DORdy <= '1' when State = sSendH or State = sSendL
else '0';
Busy
44
--Inputs
signal Clk : STD_LOGIC := '0';
signal Reset : STD_LOGIC := '0';
signal DIRdy : STD_LOGIC := '0';
signal TxBusy : STD_LOGIC := '0';
signal DI : STD_LOGIC_VECTOR(7 downto 0) := (others=>'0');
<= '1' when State /= sReady
else '0';
47
48
8
JS UCiSW 1
--Outputs
signal DO : STD_LOGIC_VECTOR(7 downto 0);
signal DORdy : STD_LOGIC;
signal Busy : STD_LOGIC;
-- AUX
constant Tclk : TIME := 1 us / 50;
JS UCiSW 1
-- Byte source
process
type typeArray is array ( 0 to 3 )
of STD_LOGIC_VECTOR( 7 downto 0 );
variable arrBytes : typeArray := ( X"10", X"20", X"3A", X"4F" );
-- MHz
begin
begin
-- Instantiate the Unit Under Test (UUT)
uut: FSM_SendByte port map(
Clk => Clk,
Reset => Reset,
DI => DI,
DIRdy => DIRdy,
TxBusy => TxBusy,
DO => DO,
DORdy => DORdy,
Busy => Busy
);
wait for 500 ns;
for i in arrBytes'RANGE loop
if Busy = '1' then
wait until Busy = '0';
end if;
wait for 7.1 * Tclk;
DI <= arrBytes( i );
DIRdy <= '1';
wait for Tclk;
DIRdy <= '0';
-- Global clock 50MHz
Clk <= not Clk after Tclk / 2;
end loop;
wait; -- will wait forever
-- Reset
Reset <= '1' after 300 ns, '0' after 300 ns + Tclk;
end process;
49
50
JS UCiSW 1
-- ASCII sink
process
begin
loop
wait until rising_edge( Clk ) and DORdy = '1';
TxBusy <= '1';
wait for 11 * Tclk;
TxBusy <= '0';
-- e.g. 11 * Tclk
end loop;
end process;
end architecture;
51
9
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement