FPGA System Design With Verilog
FPGA System Design With Verilog
Verilog
A Workshop Prepared for
Rose-Hulman Ventures
Ed Doering
Workshop Goals
Gain familiarity with FPGA devices
Gain familiarity with HDL design methods
Implement basic designs in hardware
Full-custom IC
Design at the transistor level
PLD
Complex PLD (CPLD)
FPGA
Pentium II microprocessor
Sources: http://www.xilinx.com/company/press/products/pictures2.htm,
http://micro.magnet.fsu.edu/chipshots/pentium/
Clock distribution
Other
9%
Actel
7% Xilinx
35%
Lattice
16%
Altera
33%
Source: Xilinx University Program Workshop Notes
Triscend A7 CSoC
32-bit ARM7TDMI processor
Microcontroller peripherals
Low-to-medium density
counters
Aug 9, 2001 FPGA System Design with Verilo 18
g
Choosing CPLD or FPGA
FPGA
Volatile (SRAM-based)
EEPROM)
Permits field upgrades, reconfigurable computing
medium-to-high density
Gate-Level Hardware
Simulation Synthesis
Implement Netlist
Implement
Aug 9, 2001 FPGA System Design with Verilo 25
g
Key Advantages of HDL-Based
Design Methodology
Operate at higher level of abstraction
Can debug earlier (behavioral simulator)
Parameterized design, easy to make
wholesale modifications to a design (e.g.,
bus width)
if (reset == 1)
count <= 0;
else
count <= count + 1;
HDL
FPGA ASIC
Verilog
Synthesizable
Verilog
Use this to
make hardware
in FPGA
Aug 9, 2001 FPGA System Design with Verilo 32
g
Most Likely Learning Hurdle
May try to write HDL code as if it will
eventually be “executed” by some
mysterious processor device in the FPGA
Code is written sequentially (like a
program), but you are simply writing
descriptions of the various hardware entities
in your system
/* Port modes */
input a,b;
output c;
// Functionality
assign c = ~(a & b);
endmodule
Aug 9, 2001 FPGA System Design with Verilo 38
g
Bitwise Operators
~ NOT
& AND
| OR
^ EXOR
// Port modes
input a,b;
output c;
// Registered identifiers
reg c;
// Functionality
always @ (a or b)
c <= ~(a & b);
endmodule
// Port modes
input a,b;
output c;
output d;
// Registered identifiers
reg c,d;
// Functionality
always @ (a or b) begin
c <= ~(a & b);
d <= a ^ b;
end
endmodule
// Port modes
input A,B,Sel;
output Y;
// Registered identifiers
reg Y;
// Functionality
always @ (A or B or Sel)
if (Sel==0)
Y <= A;
else
Y <= B;
endmodule
== Equal to
!= Not equal
< Less than
> Greater than
<= Less than or equal
>= Greater than or equal
&& AND
|| OR
Aug 9, 2001 FPGA System Design with Verilo 43
g
More Operators
% Modulus
Aug 9, 2001 FPGA System Design with Verilo 44
g
MUX Again...
// Functionality
always @ (A or B or Sel)
if (Sel)
Y <= B;
else
Y <= A;
// Port modes
input [3:0] Data;
input [1:0] Sel;
output Y;
// Registered identifiers
reg Y;
// Functionality
always @ (Data or Sel)
if (Sel == 0)
Y <= Data[0];
else if (Sel == 1)
Y <= Data[1];
else if (Sel == 2)
Y <= Data[2];
else Y <= Data[3];
endmodule
// Port modes
input [15:0] Data;
input [3:0] Sel;
output Y;
// Registered identifiers
reg Y;
// Functionality
always @ (Data or Sel)
casez (Sel)
4’b0000: Y <= Data[0];
4’b0001: Y <= Data[1];
4’b01??: Y <= Data[2];
default: Y <= Data[3];
endcase
endmodule
// Port modes
input [2:0] Code_In;
output [2:0] Code_Out;
// Registered identifiers
reg [2:0] Code_Out;
// Functionality
always @ (Code_In)
case (Code_In)
3’b000: Code_Out <= 3’b101;
3’b001: Code_Out <= 3’b111;
3’b010: Code_Out <= 3’b001;
3’b011: Code_Out <= 3’b000;
3’b100: Code_Out <= 3’b100;
3’b101: Code_Out <= 3’b010;
3’b110: Code_Out <= 3’b110;
3’b111: Code_Out <= 3’b011;
endcase
endmodule
{Data[13:12],a,b,Data[11:0]}
{16{a}}
// Port modes
input [3:0] A,B;
output AltB,AeqB,AgtB;
// Registered identifiers
reg AltB,AeqB,AgtB;
// Functionality
always @ (A or B) begin
AltB <= (A < B);
AeqB <= (A == B);
AgtB <= (A > B);
end
endmodule
// Port modes
input [BusWidth-1:0] A,B;
...
...
/* Port modes */
input D,Clock;
output Q;
// Registered identifiers
reg Q;
// Functionality
always @ (posedge Clock)
Q <= D;
endmodule
/* Port modes */
input T,Clock;
output Q,;
// Registered identifiers
reg Q;
// Functionality
always @ (negedge Clock)
if (T == 1)
Q <= ~Q;
endmodule
/* Port modes */
input T,Clock;
output Q,_Q;
// Registered identifiers
reg Q;
// Functionality
always @ (negedge Clock)
if (T == 1)
Q <= ~Q;
assign _Q = ~Q;
endmodule
/* Port modes */
input D,Clock,Reset;
output Q,_Q;
// Registered identifiers
reg Q;
// Functionality
always @ (negedge Clock or
posedge Reset)
if (Reset == 1)
Q <= 0;
else
Q <= D;
assign _Q = ~Q;
endmodule
/* Port modes */
input D,Clock,_Preset;
output Q;
// Registered identifiers
reg Q;
// Functionality
always @ (posedge Clock or
negedge _Preset)
if (_Preset == 0)
Q <= 1;
else
Q <= D;
endmodule
/* Port modes */
input D,Clock,Reset;
output Q;
// Registered identifiers
reg Q;
// Functionality
always @ (posedge Clock)
Q <= (Reset)? 0 : D;
endmodule
/* Port modes */
input [15:0] D;
input Clock,Reset;
output [15:0] Q;
// Registered identifiers
reg [15:0] Q;
// Functionality
always @ (posedge Clock or
posedge Reset)
if (Reset == 1)
Q <= 0;
else
Q <= D;
endmodule
// Port modes
input Clock,Reset;
output [7:0] Q;
// Registered identifiers
reg [7:0] Q;
// Functionality
always @ (posedge Clock or
posedge Reset)
if (Reset == 1)
Q <= 0;
else
Q <= Q + 1;
endmodule
// Port modes
input Clock,Reset,Enable,Init;
output [7:0] Q;
// Registered identifiers
reg [7:0] Q;
// Functionality
always @ (posedge Clock or
posedge Reset)
if (Reset == 1)
Q <= 0;
else
if (Init)
Q <= 8’hFF;
else if (Enable)
Q <= Q – 1;
endmodule
// Port modes
input Clock,Reset,Load;
input [7:0] D;
output [7:0] Q;
// Registered identifiers
reg [7:0] Q;
// Functionality
always @ (posedge Clock or
posedge Reset)
if (Reset == 1)
Q <= 0;
else
Q <= (Load) ? D :
{1’b0,Q[7:1]};
endmodule
B = A, C = ~A