Digital Design With Fpgas: by Neeraj Kulkarni
Digital Design With Fpgas: by Neeraj Kulkarni
By
Neeraj Kulkarni
Divide by 9 counter
By hand analysis
Very messy!
Typical ICs
All the circuit with basic elements packaged into a
chip with some reconfigurability.
More sophisticated approach of designing digital
circuits.
eg: Designing a divide by 9 counter
Requires only a counter IC (4029) and may be 1/2 gates.
Limitation:
Only limited number of ICs with limited functionalities.
FPGAs
A fully configurable IC
FPGAs contain programmable logic components
called logic blocks.
Contain hierarchy of reconfigurable interconnects that
allow the blocks to be wired together.
Logic Blocks can be configured to any complex circuit.
FPGA can be made to work as a Xor gate, a Counter or even
bigger- an entire Processor!
Verilog
Synthesizer
A complete
circuit diagram
Introduction to Verilog
Data types?
-Yes, called Drivers in Verilog
Drivers: wire and register
Wire: Connects 2 points in a circuit wire clk
Register (reg) : Stores values reg A
Arrays?
wire [31:0] in
reg [16:0] bus
Modules
Modules are like Black boxes.
Inputs
Module
Outputs
Example: Inverter
module Inverter(
input wire A,
output wire B
);
assign B = ~A;
endmodule
Note:
Input and Output
ports of the module
should be specified.
Combinational Circuits
Combinational circuits are acyclic interconnections of
gates.
And, Or, Not, Xor, Nand, Nor
Multiplexers, Decoders, Encoders .
Some Operators
Arithmetic
Logical
Relational
Shift
Multiply
Division
Add
Subtract
Modulo
Logical negation
&&
Logical and
||
Logical or
>
Greater than
<
Less than
==
Equality
>>
Right shift
<<
Left shift
Control Statements
if-else, case :
Exactly like C.
Hardware view: implemented using multiplexers
Syntax-Control Statements
for (i = 0; i < n; i = i +1)
begin
..
end
case(address)
0 : .
1 : .
2 : ..
default :
endcase
if ( . )
begin
end
else begin
..
end
repeat (18)
begin
..
end
assign statement
Continuous assignment statement.
Used for modeling only combinational logic.
module BusInverter(
input wire A,
output wire B
);
assign B = ~A;
endmodule
Behavioral Description
Sequential Circuits
Circuits containing state elements are called
sequential circuits.
The simplest synchronous state element: EdgeTriggered D Flip-Flop
D
ff
C
D
Q
always@ Block
It is an abstraction provided in Verilog to mainly
implement sequential circuits.
Also used for combinational circuits.
Structure of always block:
always @(#sensitivity list#)
begin
.
end
initial block
An initial block is executed only once when
simulation starts
This is useful in writing test benches
If we have multiple initial blocks, then all of
them are executed at the beginning of
simulation
Example- Counter
module Counter(
input wire CLK,
output reg [31:0] OUT
);
initial
OUT <= 0;
always @(posedge CLK)
OUT <= OUT + 1;
endmodule
Divide by 9 counter
In Verilog
module Counter(
input wire CLK,
output reg [4:0] OUT
);
initial
OUT <= 4b0;
always @(posedge CLK)
begin
if(OUT==4b1000)
OUT <= 4b0;
else
OUT <= OUT + 1;
end
endmodule
Points to Note
Use always@(*) block with blocking
assignments for combinational circuits.
Use always@(posedge CLK) block with nonblocking assignments for sequential circuits.
Do not mix blocking and non-blocking
assignments.
Size in bits
Questions?