Docsity

VHDL Programming: Bit-Counting Circuit and Dataflow VHDL - Prof. David Hwang, Study notes of Digital Systems Design

Partial preview of the text

Download VHDL Programming: Bit-Counting Circuit and Dataflow VHDL - Prof. David Hwang and more Study notes Digital Systems Design in PDF only on Docsity!

1

ECE 545—Digital System Design with VHDL

Lecture 4

Algorithmic State Machines and Dataflow

VHDL Coding

Outline

  • Algorithmic State Machines
    • Sorting Example
  • Dataflow VHDL (for combinational logic)
  • Arithmetic using std_logic_arith

3

Resources

  • Volnei A. Pedroni, Circuit Design with VHDL
    • Chapter 5, Concurrent Code
    • Chapter 4.1, Operators
  • Stephen Brown and Zvonko Vranesic , Fundamentals

of Digital Logic with VHDL Design, 2

nd

or 3

rd

Edition

  • Chapter 8.10 Algorithmic State Machine (ASM) Charts
  • Chapter 10.2.1 A Bit-Counting Circuit
  • Chapter 10.2.2 ASM Chart Implied Timing Information
  • Chapter 10.2.6 Sort Operation

(handouts distributed in class)

Algorithmic State Machines

7

Brief Class Review

• In this class we have covered the following items

without using VHDL :

• Gates and combinational logic blocks (Lecture 2)

• Sequential logic blocks (Lecture 3)

• State machines (Lecture 3)

• Algorithmic state machines (Lectures 3 & 4)

• Now we will learn how to code these blocks in VHDL

Combinational
Logic
Combinational
Logic

Registers

Today’s Topic

Register Transfer Level (RTL) Design Description

9

VHDL Design Styles (Architecture)

STRUCTURAL

components and interconnects

VHDL Design Styles

DATAFLOW

“concurrent” statements (^) • State machines

  • Registers
  • Complex Comb. Logic

“sequential” statements

NON-
SYNTHESIZABLE
SYTHESIZABLE
BEHAVIORAL
  • Test Benches
  • Gates^ •^ Modeling IP
  • Simple Comb. Logic
  • concurrent signal assignment (⇐)
  • conditional concurrent signal assignment

(when-else)

  • selected concurrent signal assignment

(with-select-when)

  • generate scheme for equations

(for-generate)

Major instructions

Concurrent statements

Dataflow VHDL

13

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 ;
ARCHITECTURE fulladd_dataflow OF fulladd IS
BEGIN
s <= x XOR y XOR cin ;
cout <= (x AND y) OR (cin AND x) OR (cin AND y) ;
END fulladd_dataflow ;

Full Adder Example

TIP: for architecture name for dataflow circuits
use either "dataflow" or "entityname_dataflow"

Logic Operators

  • Logic operators
  • Logic operators precedence

and or nand nor xor not xnor

not and or nand nor xor xnor

Highest

Lowest

only in VHDL- and later

15

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) ;

No Implied Precedence

Concatenation

SIGNAL a: STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL b: STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL c, d, e: STD_LOGIC_VECTOR(7 DOWNTO 0);

a <= "0000"; b <= "1111"; c <= a & b; -- c = "00001111"

d <= '0' & "0001111"; -- d <= "00001111"

e <= '0' & '0' & '0' & '0' & '1' & '1' & '1' & '1'; -- e <= "00001111"

19

Shifts in VHDL (using libraries)

  • Using std_logic_arith package:
    • function SHL(ARG: UNSIGNED; COUNT: UNSIGNED) return UNSIGNED;
    • function SHL(ARG: SIGNED; COUNT: UNSIGNED) return SIGNED;
    • function SHR(ARG: UNSIGNED; COUNT: UNSIGNED) return UNSIGNED;
    • function SHR(ARG: SIGNED; COUNT: UNSIGNED) return SIGNED;
  • Make sure your syntax is correct
  • Recommend not using these functions, but "hard-wiring" the

shifts as in previous examples

  • concurrent signal assignment (⇐)
  • conditional concurrent signal assignment

(when-else)

  • selected concurrent signal assignment

(with-select-when)

  • generate scheme for equations

(for-generate)

Major instructions

Concurrent statements

Dataflow VHDL

21

target_signal <= value1 when condition1 else value2 when condition2 else

... valueN-1 when conditionN-1 else valueN ;

When - Else

Value N .…

Value N-

Condition N- Condition 2 Condition 1

Value 2 Value 1

Target Signal

… 0 1

Conditional concurrent signal assignment

  • Relational operators
  • Logic and relational operators precedence

= /= < <= > >=

not = /= < <= > >= and or nand nor xor xnor

Highest
Lowest

Operators

25

  • concurrent signal assignment (⇐)
  • conditional concurrent signal assignment

(when-else)

  • selected concurrent signal assignment

(with-select-when)

  • generate scheme for equations

(for-generate)

Major instructions

Concurrent statements

Dataflow VHDL

with choice_expression select target_signal <= expression1 when choices_1 , expression2 when choices_2 ,

... expressionN when choices_N ;

With –Select-When

choices_

choices_

choices_N

expression

target_signal

choice expression

expression

expressionN

Selected concurrent signal assignment

27

Allowed formats of choices_k

WHEN value
WHEN value_1 to value_
WHEN value_1 | value_2 | .... | value N
this means boolean “or”

Allowed formats of choice_k - example

WITH sel SELECT

y <= a WHEN "000",

b WHEN "011" to "110",

c WHEN "001" | "111",

d WHEN OTHERS;

31

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;

MLU: Architecture Declarative Section

ARCHITECTURE mlu_dataflow OF mlu IS

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);

33

MLU - Architecture Body

BEGIN
A1<= NOT A WHEN (NEG_A='1') ELSE
A;
B1<= NOT B WHEN (NEG_B='1') ELSE
B;
Y <= NOT Y1 WHEN (NEG_Y='1') ELSE
Y1;
MUX_0 <= A1 AND B1;
MUX_1 <= A1 OR B1;
MUX_2 <= A1 XOR B1;
MUX_3 <= A1 XNOR B1;
L <= L1 & L0;

with (L) select Y1 <= MUX_0 WHEN "00", MUX_1 WHEN "01", MUX_2 WHEN "10", MUX_3 WHEN OTHERS;

END mlu_dataflow;

Data-flow VHDL

  • concurrent signal assignment (⇐)
  • conditional concurrent signal assignment

(when-else)

  • selected concurrent signal assignment

(with-select-when)

  • generate scheme for equations

(for-generate)

Major instructions

Concurrent statements

37

PARITY: Block Diagram

PARITY: Entity Declaration

LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY parity IS
PORT(
parity_in : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
parity_out : OUT STD_LOGIC
END parity;

39

PARITY: Block Diagram

xor_out(1) xor_out(2) xor_out(3) (^) xor_out(4) xor_out(5) (^) xor_out(6)

PARITY: Architecture

ARCHITECTURE parity_dataflow OF parity IS

SIGNAL xor_out: std_logic_vector (6 downto 1);

BEGIN

xor_out(1) <= parity_in(0) XOR parity_in(1);
xor_out(2) <= xor_out(1) XOR parity_in(2);
xor_out(3) <= xor_out(2) XOR parity_in(3);
xor_out(4) <= xor_out(3) XOR parity_in(4);
xor_out(5) <= xor_out(4) XOR parity_in(5);
xor_out(6) <= xor_out(5) XOR parity_in(6);
parity_out <= xor_out(6) XOR parity_in(7);

END parity_dataflow;