Professional Documents
Culture Documents
EE-307 Fpga Based System Design: Lecture # 05
EE-307 Fpga Based System Design: Lecture # 05
Verilog
Combinational Logic in Verilog
Lecture # 05
Today’s Lecture
Gate-Level modelling
Verilog gate Primitives
Dataflow Modelling
Continuous Assignment using assign statement
Expressions, Operators, Operands
Behavioural Modelling
Structured Procedures: Initial & always blocks
Blocking & Non-blocking statements
HLL Higher language constructs (if, switch, case, loops)
Can the life be made even more easier ??
Assign out = sel[1] ? ( sel[0] ? in3 : in2 ) : ( sel[0] ? in1 : in0 );
case (sel)
2'b00: out = in0;
2'b01: out = in1;
2'b10: out = in2;
2'b11: out = in3;
endcase
So We require an always block to be able to use
Higher Level constructs (If-Else, Case, For Loops)
module mux_case(sel,in1,in2,in3,in4,out1);
input [1:0] sel;
input in1,in2,in3,in4;
output reg out1; // LHS in always statement must be “reg”
wire reg
Note : Reg
Sensitivity List
Behavioural Model –
<Important……..>
module compare(A_lt_B, A_gt_B, A_eq_B,A,B); // Note the semicolon, Keywords are case sensitive
// There can be multiple modules per verilog file – Don’t do it plz
output reg A_lt_B, A_gt_B, A_eq_B; // Note reg – You will get error if you wont use it !
input [1:0] A,B;
always @ (A or B)
begin
if(A ==B)
begin //begin & end required for multiple lines in if statement
A_lt_B=0; // This (=) is called BLOCKING ASSIGNMENT (Will study later)
A_gt_B=0;
A_eq_B=1;
end
else if(A>B)
begin
A_lt_B=0; A_gt_B=1; A_eq_B=0; // You can write multiple lines separated with semi end
//colon. Not Recommended
else
begin
A_lt_B=0; A_gt_B=1; A_eq_B=0;
end
end
endmodule // Please note there is no semicolon at the end , Keywords are case sensitive