real world fpga design with verilog

75
Real World FPGA design with Verilog Miloš Milovanović miloshm @yahoo.com Jovan Popović josars @ galeb . etf . bg .ac. yu Veljko Milutinović vm @ etf . bg .ac. yu

Upload: tory

Post on 11-Feb-2016

156 views

Category:

Documents


4 download

DESCRIPTION

Real World FPGA design with Verilog. Milo š Milovanović [email protected] Jovan Popović [email protected] Veljko Milutinović [email protected]. Literature. - Real World FPGA Design with Verilog by Ken Coffman, Prentice Hall PTR - On-line Verilog HDL Quick Reference Guide - PowerPoint PPT Presentation

TRANSCRIPT

Page 2: Real World  FPGA design  with  Verilog

2

Literature- Real World FPGA Design with Verilog by Ken Coffman, Prentice Hall PTR

- On-line Verilog HDL Quick Reference Guide

by Stuart Sutherland titan.etf.bg.ac.yu/~gvozden/VLSI/

Miloš Milovanović/75

Page 3: Real World  FPGA design  with  Verilog

3

Field Programmable Gate Array design

Verilog – designed as a simulation and test language

Real World - &¨!¸!!”#$%&@#$%

/75Miloš Milovanović

Page 4: Real World  FPGA design  with  Verilog

4

A day in the life of an FPGA Silicon Designer

/75Miloš Milovanović

Page 5: Real World  FPGA design  with  Verilog

5

Design must be: Understandable to other designers

Logically correct

Perform under worst-case conditions of temperature and process variation

/75Miloš Milovanović

Page 6: Real World  FPGA design  with  Verilog

6

Design must be: Reliable

Testable and can be proven to meet the specification

Do not exceed the power consumption goals

(a battery-operated circuit)Miloš Milovanović

/75

Page 7: Real World  FPGA design  with  Verilog

7

Understandable Design

Miloš Milovanović /75

Page 8: Real World  FPGA design  with  Verilog

8

FPGA Architecture

Miloš Milovanović/75

Page 9: Real World  FPGA design  with  Verilog

9

Xilinx 4K Family CLB Architecture

Miloš Milovanović/75

Page 10: Real World  FPGA design  with  Verilog

10

Trivial Overheat Detector Example

Miloš Milovanović

“Big Brother” [email protected]

[email protected]

/75

Page 11: Real World  FPGA design  with  Verilog

11

Solution:

Miloš Milovanović/75

Page 12: Real World  FPGA design  with  Verilog

12Miloš Milovanović /75

Page 13: Real World  FPGA design  with  Verilog

13Miloš Milovanović /75

Page 14: Real World  FPGA design  with  Verilog

14

Simulation

Miloš Milovanović/75

Page 15: Real World  FPGA design  with  Verilog

15

Assignments Concurrent

Initial: A=B=C=E=1

A <= B + C;D <= A + E;

After assignment:A=2, D=2

Sequential

Initial: A=B=C=E=1

A = B + C;D = A + E;

After assignment:A=2, D=3

Miloš Milovanović/75

Page 16: Real World  FPGA design  with  Verilog

16

Module – the building block

module module_name (port_name, port_name, ... );

module_itemsendmodule

module module_name (.port_name (signal_name ), .port_name (signal_name ), ... );

module_itemsendmodule

Miloš Milovanović/75

Page 17: Real World  FPGA design  with  Verilog

17

Module Port Declarationsport_direction [port_size] port_name,

port_name, ... ;

port_direction – input, output, inoutport_size is a range from [ msb : lsb ]

Example1: Example2:parameter word = 32; input [15:12] addr;input [word-1:0] addr;

Miloš Milovanović/75

Page 18: Real World  FPGA design  with  Verilog

18

Data Type Declarations 1register_type [size] variable_name ,

variable_name , ... ;register_type [size] memory_name [array_size];

register_type:reg - unsigned variable of any bit sizeinteger - signed 32-bit variabletime - unsigned 64-bit variablereal or realtime - double-precision floating point variable

/75Miloš Milovanović

Page 19: Real World  FPGA design  with  Verilog

19

Data Type Declarations 2

net_type [size] #(delay) net_name , net_name , ... ;

net_type: wire or tri - Simple Interconnecting Wirewor or trior - Wired outputs OR together

wand or triand - Wired outputs AND togetherMiloš Milovanović

/75

Page 20: Real World  FPGA design  with  Verilog

20

Data Type Declarations 3#delay or #(delay) - Single delay for all output transitions

#(delay, delay) - Separate delays for (rising, falling) transitions

Miloš Milovanović/75

Page 21: Real World  FPGA design  with  Verilog

21

Data Type Declarations 4- wire a, b, c; - tri [7:0] data_bus; - reg [1:8] result; // an 8-bit // unsigned variable - reg [7:0] RAM [0:1023];

8-bits wide, with 1K of addresses- wire #(2.4,1.8) carry;a net with rise, fall

delays

/75Miloš Milovanović

Page 22: Real World  FPGA design  with  Verilog

22

Assign statement Continuous (combinational) logic

- net_type [size] net_name;assign #(delay) net_name = expression;

- net_type [size] net_name = expression;

assign out = in1 & in2; assign bidir = OE ? out : 1’bz;

Miloš Milovanović/75

Page 23: Real World  FPGA design  with  Verilog

23

Procedural Blocks

type_of_block @(sensitivity_list) statement_group: group_name local_variable_declarations

timing_control procedural_statements end_of_statement_group

Miloš Milovanović/75

Page 24: Real World  FPGA design  with  Verilog

24

Type of block

initial – process statements one time

always – process statements repeatedly

Miloš Milovanović/75

Page 25: Real World  FPGA design  with  Verilog

25

Sensitivity list OPTIONAL Signals Posedge – rising-edge triggered Negedge – falling-edge triggered

example:always @ (posedge clk or posedge rst)begin … end

Miloš Milovanović/75

Page 26: Real World  FPGA design  with  Verilog

26

Statement group

begin – end – the sequential block

fork – join – statements are evaluated concurrently

/75Miloš Milovanović

Page 27: Real World  FPGA design  with  Verilog

27

Exampleinitial

fork #10 bus = 16'h0000; #20 bus = 16'hC5A5; #30 bus = 16'hFFAA;

join

/75Miloš Milovanović

Page 28: Real World  FPGA design  with  Verilog

28

Examplealways

begin#10 bus = 16'h0000; #20 bus = 16'hC5A5; #30 bus = 16'hFFAA;

end

/75Miloš Milovanović

Page 29: Real World  FPGA design  with  Verilog

29

1

Miloš Milovanović

Example

/75

Page 30: Real World  FPGA design  with  Verilog

30

Verilog Hierarchymodule_name

instance_name(port_list);

Miloš Milovanović/75

Page 31: Real World  FPGA design  with  Verilog

31

Named & Positional Assignment

Miloš Milovanović/75

Page 32: Real World  FPGA design  with  Verilog

32

Built-in Logic Primitives and, or, nand, nor, xor, nxor bufif0, bufif1, notif0, notif1

Miloš Milovanović/75

Page 33: Real World  FPGA design  with  Verilog

33Miloš Milovanović /75

Page 34: Real World  FPGA design  with  Verilog

34

Latches and Flipflops Clocked D flipflop

Miloš Milovanović /75

Page 35: Real World  FPGA design  with  Verilog

35

Basic Latch

Miloš Milovanović/75

Page 36: Real World  FPGA design  with  Verilog

36Miloš Milovanović

/75

Page 37: Real World  FPGA design  with  Verilog

37Miloš Milovanović

test_out2 <= 0;

/75

Page 38: Real World  FPGA design  with  Verilog

38

Blocking and Nonblocking Assignments

Miloš Milovanović /75

Page 39: Real World  FPGA design  with  Verilog

39

Blocking assignmentsare order sensitive

Miloš Milovanović/75

Page 40: Real World  FPGA design  with  Verilog

40

Nonblocking Assignment

Miloš Milovanović/75

Page 41: Real World  FPGA design  with  Verilog

41

Miscellaneous Verilog Syntax Items

Numbers

- default: 32 bits wide- size’base value- underscore is legal- X is undefined- Z is the high impedance

Miloš Milovanović/75

Page 42: Real World  FPGA design  with  Verilog

42

Number examples

Miloš Milovanović/75

Page 43: Real World  FPGA design  with  Verilog

43

Forms of Negation

! – logical negation

~ - bitwise negation

Miloš Milovanović/75

Page 44: Real World  FPGA design  with  Verilog

44Miloš Milovanović

/75

Page 45: Real World  FPGA design  with  Verilog

45

Forms of AND & is a bitwise AND

&& is a logical AND (true/false)

Miloš Milovanović/75

Page 46: Real World  FPGA design  with  Verilog

46

Forms of OR | is a bitwise OR

|| is a logical OR (true/false)

Miloš Milovanović/75

Page 47: Real World  FPGA design  with  Verilog

47

AND/OR examlpe

Miloš Milovanović/75

Page 48: Real World  FPGA design  with  Verilog

48Miloš Milovanović /75

Page 49: Real World  FPGA design  with  Verilog

49

Equality Operators == is logical equalityhave an unknown (x) result if any of the compared bits are x or z

=== is case equalitylooks for exact match of bits

including x’s and z’s and return only true or false

Miloš Milovanović/75

Page 50: Real World  FPGA design  with  Verilog

50

Not equal operators

!= opposite to ==

!== opposite to ===

Miloš Milovanović/75

Page 51: Real World  FPGA design  with  Verilog

51Miloš Milovanović /75

Page 52: Real World  FPGA design  with  Verilog

52Miloš Milovanović

/75

Page 53: Real World  FPGA design  with  Verilog

53Miloš Milovanović /75

Page 54: Real World  FPGA design  with  Verilog

54

Also supported greater than (>)

less than (<)

greater than or equal (>=)

less than or equal (<=)Miloš Milovanović

/75

Page 55: Real World  FPGA design  with  Verilog

55

Shift operators

>> n – right shift (divide by 2n)

<< n – left shift (multiple by 2n)

Operating on a value which contains an x or z

gives an x result in all bit positions.Miloš Milovanović

/75

Page 56: Real World  FPGA design  with  Verilog

56

Shift operations example

Miloš Milovanović/75

Page 57: Real World  FPGA design  with  Verilog

57Miloš Milovanović

/75

Page 58: Real World  FPGA design  with  Verilog

58Miloš Milovanović

/75

Page 59: Real World  FPGA design  with  Verilog

59

Conditional Operator

out <= expression ? true_assignment : false_assignment;

- Special case: expression = x or z calculates every single bit

Miloš Milovanović/75

Page 60: Real World  FPGA design  with  Verilog

60Miloš Milovanović

/75

Page 61: Real World  FPGA design  with  Verilog

61

Math Operatorsaddition (+), subtraction (-), multiplication (*), division (/), modulus (%)

synthesis tool probably limits multiplication and division to constant powers of two

verilog assumes all reg and wire variables are unsigned

Miloš Milovanović/75

Page 62: Real World  FPGA design  with  Verilog

62

Parameters used in modules where they are

defined

can be changed by higher-level modules

cannot be changed at run timeMiloš Milovanović

/75

Page 63: Real World  FPGA design  with  Verilog

63Miloš Milovanović

/75

Page 64: Real World  FPGA design  with  Verilog

64Miloš Milovanović

/75

Page 65: Real World  FPGA design  with  Verilog

65Miloš Milovanović /75

Page 66: Real World  FPGA design  with  Verilog

66

Concatenations

Miloš Milovanović /75

Page 67: Real World  FPGA design  with  Verilog

67

Programming Statementsif, casecasez, casexforever, repeat(number), while, for

initial begin clk = 0; #1000 forever #25 clk = ~clk;

end

Miloš Milovanović /75

Page 68: Real World  FPGA design  with  Verilog

68

Testing…Compiler directives:

‘define, ‘ifdef, ‘else, ‘endif, ‘undef

‘include

‘timescale unit/precision example: ‘timescale 1ns/0.5ns

/75Miloš Milovanović

Page 69: Real World  FPGA design  with  Verilog

69

System Tasks starts with $

$finish – terminate

$stop – (time out)

/75Miloš Milovanović

Page 70: Real World  FPGA design  with  Verilog

70

System Tasks $display(format, vars…) - printf

$write(format, vars…) - $display + ‘\n’

$timeformat

$time

/75Miloš Milovanović

Page 71: Real World  FPGA design  with  Verilog

71

System Tasks $monitor (signal list and formatting)

$monitoron

$monitoroff

/75Miloš Milovanović

Page 72: Real World  FPGA design  with  Verilog

72

System Tasks$dumpfile(“filename”)

$dumpvars

$dumpall

$dumpvars(…)

$dumplimit(size)

/75Miloš Milovanović

Page 73: Real World  FPGA design  with  Verilog

73

System Tasks

$readmemh(“filename”, memory_name)

$readmemb(“filename”, memory_name)

/75Miloš Milovanović

Page 74: Real World  FPGA design  with  Verilog

74

Watch for those alligators!

/75Miloš Milovanović

Page 75: Real World  FPGA design  with  Verilog

Real World FPGA design

with Verilog

Miloš Milovanović[email protected]

Jovan Popović[email protected]

Veljko Milutinović[email protected]