M
Mahurshi Akilla
Guest
hey guys, i am pasting a simple 3 bit message detector (detects 100)
code that i wrote a while ago for fun. i was wondering if you guys
could suggest any improvements to the code in terms of coding style
and things of that nature. any comments/feedback is appreciated.
thanks
`timescale 1ns / 1ps
`define MESSAGE 3'b100
module detector(Din, Reset, clk, Flag);
input Din;
input Reset;
input clk;
output Flag;
reg [2:0] message;
reg Flag;
always @ (posedge clk or posedge Reset)
begin
if (Reset == 1'b1)
begin
message <= 3'b000;
Flag <= 0;
end
else
begin
message <= message << 1;
message[0] <= Din;
if (message == `MESSAGE)
begin
Flag <= 1;
end
else
begin
Flag <= 0;
end
end
$display("reset = %d, din = %d, message = %b, flag = %d", Reset, Din,
message, Flag);
end
endmodule
Mahurshi Akilla
code that i wrote a while ago for fun. i was wondering if you guys
could suggest any improvements to the code in terms of coding style
and things of that nature. any comments/feedback is appreciated.
thanks
`timescale 1ns / 1ps
`define MESSAGE 3'b100
module detector(Din, Reset, clk, Flag);
input Din;
input Reset;
input clk;
output Flag;
reg [2:0] message;
reg Flag;
always @ (posedge clk or posedge Reset)
begin
if (Reset == 1'b1)
begin
message <= 3'b000;
Flag <= 0;
end
else
begin
message <= message << 1;
message[0] <= Din;
if (message == `MESSAGE)
begin
Flag <= 1;
end
else
begin
Flag <= 0;
end
end
$display("reset = %d, din = %d, message = %b, flag = %d", Reset, Din,
message, Flag);
end
endmodule
Mahurshi Akilla