Introduction to Verilog
-
Upload
rogan-franco -
Category
Documents
-
view
82 -
download
0
description
Transcript of Introduction to Verilog
![Page 1: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/1.jpg)
GWU – ECE 2140 Spring 2012
Revised by Scott Trocchia
![Page 2: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/2.jpg)
What are FPGAs? What’s inside them? Brief Verilog History What is Verilog? Levels of Verilog Coding Modules Lots of Operators Verilog Modeling
◦ Always blocks◦ Continuous assignments
![Page 3: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/3.jpg)
FPGA = Field-Programmable Gate Array◦ Include space for lots of logic gates◦ Can be programmed…
…and reprogrammed ~100,000 times◦ Benefits include:
Cheap Easy to program (barring errors) Short amount of time for commercialization etc.
![Page 4: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/4.jpg)
A: This
Let’s go back to 1984…
![Page 5: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/5.jpg)
A world without Verilog…◦ … was boring
In 1984, the language was created by Gateway Design Automation, Inc.
![Page 6: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/6.jpg)
Hardware Description Language◦ Not meant to be understood for your operating
system (Windows, Mac, Linux)
Used to describe digital systems, such as◦ Register (memory)◦ CPU◦ Network switch
Built-in functions: not, and, nand, nor, or, xor, xnor, buf, …
![Page 7: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/7.jpg)
Behavioral level◦ A functional representation◦ How does my circuit work?
Register-Transfer Level (RTL)◦ How is data transferred from inputs to outputs?
Gate Level◦ What gates are contained within my circuit?
![Page 8: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/8.jpg)
module half_adder(x, y, sum, carry);
input x;input y;output sum;output carry;
assign sum = x ^ y;assign carry = x & y;
endmodule
module half_adder(A, B, Sum, C_out);
input A;input B;output Sum;output C_out;
xor(Sum, A, B);and(C_out, A, B);
endmodule
![Page 9: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/9.jpg)
module Multiplexer(In, Select, Out);
input [3:0] In;input [1:0] Select;output reg Out;
always @ (*) begincase (Select)
2'b00: Out <= In[0];2'b01: Out <= In[1];2'b10: Out <= In[2];2'b11: Out <= In[3];
endcaseendendmodule
Verilog is case-sensitive, so be mindful!
![Page 10: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/10.jpg)
reg – register – stores a value wire – used for connecting logic
Number representation◦ Typical format is: (#bits)’(RADIX)(number)
RADIX: b=binary, h=hex, d=decimal◦ Example: 4’b1110 = 4’hE = 4’d14◦ Negative numbers in 2’s complement
![Page 11: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/11.jpg)
• Arithmetic• Logical• Relational• Equality• Reduction• Shift• Concatenation• Conditional
![Page 12: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/12.jpg)
Symbol
Arithmetic operation
* Multiply
/ Divide
+ Add
- Subtract
% Modulus
![Page 13: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/13.jpg)
Relational operators◦ Same as C◦ a < b, a > b, a <= b, a >= b◦ 1-bit result: 0 if false, 1 if true
Equality operators◦ a == b◦ a != b◦ Compared bit-by-bit◦ 1-bit result: 0 (false), 1 (true)
![Page 14: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/14.jpg)
Logical operators
Bit-wise operators
operator
Description
! Logical negation
&& Logical and
|| Logical or
operator Description
~ NOT
& AND
| OR
^ XOR
^~ or ~^ XNOR
![Page 15: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/15.jpg)
• Shift– Left shift <<– Right shift >>
• Concatenation– {2’b10, 2’b01} equals 4’b1001
– reg A,B,C;A = 1'b0;B = 2'b11;C = {B,A};C = {A,B}; Will these operations give different results?
![Page 16: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/16.jpg)
Conditional Operators◦ Conditional_expression ? True_expr : false expr
Example:◦ x = 0; q = 0◦ (if x < 0) ? (q = 0) : (q = 1);
![Page 17: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/17.jpg)
Part 2
![Page 18: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/18.jpg)
• Executes loop over and over• Can only assign to registers in always
blocks• 2 types
– Level triggered - latch– Edge triggered – flip-flop
always @ (posedge Clk) beginif (Reset) begin
data <= 0;end else begin
data <= q_in;end
end
![Page 19: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/19.jpg)
• Always blocks can be used for combinational logic too
always @ (*) begincase (Select)
2'b00: out <= A;2'b01: out <= B;2'b10: out <= C;2'b11: out <= D;
endcaseend
![Page 20: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/20.jpg)
Sequential assignment inside block◦ Remember, this is HARDWARE◦ Example:
assume A=B=0 before always block executesalways @ (posedge Clk) beginA <= 1;B <= A;
end What will B equal after always block execution?
![Page 21: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/21.jpg)
Can only be assigned to wires
assign A = B^Y;
assign C = Sel ? TrueVal : FalseVal;
![Page 22: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/22.jpg)
? ? ?
![Page 23: Introduction to Verilog](https://reader036.fdocuments.in/reader036/viewer/2022081506/56813804550346895d9fc0eb/html5/thumbnails/23.jpg)
http://en.wikipedia.org/wiki/Field-programmable_gate_array
http://www.asic-world.com/verilog/intro1.html#Introduction
http://en.wikipedia.org/wiki/Verilog “Verilog – Representation of Number Literal
s”, http://web.engr.oregonstate.edu/~traylor/ece474/lecture_verilog/beamer/verilog_number_literals.pdf