CENG 342 Digital Systems A Combinational Logic Circuit in VHDL - - PowerPoint PPT Presentation

ceng 342 digital systems
SMART_READER_LITE
LIVE PREVIEW

CENG 342 Digital Systems A Combinational Logic Circuit in VHDL - - PowerPoint PPT Presentation

CENG 342 Digital Systems A Combinational Logic Circuit in VHDL Larry Pyeatt SDSM&T Testbench VHDL code can be simulated in a computer to verify the correctness. After simulation, the code can be synthesized to a physical device. For


slide-1
SLIDE 1

CENG 342 – Digital Systems

A Combinational Logic Circuit in VHDL Larry Pyeatt

SDSM&T

slide-2
SLIDE 2

Testbench

VHDL code can be simulated in a computer to verify the correctness. After simulation, the code can be synthesized to a physical device. For simulation, a special program, called a testbench, is created to mimic a physical lab bench.

The uut block is the unit under test. The test vector generator block generates testing input patterns. The monitor observes the output.

The testbench is a VHDL entity with no ports. There is a tutorial on the course website for using the Xilinx Vivado to create and simulate VHDL code.

slide-3
SLIDE 3

Testbench code

1 LIBRARY ieee; 2 USE ieee.std_logic_1164.ALL; 3 4 ENTITY cmp_testbench IS 5 END cmp_testbench; 6 7 ARCHITECTURE behavior OF cmp_testbench IS 8

  • - Component Declaration for the

9

  • - Unit Under Test (UUT)

10

COMPONENT comparator_for_1bit

11

PORT(

12

i0 : IN std_logic;

13

i1 : IN std_logic;

14

eq : OUT std_logic

15

);

16

END COMPONENT;

17

  • -Inputs

18

signal i0 : std_logic := ’0’;

19

signal i1 : std_logic := ’0’;

20

signal eq : std_logic;

21 begin 22

  • - Instantiate the Unit Under Test

23

uut: comparator_for_1bit PORT MAP (

24

i0 => i0,

25

i1 => i1,

26

eq => eq

27

);

28

  • - Stimulus process

29

stim_proc: process

30

begin

31

  • - hold reset state for 100 ns.

32

wait for 100 ns;

33

i0 <= not i0;

34

wait for 100 ns;

35

i1 <= not i1;

36

wait for 100 ns;

37

i0 <= not i0;

38

end process;

39 END;

In a process, the statements are evaluated sequentially. (Imperative programming.)

slide-4
SLIDE 4

Wait

Since processes are imperative programming, control structures may be needed. We will cover them as we need them. The wait statement is used to suspend a process Wait for time period Example: wait for 20ns; Wait until Boolean-expression: suspends a process until the expression becomes TRUE Example: wait until falling_edge(clk); Wait on sensitivity-list: wait until one of the signals on the sensitivity list changes Example: wait on max_tick; Wait by itself will suspend the process indefinitely Example: wait; --suspend process for remainder of simulation

slide-5
SLIDE 5

For Loop

The for loop defines a loop parameter which takes on the type of the range specified. Examples:

1

for I in 0 to 3 loop

2

  • - loop body

3

end loop;

1 type PRIMARY is (RED, GREEN, BLUE); 2 ... 3

for SEL in PRIMARY loop

4

  • - loop body

5

end loop; Attributes such as ’high, ’low and ’range may also be used to define the iterations of a for loop:

1

TMP := ’0’;

2

for I in A’low to A’high loop

3

TMP := TMP xor A(I);

4

end loop;

5

ODD <= TMP; We will discuss attributes in more detail later.

slide-6
SLIDE 6

Modeling Styles

Structural Modeling describes a set of interconnected components by declaring their existence and connections. The component instantiation statements are concurrent in nature, so the

  • rder of these statements is not important.

For example, the following statement blocks are equivalent;

1

and1: entity work.and(behavioral)

2

port map(i0=>a, i1=>b, o=>ab);

3

and2: entity work.and(behavioral)

4

port map(i0=>b, i1=>c, o=>bc);

5

  • r1: entity work.or(behavioral)

6

port map(i0=>ab, i1=>bc, o=>f);

1

  • r1: entity work.or(behavioral)

2

port map(i0=>ab, i1=>bc, o=>f);

3

and2: entity work.and(behavioral)

4

port map(i0=>b, i1=>c, o=>bc);

5

and1: entity work.and(behavioral)

6

port map(i0=>a, i1=>b, o=>ab);

Dataflow Modeling defines a set of concurrent (parallel) statements which declare the relationships between signals. The signal assignment statements are concurrent in nature, so the order

  • f these statements is not important.

For example, the following statement blocks are equivalent;

1

eq <= p0 or p1;

2

p0 <= (not i0) and (not i1);

3

p1 <= i0 and i1;

1

p1 <= i0 and i1;

2

p0 <= (not i0) and (not i1);

3

eq <= p0 or p1;

slide-7
SLIDE 7

Modeling Styles - Continued

Behavioral Modeling describes the functionality (or behavior) of an entity using sequential statements. These statements are usually specified within a process statement. The process statement itself is a concurrent statement, but inside it lies a set

  • f statements which are all sequential in nature. Their order is important.

Mixed Modeling is the combination of any of the three pure modeling styles.

slide-8
SLIDE 8

2-bit Comparator

a1 a0 b1 b0 a = b 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Logical function for a = b?

slide-9
SLIDE 9

2-bit Comparator

a1 a0 b1 b0 a = b 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Logical function for a = b?

00 01 11 10 00

1

01

1

11

1

10

1

slide-10
SLIDE 10

2-bit Comparator

a1 a0 b1 b0 a = b 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Logical function for a = b?

00 01 11 10 00

1

01

1

11

1

10

1 Not much simplification possible there. . . f = a1 a0 b1 b0 + a1 a0 b1 b0 + a1 a0 b1 b0 + a1 a0 b1 b0

slide-11
SLIDE 11

2-bit Comparator: VHDL Entity Declaration

Here is the entity declaration:

1 library IEEE; 2 use IEEE.std_logic_1164.ALL; 3 4 -- eq2 is a two-bit comparator. 5 -- If a==b then aeqb=1, else aeqb=0 6 entity eq2 is 7

Port ( a : in std_logic_vector (1 downto 0);

8

b : in std_logic_vector (1 downto 0);

9

aeqb : out std_logic);

10 end eq2;

We use std_logic_vector for each of the two inputs. This allows us to define them as two-bit busses. When defining std_logic_vector, we typically put the highest index on the left, which goes along with our concept that the bits in a multi-bit number are counted up from right to left (or down from left to right). This declares an entity which accepts two 2-bit numbers, and outputs a single bit. It does not say what the relationship is between the inputs and the outputs. That part is done in the architecture. We leave a comment here so that we know what it does without reading the code in the architecture(s).

slide-12
SLIDE 12

2-bit Comparator: VHDL Data Flow Implementation

With the previous Sum-Of-Products equation, we can create a straightforward Data Flow implementation:

12 architecture sop_arch of eq2 is 13

signal p0,p1,p2,p3: std_logic;

14 begin 15

  • - sum of product terms

16

aeqb <= p0 or p1 or p2 or p3;

17

  • - product terms

18

p0 <= ((not a(1)) and (not b(1))) and ((not a(0)) and (not b(0)));

19

p1 <= ((not a(1)) and (not b(1))) and (a(0) and b(0));

20

p2 <= (a(1) and b(1)) and ((not a(0)) and (not b(0)));

21

p3 <= (a(1) and b(1)) and (a(0) and b(0));

22 end sop_arch;

This collection of concurrent statements describes the logical relationship between the signals and ports in the device. (A port is a special type of signal.)

slide-13
SLIDE 13

2-bit Comparator: VHDL Structural Implementation

Structural design allows us to build a large system from simple building blocks. It is close to schematic capture. Components are interconnected in a hierarchical manner. Structural descriptions may connect simple gates or complex, abstract components. We can use the 1-bit comparator to build a 2-bit comparator. Graphical representation:

a = b eq1 eq1 a0 b0 a1 b1 a0 = b0 a1 = b1

VHDL:

24 architecture struc_arch of eq2 is 25

signal e0, e1: std_logic;

26 begin 27

  • - instantiate two 1-bit comparators

28

eq_bit0_unit: entity work.eq1(sop_arch) port map(i0=>a(0), i1=>b(0), eq=>e0);

29

eq_bit1_unit: entity work.eq1(sop_arch) port map(i0=>a(1), i1=>b(1), eq=>e1);

30

  • - a and b are equal if individual bits are equal

31

aeqb <= e0 and e1;

32 end struc_arch;

Note that this is actually a mixed model implementation.

slide-14
SLIDE 14

Entity Instantiation

Syntax:

1 unit_label: entity lib_name.entity_name (arch_name) 2

port map (formal_signal => actual_signal , ... ); The work library is the default library to store the compiled entity and architecture units. The port mapping specifies the connections, where formal_signal is the I/O port in a component entity (building block), while actual_signal is a signal or port on the entity you are defining. For structural design of VHDL, put all relevant source files under the same project.

1

Create a project

2

Add a VHDL source file for the 1-bit comparator.

3

Create a testbench file for the 1-bit comparator (should be in “simulation only” sources). Do simulation and check the correctness.

4

Under the same project (hardware chip icon xcs400), create a new VHDL source file for the 2-bit comparator.

5

Under the same project, create a new VHDL source file for the testbench for the 2-bit comparator (should be in “simulation only” sources). Do simulation and check the correctness.

slide-15
SLIDE 15

Component Instantiation

slide-16
SLIDE 16

Assignment

1

Run both of the comparator testbenches.

2

Modify the 2-bit testbench to use loop(s) rather that specifying each bit combination explicitly.

3

Create a new project, and implement a 2-to-4 binary decoder.

An n-to-2n decoder has an n inputs and 2n outputs. The n inputs represent a binary number that determines which one of the outputs is true. A 2-to-4 decoder operates according to the following truth table. a1 a0 Q0 Q1 Q2 Q3 1 1 1 1 1 1 1 1 The 2-bit input is called a, and it’s two bits are a1 and a0. The four outputs are Q0–Q3. If the input is the binary number i, then output Qi is true and all other outputs are false.

4

Create a testbench for your decoder and verify that it works.