Professional Documents
Culture Documents
Verilog
Combinational Logic in Verilog
Lecture # 08
2
D Q
Gate
module Decoder2( Missed Assignment to one output signal
input [1:0] opcode,
output reg [1:0] decoder_op);
always @ (opcode) Decoder_op[0]
begin
6
case(opcode)
Note the overhead of a LATCH
2'b01 : decoder_op = 2'b01; • You need to generate the logic for
2'b00 : decoder_op = 2'b01; Gate/Enable Signal
2'b11 : decoder_op = 2'b10; • We NEED to use the previous value of 0
2'b10 : decoder_op[0] = 1'b1; decoder_op[1] when opcode = 2’b10
endcase
end
endmodule
D Q
decoder_op = 2'b01;
case(opcode) Initialize – To account for missed assignments.
2'b01 : decoder_op = 2'b01; And a way to provide default values if an
2'b00 : decoder_op = 2'b01; assignment is missed.
2'b11 : decoder_op = 2'b10; WARNING : This is not S/W initialization
endcase
end
endmodule
module Decoder(
input [1:0] opcode,
output reg [1:0] decoder_op
);
always @ (opcode)
begin
9
decoder_op = 2'b01;
case(opcode) Best Coding Practice
2'b01 : decoder_op = 2'b01;
2'b00 : decoder_op[0] = 1'b0; Initialize for Missed Assignments
2'b11 : decoder_op = 2'b10; Default for Missed Cases
default : decoder_op = 2'b01;
endcase
end
endmodule
In summary...
10
Suggested Reading
<Samir Palnitkar> Verilog: Chapter 1-6
(Combinational circuits only)
Verilog Tutorial
http://www.asic-world.com/verilog/veritut.html
HDL Coding Guidelines for Student Projects, Nestor,
J.A.; , IEEE Conference on Microelectronic Systems
Education (MSE), 2011