Vous êtes sur la page 1sur 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

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

2 /75

Field Programmable Gate Array design Verilog designed as a simulation and test language Real World - &!!! #$%&@#$%

Milo Milovanovi

3 /75

A day in the life of an FPGA Silicon Designer

Milo Milovanovi

4 /75

Design must be:


Understandable to other designers Logically correct Perform under worst-case conditions of temperature and process variation
Milo Milovanovi

5 /75

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

6 /75

Understandable Design

Milo Milovanovi

7 /75

FPGA Architecture

Milo Milovanovi

8 /75

Xilinx 4K Family CLB Architecture

Milo Milovanovi

9 /75

Trivial Overheat Detector Example


josars@galeb.etf.bg.ac.yu Big Brother vm@etf.bg.ac.yu

Milo Milovanovi

10 /75

Solution:

Milo Milovanovi

11 /75

Milo Milovanovi

12 /75

Milo Milovanovi

13 /75

Simulation

Milo Milovanovi

14 /75

Assignments
Concurrent Initial: A=B=C=E=1 A <= B + C; D <= A + E; After assignment: A=2, D=2 Milo Milovanovi Sequential Initial: A=B=C=E=1 A = B + C; D = A + E; After assignment: A=2, D=3
15 /75

Module

the building block

module module_name (port_name, port_name, ... ); module_items endmodule module module_name (.port_name (signal_name ), .port_name (signal_name ), ... ); module_items Milo Milovanovi 16 /75 endmodule

Module Port Declarations


port_direction [port_size] port_name, port_name, ... ; port_direction input, output, inout port_size is a range from [ msb : lsb ] Example1: Example2: parameter word = 32; input [15:12] addr; input [word-1:0] addr;
Milo Milovanovi
17 /75

Data Type Declarations 1


register_type [size] variable_name , variable_name , ... ; register_type [size] memory_name [array_size]; register_type: reg - unsigned variable of any bit size integer - signed 32-bit variable time - unsigned 64-bit variable real or realtime - double-precision floating point variable Milo Milovanovi

18 /75

Data Type Declarations 2


net_type [size] #(delay) net_name , net_name , ... ; net_type: wire or tri - Simple Interconnecting Wire wor or trior - Wired outputs OR together wand or triand - Wired outputs AND together
Milo Milovanovi
19 /75

Data Type Declarations 3


#delay or #(delay) - Single delay for all output transitions #(delay, delay) - Separate delays for (rising, falling) transitions

Milo Milovanovi

20 /75

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
Milo Milovanovi
21 /75

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;
22 /75

Milo Milovanovi

Procedural Blocks
type_of_block @(sensitivity_list) statement_group: group_name local_variable_declarations timing_control procedural_statements end_of_statement_group

Milo Milovanovi

23 /75

Type of block
initial always process statements one time process statements repeatedly

Milo Milovanovi

24 /75

Sensitivity list
OPTIONAL Signals Posedge rising-edge triggered Negedge falling-edge triggered example: always @ (posedge clk or posedge rst) begin end
Milo Milovanovi
25 /75

Statement group
begin end the sequential block

fork join statements are evaluated concurrently

Milo Milovanovi

26 /75

Example
initial fork #10 bus = 16'h0000; #20 bus = 16'hC5A5; #30 bus = 16'hFFAA; join
Milo Milovanovi

27 /75

Example
always begin #10 bus = 16'h0000; #20 bus = 16'hC5A5; #30 bus = 16'hFFAA; end
Milo Milovanovi

28 /75

Example

Milo Milovanovi

29 /75

Verilog Hierarchy
module_name instance_name(port_list);

Milo Milovanovi

30 /75

Named & Positional Assignment

Milo Milovanovi

31 /75

Built-in Logic Primitives


and, or, nand, nor, xor, nxor bufif0, bufif1, notif0, notif1

Milo Milovanovi

32 /75

Milo Milovanovi

33 /75

Latches and Flipflops


Clocked D flipflop

Milo Milovanovi

34 /75

Basic Latch

Milo Milovanovi

35 /75

Milo Milovanovi

36 /75

test_out2 <= 0;

Milo Milovanovi

37 /75

Blocking and Nonblocking Assignments

Milo Milovanovi

38 /75

Blocking assignments are order sensitive

Milo Milovanovi

39 /75

Nonblocking Assignment

Milo Milovanovi

40 /75

Miscellaneous Verilog Syntax Items


Numbers

default: 32 bits wide size base value underscore is legal X is undefined Z is the high impedance
41 /75

Milo Milovanovi

Number examples

Milo Milovanovi

42 /75

Forms of Negation
! logical negation

~ - bitwise negation

Milo Milovanovi

43 /75

Milo Milovanovi

44 /75

Forms of AND
& is a bitwise AND && is a logical AND (true/false)

Milo Milovanovi

45 /75

Forms of OR
| is a bitwise OR || is a logical OR (true/false)

Milo Milovanovi

46 /75

AND/OR examlpe

Milo Milovanovi

47 /75

Milo Milovanovi

48 /75

Equality Operators
== is logical equality have an unknown (x) result if any of the compared bits are x or z === is case equality looks for exact match of bits including x s and z s and return only true or false
Milo Milovanovi

49 /75

Not equal operators


!= opposite to == !== opposite to ===

Milo Milovanovi

50 /75

Milo Milovanovi

51 /75

Milo Milovanovi

52 /75

Milo Milovanovi

53 /75

Also supported
greater than (>) less than (<) greater than or equal (>=) less than or equal (<=)
Milo Milovanovi
54 /75

Shift operators
>> n << n right shift (divide by 2n) 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

55 /75

Shift operations example

Milo Milovanovi

56 /75

Milo Milovanovi

57 /75

Milo Milovanovi

58 /75

Conditional Operator
out <= expression ? true_assignment : false_assignment;

- Special case: expression = x or z


calculates every single bit
Milo Milovanovi

59 /75

Milo Milovanovi

60 /75

Math Operators
addition (+), 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
61 /75

Parameters
used in modules where they are defined can be changed by higher-level modules cannot be changed at run time
Milo Milovanovi

62 /75

Milo Milovanovi

63 /75

Milo Milovanovi

64 /75

Milo Milovanovi

65 /75

Concatenations

Milo Milovanovi

66 /75

Programming Statements
if, case casez, casex forever, repeat(number), while, for initial begin clk = 0; #1000 forever #25 clk = ~clk; end
Milo Milovanovi
67 /75

Testing
Compiler directives:
define, ifdef, else, endif, undef include timescale unit/precision example: timescale 1ns/0.5ns
Milo Milovanovi
68 /75

System Tasks
starts with $ $finish $stop terminate (time out)

Milo Milovanovi

69 /75

System Tasks
$display(format, vars ) - printf $write(format, vars ) - $display + \n $timeformat $time
Milo Milovanovi
70 /75

System Tasks
$monitor (signal list and formatting) $monitoron $monitoroff

Milo Milovanovi

71 /75

System Tasks
$dumpfile( filename ) $dumpvars $dumpall $dumpvars( ) $dumplimit(size)
Milo Milovanovi
72 /75

System Tasks
$readmemh( filename , memory_name) $readmemb( filename , memory_name)

Milo Milovanovi

73 /75

Watch for those alligators!

Milo Milovanovi

74 /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

Vous aimerez peut-être aussi