Professional Documents
Culture Documents
*.sdc – timing
*.qsf – signal
*.sof – outputfile
Simulation
*.qsf
#============================================================
#Y
#============================================================
set_location_assignment PIN_V16 -to Y[0]
set_location_assignment PIN_W16 -to Y[1]
set_location_assignment PIN_V17 -to Y[2]
set_location_assignment PIN_V18 -to Y[3]
set_location_assignment PIN_W17 -to Y[4]
set_location_assignment PIN_W19 -to Y[5]
set_location_assignment PIN_Y19 -to Y[6]
set_location_assignment PIN_W20 -to Y[7]
set_location_assignment PIN_W21 -to Y[8]
set_location_assignment PIN_Y21 -to Y[9]
Pin
Planner
Simple Inputs and Outputs
Switch inputs
7 Segment LED’s
J-TAG Chain on board
High-Speed USB
Peripheral Controller
Simple Signal Assignments
VHDL has built-in support for the following operators
– and logical AND
– or logical OR
– not logical NOT
– nand, nor, xor, xnor
• VHDL does not assume any precedence of logic operators.
Use parentheses in expressions to determine precedence
– Exception to this is NOT logical operator
• In VHDL, a logic expression is called a simple assignment
statement. There are other types that will be introduced that
are useful for more complex circuits.
Signal Usage
signal K,L,M:bit;
begin
Y(9 downto 2) <= (others => '0');
K <= not D(0) and D(1);
L <= not D(0) and not D(1) and D(2);
M <= (not D(0) and not D(1) and not D(2) and D(3));
Y(0) <= K or M;
Y(1) <= L or M;
end behavioral ;
Selected signal assignment
-- or
C <='0' when a='0' and b='0' else
'1' when a='1' and b='1' else
'1' when a='1' and b='0' else
'0' when a='1' and b='1' else
'0';
Mux 2-1
entity mux2to1 is
port (w0, w1, s : in std_logic;
f : out std_logic);
end mux2to1;
architecture behavior of mux2to1 is
begin
f <= w0 when s = '0' else w1;
end behavior;
Priority Encoder
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Priority_Encoder_VHDL is
port ( Sel : in std_logic_vector(3 downto 0);
encoded_data : out std_logic_vector(1 downto
0);
D : out std_logic);
end entity Priority_Encoder_VHDL;
Sensitivity
Architecture SEQ of DECODER 2x4 is
begin
list (equivalent to wait
MYPROCESS: process(A,B,ENABLE) on statements)
variable ABAR, BBAR:BIT;
Labels begin
Declarations
ABAR := not A; BBAR := not B;
if (ENABLE = ‘1’) then
Z(3) <= not (A and B); Sequential
Assign values Z(0) <= not (ABAR and BBAR); statements
to signal Z(2) <= not (A and BBAR);
drivers else Actual
Z<= ‘1111’; assignment
end if; of Signals
end process MYPROCESS;
end;
Process Rules
• If a process has a sensitivity list, then it can not contain a wait
statement
• A process with a sensitivity list is always triggered at time 0 because
all signals always have an initial event placed on them.
• A process without a sensitivity list is triggered at time 0 initially
• If a proc without a sensitivity list “falls out the bottom” then it loops
back to top until it hits a wait statement.
Interaction of Processes
READY
CLK ACK
RX: process
begin READY MP: process
READ_WORD(SERIAL_IN,CLK,DATA); begin
READY <= ‘1’; wait for 25 ns;
DATA PARALLEL_OUT <= DATA;
wait until ACK =‘1’;
READY <= ‘0’; ACK <= ‘1’,’0’ after 25 ns;
wait for 50 ns; wait until READY = ‘1’;
ACK end process MP;
end process RX;
READY
0 65 75 140 150
entity DE1_SoC is
port
( 10
SW : in std_logic_vector(9 downto 0); Function
LEDR : out std_logic_vector(9 downto 0)
);
end DE1_SoC;
Small ALU Implementation using 2-1 decoder
architecture ppl_type of DE1_SoC is
begin
process(SW)
begin
LEDR(9 downto 3) <= (others => '0');
case SW(1 downto 0) is
when "00" =>
LEDR(2 downto 0) <= ('0' & SW(9 downto 8)) + ('0' & SW(7 downto 6));
when "01" =>
LEDR(2 downto 0) <= ('0' & SW(9 downto 8)) + (not ('0' & SW(7 downto 6))+"001");
when "10" =>
LEDR(2 downto 0) <= ('0' & SW(9 downto 8)) and ('0' & SW(7 downto 6));
when "11" =>
LEDR(2 downto 0) <= ('0' & SW(9 downto 8)) xor ('0' & SW(7 downto 6));
when others =>
LEDR(2 downto 0) <= "XXX";
end case;
end process;
end;
Review of VHDL for Sequential Circuits
• Basic storage elements
– Structural design using library components
– Behavioral design: D latches and D flip-flops
• Options including
– Synchronous and asynchronous reset
– Multiplexed inputs
– Enable inputs
• Counters
• Shift Registers
• Arbitrary finite state machines (FSM) – next week?
– Mealy and Moore model designs – next week?
Structural VHDL Using a D flip-flop
package
library ieee;
use ieee.std_logic_1164.all;
library altera;
use altera.maxplus2.all;
entity flipflop is
port ( d, clock : in std_logic; reset_n,
preset_n : in std_logic; q : out std_logic);
end flipflop;
architecture structure of flipflop is
begin
dff_instance: dff port map (d,clock,reset_n,preset_n,q);
end structure;
Code for a gated D latch
library ieee;
use ieee.std_logic_1164.all;
entity latch is
port ( d, clk : in std_logic;q : out std_logic);
end latch;
architecture behavior of latch is
begin
process ( d, clk )
begin
if clk = '1' then
q <= d;
end if;
-- implied memory implementation
-- uses the last assigned value
end process;
end behavior;
Code for a D flip-flop
library ieee;
use ieee.std_logic_1164.all;
entity flipflop is
port ( d, clock : in std_logic;
q : out std_logic);
end flipflop;
architecture behavior of flipflop is
begin
process (clock)
begin
if clock'event and clock = '1' then
q <= d; Positive edge
end if; triggered
end process;
end behavior;
Code for a D flip-flop
library ieee;
use ieee.std_logic_1164.all;
entity flipflop is
port ( d, clock : in std_logic; q : out std_logic);
end flipflop;
architecture behavior of flipflop is
begin
process (clock)
begin
if rising_edge(clock) then Use “falling edge”
q <= d; for negative going
end if; edge
end process;
Code for a D flip-flop (alternate)
library ieee;
use ieee.std_logic_1164.all;
entity flipflop is
port ( d, clock : in std_logic;
q : out std_logic );
end flipflop;
architecture behavior of flipflop is
begin
process
begin
wait until clock'event and clock = '1';
q <= d;
end process;
end behavior;
D flip-flop with synchronous reset
library ieee;
use ieee.std_logic_1164.all;
entity flipflop is
port ( d, reset_n, clock : in std_logic;
q : out std_logic);
end flipflop;
architecture behavior of flipflop is
begin
process
begin
wait until clock'event and clock = '1';
if reset_n = '0' then
q <= '0';
else
q <= d;
end if;
end process;
D flip-flop with MUX input
library ieee;
use ieee.std_logic_1164.all;
entity muxdff is
port ( d0, d1, sel, clock : in std_logic;
q : out std_logic);
end muxdff;
architecture behavior of muxdff is
begin
process
begin
wait until clock'event and clock = '1';
if sel = '0' then
q <= d0;
else
q <= d1;
end if;
end process;
end behavior;
D flip-flop with enable input
library ieee;
use ieee.std_logic_1164.all;
entity flipflop is
port ( enable, d, clk : in std_logic;q : out std_logic);
end flipflop;
architecture behavior of flipflop is
begin
process(clk)
begin
if enable=‘0’ then null; This will be our preferred method
elsif rising_edge(clk) then for creating a D flip-flop or a
q <= d; multibit register with enable.
end if;
end process;
D flip-flop with asynchronous reset
library ieee;
use ieee.std_logic_1164.all;
entity flipflop is
port ( reset_n, d, clk : in std_logic;
q : out std_logic);
end flipflop;
architecture behavior of flipflop is
begin
process(clk,reset_n)
begin
if reset_n =‘0’ then
q <= ‘0’;
This will be our preferred method
elsif rising_edge(clk) then
for creating a D flip-flop or a
q <= d;
multibit register with reset.
end if;
end process;
end behavior;
Counter Modeling with VHDL
library ieee;
use ieee.std_logic_1164.all;
-- use numeric_std to include
-- signed and unsigned data types
use ieee.numeric_std.all;
entity upcount is
port ( clock, reset_n,e : in std_logic; q : out unsigned(3 downto 0));
end upcount;
Four bit up counter
architecture behavior of upcount is
signal count : unsigned(3 downto 0);
begin
process (clock,reset_n)
begin
if reset_n = '0' then
count <= "0000";
elsif (clock'event and clock = '1') then
if e = '1' then
count <= count + 1;
else
count <= count;
end if;
end if;
end process;
q <= count;
end behavior;
Up Counter Using INTEGER
library ieee;
use ieee.std_logic_1164.all;
entity count is
port( clock : in std_logic;
sload : in std_logic;
-- integer data types are a default size of 32 bits
-- use a range specifier to limit the number of bits
-- generated for the register (5 bits in this case)
data : in integer range 0 to 31;
result : out integer range 0 to 31;
end count;
Up Counter Using INTEGER
architecture rtl of count is
signal result_reg : integer range 0 to 31;
begin
process (clock)
begin
if (clock'event and clock = '1') then
if (sload = '1') then
result_reg <= data;
else
result_reg <= result_reg + 1;
end if;
end if;
end process;
result <= result_reg;
end rtl;
VHDL Shift Register Design
-- vhdl code for an 8-bit shift-left register with a
positive-
-- edge clock, asynchronous clear, serial in, and serial
out.
library ieee;
use ieee.std_logic_1164.all;
entity shift is
port(
-- clk is the clock for the shift operation
-- si is a serial input into the lsb of the shift register
-- clr is an asynchronous active high clear control signal
clk, si, clr : in std_logic;
-- so is a serial output from the msb of the shift register
so : out std_logic);
end shift;
VHDL Shift Register Design
architecture behavior of shift is
signal s_reg: std_logic_vector(7 downto 0);
begin
process(clk,clr)
begin
if(clr='1') then
s_reg <= "00000000";
elsif rising_edge(clk) then
s_reg <= s_reg (6 downto 0) & si;
end if;
end process;
so <= s_reg(7);
end behavior;
Rotate Register Example
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity rotatereg is
generic( width : integer := 8);
port(clk : in std_logic;
dir : in std_logic := '0';
reg_out : out std_logic_vector(width-1 downto 0));
end rotatereg;
architecture behavior of rotatereg is
signal reg : std_logic_vector(width-1 downto 0) := (0 => '1', others => '0');
begin
process(clk)
begin
if rising_edge(clk) then
if (dir='0') then -- Rotate right if dir='0'
reg <= reg(0) & reg(width-1 downto 1);
else
reg <= reg(width-2 downto 0) & reg(width-1);
end if;
end if;
end process;
reg_out <= reg;
end behavior;
THESE TO BE MERGED WITH
PREVIOUS SLIDES!!!!
Recommended
y <= "10" ; • Note that not all inputs need to be included on the sensitivity list
Timing diagram
t1 t2 t3 t4
Clock
D
Q
Time
Clock
D
Q
Time
ENTITY flipflop_ar IS D Q
PORT ( D, Reset, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC) ; Clock
END flipflop_ar ; Reset
ENTITY reg8 IS
PORT ( D : IN STD_LOGIC_VECTOR(7 DOWNTO 0) ;
Reset, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ) ;
END reg8 ;
ENTITY regn IS
GENERIC ( N : INTEGER := 16 ) ;
PORT ( D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ;
Reset, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ;
END regn ;
Q <= “10000001” can be written as Q <= (7 => ‘1’, 0 => ‘1’, OTHERS => ‘0’)
or Q <= (7 | 0 => ‘1’, OTHERS => ‘0’)
Q <= “00011110” can be written as Q <= (4 downto 1=> ‘1’, OTHERS => ‘0’)
ENTITY regne IS
GENERIC ( N : INTEGER := 8 ) ;
PORT ( D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ;
Enable, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ;
END regne ;
Enf Enf
Clk Clk
Reset Reset
EnC EnV
Clk Clk
Reset Reset
ENTITY upcount_ar IS
PORT ( Clock, Reset, Enable : IN STD_LOGIC ;
Q : OUT STD_LOGIC_VECTOR (3 DOWNTO 0)) ;
END upcount_ar ;
Enable 4
Q
Clock
upcount
Reset
Sin
D Q D Q D Q D Q
Clock
Enable
D Q D Q D Q D Q
Clock
Enable
ENTITY shift4 IS
PORT ( D : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
Enable : IN STD_LOGIC ;
Load : IN STD_LOGIC ;
Sin : IN STD_LOGIC ;
Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;
END shift4 ;
4 Enable 4
D Q
Load
Sin
shift4
Clock
ECE 448 – FPGA and ASIC
Design with VHDL
4-bit shift register with parallel load (2)
ARCHITECTURE behavioral OF shift4 IS
SIGNAL Qt : STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN 4 Enable 4
PROCESS (Clock) D Q
BEGIN Load
IF rising_edge(Clock) THEN
Sin
IF Enable = ‘1’ THEN shift4
IF Load = '1' THEN Clock
Qt <= D ;
ELSE
Qt <= Sin & Qt(3 downto 1);
END IF;
END IF ;
END PROCESS ;
Q <= Qt;
END behavioral ;
ENTITY shiftn IS
GENERIC ( N : INTEGER := 8 ) ;
PORT ( D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ;
Enable : IN STD_LOGIC ;
Load : IN STD_LOGIC ;
Sin : IN STD_LOGIC ;
Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ;
END shiftn ;
N Enable N
D Q
Load
Sin
shiftn
Clock
ECE 448 – FPGA and ASIC
Design with VHDL
N-bit shift register with parallel load (2)
ARCHITECTURE behavioral OF shiftn IS
SIGNAL Qt: STD_LOGIC_VECTOR(N-1 DOWNTO 0);
BEGIN N N
Enable
PROCESS (Clock)
D Q
BEGIN
IF rising_edge(Clock) THEN Load
IF Enable = ‘1’ THEN Sin
shiftn
IF Load = '1' THEN
Clock
Qt <= D ;
ELSE
Qt <= Sin & Qt(N-1 downto 1);
END IF;
END IF ;
END PROCESS ;
Q <= Qt;
END behavior al;
ENTITY regne IS
GENERIC ( N : INTEGER := 8 ) ;
PORT ( D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ;
Enable, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ;
END regne ;
s(0)
r(0) 0 p(0) En
r(1) 1
w0 q(1) Enable
p(1) y1 w y
q(0) 1 3 z(3) t(3)
r(2) w1
p(2) y0 w y
r(3) w2 0 2 z(2) t(2)
ena D Q
z y
w3 1
priority
z(1) t(1)
r(4) 0 p(3) y
En 0 z(0) t(0)
dec2to4 regne
r(5) 1
Clk Clock
s(1)
ECE 448 – FPGA and ASIC
Design with VHDL
Structural description – example (1)
VHDL-93
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY priority_resolver IS
PORT (r: IN STD_LOGIC_VECTOR(5 DOWNTO 0) ;
s : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;
clk : IN STD_LOGIC;
en : IN STD_LOGIC;
t : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;
END priority_resolver;
En => ena,
y => z);
Enable => En ,
Q => t );
END structural;
ENTITY priority_resolver IS
PORT (r: IN STD_LOGIC_VECTOR(5 DOWNTO 0) ;
s : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;
clk : IN STD_LOGIC;
en : IN STD_LOGIC;
t : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;
END priority_resolver;
COMPONENT priority
PORT (w : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
y : OUT STD_LOGIC_VECTOR(1 DOWNTO 0) ;
z : OUT STD_LOGIC ) ;
END COMPONENT ;
COMPONENT dec2to4
PORT (w : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;
En : IN STD_LOGIC ;
y : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;
END COMPONENT ;
COMPONENT regne
GENERIC ( N : INTEGER := 8 ) ;
PORT ( D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ;
Enable, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ;
END COMPONENT ;
Enable => En ,
Clock => Clk,
Q => t );
END structural;
Examples:
package alu_pkg is
end alu_pkg;
Using objects from a package
library ieee;
use ieee.std_logic_1164.all;
library work;
use work.alu_pkg.all;
entity alu_comb is
…………..
Mixing Description Styles
Inside of an Architecture
begin
Concurrent statements:
• Simple signal assignment
• Conditional signal assignment
• Selected signal assignment
Process statement
• inside process you can use only sequential
statements
end ARCHITECTURE_NAME;
PRNG Example (1)
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use work.prng_pkg.all;
ENTITY PRNG IS
PORT( Coeff : in std_logic_vector(4 downto 0);
Load_Coeff : in std_logic;
Seed : in std_logic_vector(4 downto 0);
Init_Run : in std_logic;
Clk : in std_logic;
Current_State : out std_logic_vector(4 downto 0));
END PRNG;
-- Behavioral
Coeff_Reg: PROCESS(Clk)
BEGIN
IF rising_edge(Clk) THEN
IF Load_Coeff = '1' THEN
Coeff_Q <= Coeff;
END IF;
END IF;
END PROCESS;
-- Structural
Shift5_Reg : ENTITY work.Shift5(behavioral) PORT MAP ( D => Seed,
Load => Init_Run,
Sin => Sin,
Clock => Clk,
Q => Shift5_Q);
END mixed;
Sequential Logic Synthesis
for
Beginners
Recommended
• S. Brown and Z. Vranesic, Fundamentals of Digital
Logic with VHDL Design
Chapter 6, Combinational-Circuit Building Blocks
Chapter 5.5, Design of Arithmetic Circuits Using
CAD Tools
ECE 448 – FPGA and ASIC
Design with VHDL
Types of VHDL Description
(Modeling Styles)
VHDL Descriptions
• Testbenches
VHDL code
Dataflow VHDL
synthesizable
VHDL code
Dataflow VHDL
synthesizable
Concurrent Statements
• concurrent signal assignment
()
<=
target_signal <= expression;
When - Else
target_signal <= value1 when condition1 else
value2 when condition2 else
. . .
valueN-1 when conditionN-1 else
valueN;
With –Select-When
with choice_expression select
target_signal <= expression1 when choices_1,
expression2 when choices_2,
. . .
expressionN when choices_N;
b
8 bus
c = d0
SIGNAL a: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL b: STD_LOGIC_VECTOR(4 DOWNTO 0);
SIGNAL c: STD_LOGIC;
SIGNAL d: STD_LOGIC_VECTOR(9 DOWNTO 0);
4
A(3) A(2) A(1) A(0)
A
A
>>1
C L
4 C
‘0’ A(3) A(2) A(1)
4
A(3) A(2) A(1) A(0)
A
A
>>1
C A
4 C
A(3) A(3) A(2) A(1)
4
A(3) A(2) A(1) A(0)
A
A
<<1
C L
4 C
A(2) A(1) A(0) ‘0’
4
A(3) A(2) A(1) A(0)
A
A
<<< 1
C
4 C
A(2) A(1) A(0) A(3)
A
3
B A <<< B
C
8
x1
x2
x1
x1 + x2 x1+ x2+ + xn
x2
xn
(b) OR gates
x x
xn
x1
x2
x1
x1 + x2 x 1 + x 2 +… + x n
x2
xn
x1
x1 x1
x2 x2
x2
(a) x1 x2 = x1 + x2
x1
x1 x1
x2 x2
x2
(b) x1 + x2 = x1 x2
x1 x2 f = x1 x2
0 0 0
0 1 1
x1
1 0 1 f = x1 x2
x2
1 1 0
x1
x2
f = x1 x2
x1 x2 f = x1 x2
0 0 1
0 1 0
x1
1 0 0 f = x1 x2 = x1 . x2
x2
1 1 1
x1
x2
f = x1 x2
x
y s
cin
cout
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY fulladd IS
PORT ( x : IN STD_LOGIC ;
y : IN STD_LOGIC ;
cin : IN STD_LOGIC ;
s : OUT STD_LOGIC ;
cout : OUT STD_LOGIC ) ;
END fulladd ;
• Logic operators
and or nand nor xor not xnor
Wanted: y = ab + cd
Incorrect
y <= a and b or c and d ;
equivalent to
y <= ((a and b) or c) and d ;
equivalent to
y = (ab + c)d
Correct
y <= (a and b) or (c and d) ;
w
0 0 w
f 0 0
w
1 1 1 w
1
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY mux2to1 IS
PORT ( w0, w1, s : IN STD_LOGIC ;
f : OUT STD_LOGIC ) ;
END mux2to1 ;
w 0
3
0
w 1 y
2 w
1 1
s2
s1
VHDL:
f <= w1 WHEN s1 = ‘1' ELSE
w2 WHEN s2 = ‘1’ ELSE
w3 ;
ENTITY mux_cascade IS
PORT ( w1, w2, w3: IN STD_LOGIC ;
s1, s2 : IN STD_LOGIC ;
f : OUT STD_LOGIC ) ;
END mux_cascade ;
• Relational operators
= /= < <= > >=
compare a = bc
Incorrect
… when a = b and c else …
equivalent to
… when (a = b) and c else …
Correct
… when a = (b and c) else …
s
s 0
s s f
s 1 0
1
w 0 0 w
0 00 0
w 0 1 w
1 01 1
f
w 1 0 w
2 10 2
w 11 1 1 w
3 3
WITH s SELECT
f <= w0 WHEN "00",
w1 WHEN "01",
w2 WHEN "10",
w3 WHEN OTHERS ;
ECE 448 – FPGA and ASIC
Design with VHDL
VHDL code for a 4-to-1 Multiplexer entity
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY mux4to1 IS
PORT ( w0, w1, w2, w3 : IN STD_LOGIC ;
s : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;
f : OUT STD_LOGIC ) ;
END mux4to1 ;
ENTITY dec2to4 IS
PORT ( w : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;
En : IN STD_LOGIC ;
y : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;
END dec2to4 ;
w0
y0
w1 y
w y1
w2 y <= "11" WHEN w(3) = '1' ELSE
w3 z "10" WHEN w(2) = '1' ELSE
"01" WHEN w(1) = '1' ELSE
"00" ;
w3 w2 w1 w0 y1 y0 z z <= '0' WHEN w = "0000" ELSE '1' ;
0 0 0 0 d d 0
0 0 0 1 0 0 1
0 0 1 - 0 1 1
0 1 - - 1 0 1
1 - - - 1 1 1
ENTITY priority IS
PORT ( w : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
y : OUT STD_LOGIC_VECTOR(1 DOWNTO 0) ;
z : OUT STD_LOGIC ) ;
END priority ;
16 16
X Y
Cout + Cin
S
16
USE ieee.std_logic_unsigned.all
and
signals of the type
STD_LOGIC_VECTOR
OR
USE ieee.numeric_std.all
and
signals of the type
UNSIGNED
and conversion functions:
std_logic_vector(), unsigned()
ENTITY adder16 IS
PORT ( Cin : IN STD_LOGIC ;
X : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ;
Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ;
S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0) ;
Cout : OUT STD_LOGIC ) ;
END adder16 ;
ENTITY adder16 IS
PORT ( Cin : IN STD_LOGIC ;
X : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ;
Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ;
S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0) ;
Cout : OUT STD_LOGIC ) ;
END adder16 ;
USE ieee.numeric_std.all,
signals of the type
SIGNED,
and conversion functions:
std_logic_vector(), signed()
OR
USE ieee.std_logic_signed.all
and signals of the type
STD_LOGIC_VECTOR
ECE 448 – FPGA and ASIC
Design with VHDL
Signed and Unsigned Types
Unsigned Signed
1111 15 1111 -1
x 1111 x 15 x 1111 x -1
8 8
a b
*
c U
16
entity multiply is
port(
a : in STD_LOGIC_VECTOR(7 downto 0);
b : in STD_LOGIC_VECTOR(7 downto 0);
c : out STD_LOGIC_VECTOR(15 downto 0)
);
end multiply;
8 8
a b
*
c S
16
entity multiply is
port(
a : in STD_LOGIC_VECTOR(7 downto 0);
b : in STD_LOGIC_VECTOR(7 downto 0);
c : out STD_LOGIC_VECTOR(15 downto 0)
);
end multiply;
8 8
a b
*
cu cs
16 16
entity multiply is
port(
a : in STD_LOGIC_VECTOR(7 downto 0);
b : in STD_LOGIC_VECTOR(7 downto 0);
cu : out STD_LOGIC_VECTOR(15 downto 0);
cs : out STD_LOGIC_VECTOR(15 downto 0)
);
end multiply;
-- signed multiplication
cs <= STD_LOGIC_VECTOR(SIGNED(a)*SIGNED(b));
-- unsigned multiplication
cu <= STD_LOGIC_VECTOR(UNSIGNED(a)*UNSIGNED(b));
end dataflow;
4
A
4
A>B AgtB
B
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_unsigned.all ;
ENTITY compare IS
PORT ( A, B : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
AgtB : OUT STD_LOGIC ) ;
END compare ;
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_signed.all ;
ENTITY compare IS
PORT ( A, B : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
AgtB : OUT STD_LOGIC ) ;
END compare ;
x f
e= 0
(a) A tri-state buffer x f
e x f e= 1
x f
0 0 Z
0 1 Z
1 0 0 (b) Equivalent circuit
1 1 1
e e
x f x f
e e
x f x f
ENTITY tri_state IS
PORT ( e: IN STD_LOGIC;
x: IN STD_LOGIC;
f: OUT STD_LOGIC
);
END tri_state;
Addr
8x16
ROM
Dout
16
C
ECE 448 – FPGA and ASIC
Design with VHDL
ROM 8x16 example (2)
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;
ENTITY rom IS
PORT (
Addr : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
Dout : OUT STD_LOGIC_VECTOR(15 DOWNTO 0)
);
END rom;
ROM 8x16 example (3)
ARCHITECTURE dataflow OF rom IS
SIGNAL temp: INTEGER RANGE 0 TO 7;
TYPE vector_array IS ARRAY (0 to 7) OF STD_LOGIC_VECTOR(15 DOWNTO 0);
CONSTANT memory : vector_array :=
( X”800A",
X"D459",
X"A870",
X"7853",
X"650D",
X"642F",
X"F742",
X"F548");
BEGIN
END dataflow;
Describing
Combinational Logic
Using
Dataflow Design Style
IN0 Y1
MUX_1
NEG_A IN1 0
MUX_2 IN2 OUTPUT Y
1
IN3 SEL0
SEL1
NEG_Y
0 B1
B
1
L1 L0
MUX_3
NEG_B
MLU: Entity Declaration
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY mlu IS
PORT(
NEG_A : IN STD_LOGIC;
NEG_B : IN STD_LOGIC;
NEG_Y : IN STD_LOGIC;
A: IN STD_LOGIC;
B: IN STD_LOGIC;
L1 : IN STD_LOGIC;
L0 : IN STD_LOGIC;
Y: OUT STD_LOGIC
);
END mlu;
SIGNAL A1 : STD_LOGIC;
SIGNAL B1 : STD_LOGIC;
SIGNAL Y1 : STD_LOGIC;
SIGNAL MUX_0 : STD_LOGIC;
SIGNAL MUX_1 : STD_LOGIC;
SIGNAL MUX_2 : STD_LOGIC;
SIGNAL MUX_3 : STD_LOGIC;
SIGNAL L: STD_LOGIC_VECTOR(1 DOWNTO 0);
END mlu_dataflow;
Major instructions
Concurrent statements
• concurrent signal assignment ()
• conditional concurrent signal assignment
(when-else)
• selected concurrent signal assignment
(with-select-when)
When - Else
target_signal <= value1 when condition1 else
value2 when condition2 else
. . .
valueN-1 when conditionN-1 else
valueN;
When - Else
target_signal <= value1 when condition1 else
value2 when condition2 else
. . .
valueN-1 when conditionN-1 else
valueN;
Value N 0
1
.… … 0
Value N-1 1 0
Target Signal
1
Value 2
Value 1
Condition N-1
Condition 2
Condition 1
ECE 448 – FPGA and ASIC
Design with VHDL
Data-flow VHDL
Major instructions
Concurrent statements
• concurrent signal assignment ()
• conditional concurrent signal assignment
(when-else)
• selected concurrent signal assignment
(with-select-when)
With –Select-When
with choice_expression select
target_signal <= expression1 when choices_1,
expression2 when choices_2,
. . .
expressionN when choices_N;
expression1 choices_1
expression2 choices_2
target_signal
expressionN choices_N
choice expression
ECE 448 – FPGA and ASIC
Design with VHDL
Allowed formats of choices_k
WHEN value
WHEN OTHERS
Statements, such as
wait for 5 ns
a <= b after 10 ns
will not produce the required delay, and
should not be used in the code intended
for synthesis.
PROCESS (clk)
BEGIN
counter <= counter + 1;
END PROCESS;