1 asic 120: digital systems and standard-cell asic design tutorial 2: introduction to vhdl february...

53
1 ASIC 120: Digital Systems and Standard- Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

Upload: norman-walsh

Post on 18-Jan-2018

220 views

Category:

Documents


0 download

DESCRIPTION

3 Summary of Previous Tutorial Digital Systems Combinational Logic –NOT, AND, OR, XOR, NAND, etc. –mux, half-adder, full-adder Sequential Logic –flip-flop/register, shift register, counter

TRANSCRIPT

Page 1: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

1

ASIC 120: Digital Systems and Standard-Cell ASIC Design

Tutorial 2: Introduction to VHDLFebruary 1, 2006

Page 2: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

2

Outline

• State Machines• HDL design flow• Format of a VHDL file• Combinational statements

– assignments, conditionals, when … else• Sequential statements

– processes, if … then … else

Page 3: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

3

Summary of Previous Tutorial

• Digital Systems• Combinational Logic

– NOT, AND, OR, XOR, NAND, etc.– mux, half-adder, full-adder

• Sequential Logic– flip-flop/register, shift register, counter

Page 4: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

4

Recall: Sequential Circuits

• Sequential– computation involves a

feedback loop (memory)

• Example: ring counter

In Out

CombinationalInput Output

Feedback

Clk

DFF

D Q

S C

Init

DFF

D Q

S C

DFF

D Q

S C

DFF

D Q

S C

Page 5: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

5

State Machines

• We actually mean a Finite State Machine (FSM)– models behaviour

• Components relevant to digital design– states– transitions– inputs– outputs

Page 6: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

6

State Machines

• Represented as a state diagram

S0

S1

S3

1/0

S2

0/0

1/1

0/1

1/1

1/00/1

0/0

State

Transition

Output

Input

Page 7: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

7

State Machines• Or as a state table Present

StateInput

ANext State

OutputX

S0 0 S0 0S0 1 S1 0S1 0 S3 1

S1 1 S2 1S2 0 S3 1S2 1 S2 1S3 0 S1 0S3 1 S0 0

Input A Output X

S0

S1

S3

1/0

S2

0/0

1/1

0/1

1/1

1/00/1

0/0

Page 8: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

8

State Machines• Encode states into

binary Present State

InputA

Next State

OutputX

00 0 00 0

00 1 01 0

01 0 11 1

01 1 10 1

10 0 11 1

10 1 10 1

11 0 01 0

11 1 00 0

Input A Output X

00

01

11

1/0

10

0/0

1/1

0/1

1/1

1/00/1

0/0

Page 9: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

9

State Machines

• Some things to note– we assigned S0 = 00, S1 = 01, etc., but

state/bit mapping can be completely arbitrary– output is occurring on the transitions, this is

called a Mealy state machine– where the output is dependent only on the

current state, it is called a Moore machine

Page 10: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

10

State Machines• Remodelled as a Moore

state machine Present State

InputA

Next State

OutputX

00 0 00 0

00 1 01 0

01 0 11 1

01 1 10 1

10 0 11 1

10 1 10 1

11 0 01 0

11 1 00 0

Input A

Output X

00(0)

01(0)

11(1)

1

10(1)

0

1

10

0

Page 11: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

11

State Machines

• This example is rather contrived– only dealing with abstract “states”, but

imagine application to automatic door, traffic lights, etc.

– Moore and Mealy machine looked the same• but they won’t always

Page 12: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

12

State Machines

00(0)

01(0)

11(1)

1

10(1)

0

1

10

000

01

11

1/0

10

0/0

1/1

0/1

1/1

1/00/1

0/0

Moore Mealy

Page 13: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

13

State Machines: Moore vs. Mealy

• Mealy can often be represented using less states– transitions can produce different output

• Even with more states, Moore often creates less hardware– less combinational logic– on an FPGA, registers (D flip-flops) are “free”

Page 14: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

14

State Machines in Digital Hardware

• This state machine requires two registers (D flip-flops), since there are four states

• Basic procedure:1) create state table2) derive FF input equations (and output

equations) from next state column with respect to present state and inputs

3) simplify equations4) draw hardware

Page 15: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

15

State Machines in Digital HardwareLet the two state bits (registers) be G and H

– we also have input A

G = GHA + GHA + GHA + GHAH = GHA + GHA + GHA + GHAX = G H

Present State

A Next State

X

G H G H

0 0 0 0 0 0

0 0 1 0 1 0

0 1 0 1 1 1

0 1 1 1 0 1

1 0 0 1 1 1

1 0 1 1 0 1

1 1 0 0 1 0

1 1 1 0 0 0

Page 16: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

16

State Machines in Digital HardwareSimplify the equations

G = G HH = GHA + AX = G H

Present State

A Next State

X

G H G H

0 0 0 0 0 0

0 0 1 0 1 0

0 1 0 1 1 1

0 1 1 1 0 1

1 0 0 1 1 1

1 0 1 1 0 1

1 1 0 0 1 0

1 1 1 0 0 0

Page 17: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

17

State Machines in Digital HardwareDraw the hardware

G = G HH = GHA + AX = G H

DFF

D Q

DFF

D Q

G H

A

A

XClk

Page 18: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

18

State Machines in Digital Hardware

• I’ve skipped many details and nuances– see ECE 223 course notes

• State machines can get very complicated– often don’t work out states in this detail– let synthesis tools do it

Page 19: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

19

Optimization of State Machines

• Outside the scope of this tutorial• Summary

– reduce number of states by combining states, while preserving equivalent functionality

– bit encoding can affect the size of the circuitry generated to implement it

Page 20: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

20

Ring Counter• Is this a state machine?

Yes: every sequential circuit is a state machine

Clk

DFF

D Q

S C

Init

DFF

D Q

S C

DFF

D Q

S C

DFF

D Q

S C

Page 21: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

21

Back to Register Transfer Level (RTL) Logic

Register Register

Clock

Cloudof Logic

RegisterCloudof Logic

DataIn

DataOut

Feedback

Combinational

Sequential

Page 22: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

22

Hardware Description Languages (HDLs)

• HDLs describes in text a digital circuit• Examples

– VHDL (we will look at this next time)– Verilog– AHDL– JHDL

Page 23: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

23

Hardware Description Languages (HDLs)

• schematics are useful for…– drawing high level diagrams– manually working out simple pieces of logic

• HDLs are useful for…– describing complex digital systems

• HDLs are not...– software programming languages (C, Java,

assembly, etc.)

Page 24: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

24

Think Digital

• When designing a digital system in VHDL, it is important to remember the relation between code constructs and actual hardware

Page 25: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

25

HDL Design Flow1. Concept, requirements analysis2. High level design3. Functional implementation (need not be synthesizable)4. Functional simulation (3 -> 4 until functionality is good)5. Synthesizable implementation6. Synthesizable simulation (6 -> 5 until functionality is good)7. Timing simulation (7 -> 5 until timing is good; this step I often

bypassed in practice)8. Synthesis

• design is compiled to hardware• we will cover this in more detail later• 8 -> 5 if design doesn’t compile or doesn’t fit

9. Testing in hardware (9 -> 5 if something is wrong)

Page 26: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

26

What does “synthesizable” mean?

• Synthesizable means that a given design can be compiled into hardware– FPGA (reprogrammable ASIC)– ASIC

• A non-synthesizable design can be simulated in software and is useful for– working out functionality– testing out concepts– test benches (covered in detail later)

Page 27: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

27

Levels of Abstraction

• Behavioural• Dataflow• Structural

Page 28: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

28

Components of a VHDL File• library

– ieee, etc.• use• entity

– defines the interface• architecture

– defines the functionality• component

– reusable functionality• multiple entity/architectures in one file

Page 29: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

29

Why do we use IEEE libraries?

• standard VHDL libraries are limited to two values: 0 and 1

• this is fine for theory, but in practice a physical wire can have other values

• more on this in later tutorials

Page 30: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

30

Inputs and Outputs

• declared in the entity• the “pins” of the hardware block• can only be input, output, or I/O• output pins cannot be read from

– for example, if I assign a value to an output pin I cannot “read” that value back in another place

– output pins are like black holes in this way

Page 31: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

31

Signals

• Signals are the internal “wires” of your design

• Can be assigned a value, or have their value read

• Signals can be read in multiple places, but assigned in only one place– “cannot have multiple output pins driving a

wire”

Page 32: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

32

Buses

• Provide an easy way to group multiple signals or ports

Page 33: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

33

Combinational Logic

• In VHDL: “Concurrent Statements”• Remember: all functionality is defined

within architecture block• Order doesn’t matter• Types of concurrent statements

– assignments– conditional assignments– processes

Page 34: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

34

Combinational Assignments

destination <= source_logic;

examples:

X <= A AND B;Y <= NOT (A AND B);Z <= A XOR B AND C NOT B;

Page 35: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

35

Conditional Assignmentsdestination <= source_logic_1 when condition_1

else source_logic_2 when condition_2else source_logic_3;

example:

X <= A AND B when Sel = “00” else NOT (A AND B) when Sel = “01” else A XOR B when Sel(0) & Sel(1) = “10”

Page 36: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

36

Conditional Assignment: A MUX

• Conditional assignments are modelled physically as a multiplexer

00

01

10

11

X <= A AND B when Sel = “00”else NOT (A AND B) when Sel = “01”else A XOR B when Sel(0) & Sel(1) = “10”

Sel(0) Sel(1)

Sel

AB

AB

X

Page 37: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

37

Brackets and The & Operator

• Brackets– used to reference parts of buses

• & Operator– signal concatenation operator– used for constructing buses out of single wire

signals, or parts of other buses

Page 38: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

38

Processes

• Contain chunks of VHDL code• Can be purely combinational• Most useful for sequential logic

– controlled by a clock• processes are executed in parallel, in any

order• Processes can optionally be named

Page 39: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

39

Process Statement

[process_name:] process (sensitivity_list)    declarationsbegin    sequential_statementsend process;

Page 40: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

40

Sequential Logic

• In VHDL: “Sequential Statements”• Within a process, statements execute

sequentially– important to remember that logic is tied back

to underlying hardware

Page 41: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

41

If … Then …Else Statement• Like the concurrent “when … else” statement,

modelled as a multiplexer

    if first_condition then        statements    elsif second_condition then       statements    else       statements    end if;

Page 42: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

42

MUX with an If Statement    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;        end if;    end process;

Page 43: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

43

MUX with an If Statement

• Note that this mux is a combinational mux– i.e., not governed by a clock

A

B

C

D

00

01

10

11

Sel(0) Sel(1)

Y

Page 44: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

44

Clocked Processes• Or: “Sequential Processes”• Consider a “clocked mux”:    process    begin wait until rising_edge(Clk);        if Sel = "00" then            Y <= A;        elsif Sel = "01" then            Y <= B;        elsif Sel = "10" then            Y <= C;        elsif then            Y <= D;        end if;    end process;

Page 45: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

45

Clocked Processes• Or: “Sequential Processes”• Consider a “clocked mux”:    process    begin wait until rising_edge(Clk);        if Sel = "00" then            Y <= A;        elsif Sel = "01" then            Y <= B;        elsif Sel = "10" then            Y <= C;        elsif then            Y <= D;        end if;    end process;

A

B

C

D

00

01

10

11

Sel(0) Sel(1)

Y

DFF

D Q

Clk

Page 46: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

46

Clocked Processes

• Statements are essentially executed in series

• Important to always keep in mind underlying hardware

Page 47: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

47

Clocked Processes• Consider:    process    begin wait until rising_edge(Clk);

        if Sel = ‘0’ then            Y <= A; else            Y <= B;        end if;

        if Sel = ‘0’ then            Z <= B; else            Z <= A;        end if;    end process;

Page 48: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

48

Clocked Processes• Consider:    process    begin wait until rising_edge(Clk);

        if Sel = ‘0’ then            Y <= A; else            Y <= B;        end if;

        if Sel = ‘0’ then            Z <= B; else            Z <= A;        end if;    end process;

A

B

0

1

Sel

Y

DFF

D Q

Clk

B

A

0

1

Sel

Z

DFF

D Q

Clk

Page 49: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

49

Clocked Processes• This code produces the same hardware:    process    begin wait until rising_edge(Clk);

        if Sel = ‘0’ then            Y <= A; Z <= B; else            Y <= B;            Z <= A;        end if;    end process;

A

B

0

1

Sel

Y

DFF

D Q

Clk

B

A

0

1

Sel

Z

DFF

D Q

Clk

Page 50: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

50

Remember

• Always consider the underlying hardware!– ask yourself: what does the VHDL code I’m

writing actually represent?

Page 51: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

51

Preview of Next Tutorial

• Intermediate VHDL– sequential statements continued

• more on registers, case, loops– latch inference– loops– other signal values besides ‘0’ and ‘1’– more VHDL data types– attributes, type definitions

Page 52: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

52

Summary

• State Machines• HDL design flow• Format of a VHDL file• Combinational statements

– assignments, conditionals, when … else• Sequential statements

– processes, if … then … else

Page 53: 1 ASIC 120: Digital Systems and Standard-Cell ASIC Design Tutorial 2: Introduction to VHDL February 1, 2006

53

UW ASIC Design Team• www.asic.uwaterloo.ca• reference material

– Prof. Hamel’s Winter 2005 ECE 223 course noteshttp://www.ece.uwaterloo.ca/~ece223/jhamel/

– Accolade VHDL reference (excellent!):http://www.acc-eda.com/vhdlref/

– Bryce Leung’s tutorials (UW ASIC website)– Mike Goldsmith’s tutorials (UW ASIC website)– your course notes

• my contact info:Jeff Wentworth, [email protected]