Lecture 2

15
III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 1 ECE2072/TRC2300/TEC2172 Digital Systems: Hardware Description Languages (Sec3.6 Katz2e) based on textbook Contemporary Logic Design, 2 nd Edition by R. H. Katz and G. Borriello COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University pursuant to Part VB of the Copyright Act 1968 (the Act). The material in this communication may be subject to copyright under the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act. Do not remove this notice.

description

Lecture 2

Transcript of Lecture 2

Page 1: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 1

ECE2072/TRC2300/TEC2172 Digital Systems:Hardware Description Languages

(Sec3.6 Katz2e) based on textbook

Contemporary Logic Design, 2nd Editionby R. H. Katz and G. Borriello

COMMONWEALTH OF AUSTRALIACopyright Regulations 1969

WARNING

This material has been reproduced and communicated to you by or on behalf of Monash University pursuant to Part VB of the Copyright Act 1968 (the Act).

The material in this communication may be subject to copyright under the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act.

Do not remove this notice.

Page 2: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 2

Hardware description languages

Describe hardware at varying levels of abstractionStructural description

textual replacement for schematichierarchical composition of modules from primitives

Behavioral/functional descriptiondescribe what module does, not howsynthesis generates circuit for module

Simulation semantics

Page 3: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 3

HDLs

ISP (circa 1977) - research project at CMUsimulation, but no synthesis

Abel (circa 1983) - developed by Data-I/Otargeted to programmable logic devicesnot good for much more than state machines

Verilog (circa 1985) - developed by Gateway (absorbed by Cadence)similar to Pascal and Cdelays is only interaction with simulatorfairly efficient and easy to writeIEEE standard

VHDL (circa 1987) - DoD sponsored standardsimilar to Ada (emphasis on re-use and maintainability)simulation semantics visiblevery general but verboseIEEE standard

Page 4: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 4

Verilog

Supports structural and behavioral descriptionsStructural

explicit structure of the circuite.g., each logic gate instantiated and connected to others

Behavioralprogram describes input/output behavior of circuitmany structural implementations could have same behaviore.g., different implementation of one Boolean function

We’ll mostly be using behavioral Verilogrely on schematic when we want structural descriptions

Page 5: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 5

Example: XOR Gate

Write a structural and behavioral Verilog module for the following XOR gate:

a

b

out

Page 6: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 6

module xor_gate (out, a, b);input a, b;output out;wire abar, bbar, t1, t2;

inverter invA (abar, a);inverter invB (bbar, b);and_gate and1 (t1, a, bbar);and_gate and2 (t2, b, abar);or_gate or1 (out, t1, t2);

endmodule

Structural model a

b

out

Page 7: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 7

module xor_gate (out, a, b);input a, b;output out;reg out;

always @(a or b) begin#6 out = a ^ b;

end

endmodule

Simple behavioral modelalways block:

statements between begin-end are run whenever signal in sensitivity listchanges

specifies when block is executed ie. triggered by which signals

a

b

out

delay from input changeto output change

Page 8: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 8

module xor_gate (out, a, b);input a, b;output out;reg out;

assign #6 out = a ^ b;

endmodule

Simple behavioral model

Continuous assignment statement:shorthand for always block: executed whenever operands change

delay from input changeto output change

simulation register -keeps track ofvalue of signal

Page 9: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 9

module testbench (x, y);output x, y;reg [1:0] cnt;

initial begincnt = 0;repeat (4) begin#10 cnt = cnt + 1;$display ("@ time=%d, x=%b, y=%b, cnt=%b",

$time, x, y, cnt); end#10 $finish;

end

assign x = cnt[1];assign y = cnt[0];

endmodule

Driving a simulation through a “testbench”

2-bit vector

initial block executed only once at startof simulation

directive to stop simulation

print to a console

Page 10: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 10

Complete simulation

Instantiate stimulus component and device to test in a schematic

a

b

ztest-bench

xy

Page 11: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 11

module Compare1 (Equal, Alarger, Blarger, A, B);input A, B;output Equal, Alarger, Blarger;

assign #5 Equal = (A & B) | (~A & ~B);assign #3 Alarger = (A & ~B);assign #3 Blarger = (~A & B);

endmodule

Comparator example

Page 12: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 12

module life (n0, n1, n2, n3, n4, n5, n6, n7, self, out);input n0, n1, n2, n3, n4, n5, n6, n7, self;output out;reg out;reg [7:0] neighbors;reg [3:0] count;reg [3:0] i;

assign neighbors = {n7, n6, n5, n4, n3, n2, n1, n0};

always @(neighbors or self) begincount = 0;for (i = 0; i < 8; i = i+1) count = count + neighbors[i];out = (count == 3);out = out | ((self == 1) & (count == 2));

end

endmodule

More complex behavioral model

Page 13: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 13

Hardware description languages vs. programming languages

Program structureinstantiation of multiple components of the same typespecify interconnections between modules via schematichierarchy of modules (only leaves can be HDL in Aldec ActiveHDL)

Assignmentcontinuous assignment (logic always computes)propagation delay (computation takes time)timing of signals is important (when does computation have its effect)

Data structuressize explicitly spelled out - no dynamic structures no pointers

Parallelismhardware is naturally parallel (must support multiple threads)assignments can occur in parallel (not just sequentially)

Page 14: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 14

Hardware description languages and combinational logic

Modules - specification of inputs, outputs, bidirectional, and internal signalsContinuous assignment - a gate’s output is a function of its inputs at all times (doesn’t need to wait to be "called")Propagation delay- concept of time and delay in input affecting gate outputComposition - connecting modules together with wiresHierarchy - modules encapsulate functional blocks

Page 15: Lecture 2

III - Working with Combinational Logic © Copyright 2004, Gaetano Borriello and Randy H. Katz 15

Hardware description languages summary

Provide a way to describe logic circuits texturally and take advantage of software constructs including variables, subprocedures, loops and conditional statementsStructural and behavioural description of functionsParallelism – continuous assignment statementHDL allows designs to be simulated before construction:

Designs are easily modifiedShortens the development/debug cycle

Can be synthesized directly into hardware