CENG 342 Digital Systems Register-Transfer (RT) Level Combinational - - PowerPoint PPT Presentation

ceng 342 digital systems
SMART_READER_LITE
LIVE PREVIEW

CENG 342 Digital Systems Register-Transfer (RT) Level Combinational - - PowerPoint PPT Presentation

CENG 342 Digital Systems Register-Transfer (RT) Level Combinational Circuit Larry Pyeatt SDSM&T RT-Level Description Gate-level Design RT-level Design (module-level) Adders Comparators Decoders Multiplexers VHDL operators and


slide-1
SLIDE 1

CENG 342 – Digital Systems

Register-Transfer (RT) Level Combinational Circuit Larry Pyeatt

SDSM&T

slide-2
SLIDE 2

RT-Level Description

Gate-level Design RT-level Design (module-level)

Adders Comparators Decoders Multiplexers

VHDL operators and routing constructs RT-level combinational circuits

slide-3
SLIDE 3

Operators - arithmetic, structural, relational, and logical

Operator Description Data type of operands Data type of Result a ** b exponentiation integer integer a * b multiplication integer integer a / b division integer integer a + b addition integer integer a - b subtraction integer integer a & b concatenation 1-D array, element 1-D array a = b equal to any boolean a /= b not equal to any boolean a < b less than scalar or 1-D array boolean a <= b less than or equal to scalar or 1-D array boolean a > b greater than scalar or 1-D array boolean a >= b greater than or equal to scalar or 1-D array boolean not a negation scalar or 1-D array same as operand a and b and boolean, std_logic, std_logic_vector same as operands a or b

  • r

boolean, std_logic, std_logic_vector same as operands a xor b exclusive or boolean, std_logic, std_logic_vector same as operands

slide-4
SLIDE 4

Operators and data types in IEEE numeric_std package

The IEEE numeric_std package is part of the IEEE library. It: adds two data types: unsigned, and signed, and defines the relational and arithmetic operations over those data types. To use the package, add to the top of your VHDL file:

1 library ieee; 2 use ieee.numeric_std.all -- include numeric_std package

Operator Description Data type of operands Data type of Result a * b multiplication unsigned, natural, signed, integer unsigned, signed a + b addition unsigned, natural, signed, integer unsigned, signed a - b subtraction unsigned, natural, signed, integer unsigned, signed a = b equal to unsigned, natural, signed, integer boolean a /= b not equal to unsigned, natural, signed, integer boolean a < b less than unsigned, natural, signed, integer boolean a <= b less than or equal to unsigned, natural, signed, integer boolean a > b greater than unsigned, natural, signed, integer boolean a >= b greater than or equal to unsigned, natural, signed, integer boolean

slide-5
SLIDE 5

Type hierarchy

Type Value Package boolean true, false VHDL standard integer −(231) to (231 − 1) VHDL standard natural zero and positive integers VHDL standard std_logic ’U’, ’X’, ’0’, ’1’, ’Z’, ’W’, ’L’, ’H’, ’-’ std_logic_1164 std_logic_vector array of std_logic std_logic_1164 unsigned array of std_logic numeric_std signed array of std_logic numeric_std

Example:

1

signal A_unsigned : unsigned(3 downto 0) ;

2

signal B_signed : signed (3 downto 0) ;

3

signal C_slv : std_logic_vector (3 downto 0) ;

4

. . .

5

A_unsigned <= "1111" ; -- set A_unsigned to 15

6

B_signed <= "1111" ;

  • - set B_signed to -8

7

C_slv <= "1111" ;

  • - set C_slv to "1111"
slide-6
SLIDE 6

Example

1

signal A, B, Result : unsigned(7 downto 0) ;

2

signal Result1 : unsigned(8 downto 0) ;

3

signal Result2 : unsigned(6 downto 0) ;

4

. . .

5

  • - simple addition, no carry out

6

Result <= A + B ;

7

  • - with carry out ?

8

Result1 <= (’0’ & A) + (’0’ & B)

9

  • - For a smaller result, take slices of input arrays

10

Result2 <= A(6 downto 0) + B(6 downto 0) ;

Length of result depends on length of operands and the operation being performed.

1 Y <= A;

  • - Y’Length = A’Length

2 Y <= A and B; -- Y’Length = A’Length = B’Length 3 W <= A > B;

  • - Boolean: W is one bit

4 Y <= A + B;

  • - Y’Length = Maximum(A’Length, B’Length) or +1 with carry out

5 V <= A * B;

  • - Y’Length = A’Length + B’Length
slide-7
SLIDE 7

Type Conversions

The std_logic_vector, unsigned, and signed types are defined as arrays with elements of std_logic. They are not the same type as the built-in boolean, integer, and natural, types, but sometimes it is necessary to work with combinations of these types. There are conversion (typecasting) functions.

Data type of a To data type Conversion function unsigned or signed std_logic_vector std_logic_vector(a) signed or std_logic_vector unsigned unsigned(a) unsigned or std_logic_vector signed signed(a) unsigned or signed integer to_integer(a) natural unsigned to_unsigned(a, size) integer signed to_signed(a, size)

Example:

1 signal a1, a2, a3, a4: std_logic_vector(3 downto 0); 2 signal b1, b2, b3, b4: unsigned(3 downto 0); 3 variable i: natural; 4 ... 5

a1 <= std_logic_vector (b1);

6

b3 <= unsigned (a4);

7

b3 <= to_unsigned(i,4);

8

a2 <= std_logic_vector (to_unsigned(3,4));

slide-8
SLIDE 8

Type Conversions - Quiz

1 signal a1, a2, a3, a4: std_logic_vector(3 downto 0); 2 signal b1, b2, b3, b4: unsigned(3 downto 0);

Statement Valid? a3 <= a1 + a2 a2 <= a1 + 2 b3 <= b1 + b2 b2 <= b1 + 2 a3 <= a1 * a2 b3 <= b1 * b2

slide-9
SLIDE 9

Type Conversions - Quiz

1 signal a1, a2, a3, a4: std_logic_vector(3 downto 0); 2 signal b1, b2, b3, b4: unsigned(3 downto 0);

Statement Valid? a3 <= a1 + a2 N a2 <= a1 + 2 b3 <= b1 + b2 b2 <= b1 + 2 a3 <= a1 * a2 b3 <= b1 * b2

slide-10
SLIDE 10

Type Conversions - Quiz

1 signal a1, a2, a3, a4: std_logic_vector(3 downto 0); 2 signal b1, b2, b3, b4: unsigned(3 downto 0);

Statement Valid? a3 <= a1 + a2 N a2 <= a1 + 2 N b3 <= b1 + b2 b2 <= b1 + 2 a3 <= a1 * a2 b3 <= b1 * b2

slide-11
SLIDE 11

Type Conversions - Quiz

1 signal a1, a2, a3, a4: std_logic_vector(3 downto 0); 2 signal b1, b2, b3, b4: unsigned(3 downto 0);

Statement Valid? a3 <= a1 + a2 N a2 <= a1 + 2 N b3 <= b1 + b2 Y b2 <= b1 + 2 a3 <= a1 * a2 b3 <= b1 * b2

slide-12
SLIDE 12

Type Conversions - Quiz

1 signal a1, a2, a3, a4: std_logic_vector(3 downto 0); 2 signal b1, b2, b3, b4: unsigned(3 downto 0);

Statement Valid? a3 <= a1 + a2 N a2 <= a1 + 2 N b3 <= b1 + b2 Y b2 <= b1 + 2 Y a3 <= a1 * a2 b3 <= b1 * b2

slide-13
SLIDE 13

Type Conversions - Quiz

1 signal a1, a2, a3, a4: std_logic_vector(3 downto 0); 2 signal b1, b2, b3, b4: unsigned(3 downto 0);

Statement Valid? a3 <= a1 + a2 N a2 <= a1 + 2 N b3 <= b1 + b2 Y b2 <= b1 + 2 Y a3 <= a1 * a2 N b3 <= b1 * b2

slide-14
SLIDE 14

Type Conversions - Quiz

1 signal a1, a2, a3, a4: std_logic_vector(3 downto 0); 2 signal b1, b2, b3, b4: unsigned(3 downto 0);

Statement Valid? a3 <= a1 + a2 N a2 <= a1 + 2 N b3 <= b1 + b2 Y b2 <= b1 + 2 Y a3 <= a1 * a2 N b3 <= b1 * b2 Y

slide-15
SLIDE 15

Other synthesis-related VHDL constructs

Concatenation operator: & is used to combine segments of small arrays to form a bigger array. Example1: shifting a signal for a fixed amount

1

signal a: std_logic_vector (6 downto 0);

2

signal shift1, shift2, shift3: std_logic_vector (6 downto 0);

3

...

4

shift1 <= a(2 downto 0) & a(6 downto 3); -- rotate right 3 bits

5

shift2 <= "000" & a(6 downto 3);

  • - logical shift right 3 bits

6

Shift3 <= a(6) & a(6) & a(6 downto 2);

  • - arithmetic shift right 3 bits

Example2: addition with carry out

1

signal A, B: unsigned(7 downto 0) ;

2

signal Result1 : unsigned(8 downto 0) ;

3

...

4

  • - addition with carry out

5

Result1 <= (’0’ & A) + (’0’ & B) ;

slide-16
SLIDE 16

Array aggregation

VHDL has some handy syntax for assigning values to arrays. Example:

1

a <= "10100000";

2

a <= (7=>’1’, 6=>’0’, 0=>’0’, 1=>’0’, 5=>’1’, 4=>’0’, 3=>’0’, 2=>’1’);

3

a <= (7|5=>’1’, 6|4|3|2|1|0=>’0’);

4

a <= (7|5=>’1’, others=>’0’); Note that " is used for multiple bits, and ’ is used for single bits.

slide-17
SLIDE 17

Tri-state buffer

A logic component that is not always covered in the introductory logic course. It can output ’0’, ’1’ or ’Z’. The ’Z’ output high impedence, or open circuit. In other words, the component is not

  • utputting logic high or low, and it is as if it is not connected at all.

The diagram and truth table are: Core of the VHDL code for the tri-state buffer:

1 y <= a_in when oe=’1’ else ’Z’;

Example: implement a bidirectional port to better utilize a I/O pin:

1

...

2 bi <= sig_out when dir=’1’ else ’Z’; 3 sig_in <=bi;

slide-18
SLIDE 18

Summary

A small set of data types and operators are needed in our class for the purpose of synthesis If no arithmetic operations, use std_logic and std_logic_vector for entity port declaration and internal signals. ’Z’ value is only used in a tri-state buffer. For internal signals with arithmetic operations, use the IEEE numeric_std package and its unsigned and signed types Use integer and arithmetic operators for constant and array boundary, but not for a signal’s data type. Use the result of a relational operation (Boolean data type) in routing constructs. Use a user-defined two-directional data type for two-dimensional storage array (Chapter 4) Use a user-defined enumerate data type for the symbolic states of a finite state machine (Chapter 5) Reference: http://www.synthworks.com/papers/vhdl_math_tricks_mapld_2003.pdf