M
Mahurshi Akilla
Guest
i'm trying to write a detector that would set "Flag" to 1 if a certain
sequence (in this case, 100) is detected.
the code works fine. however, after i introduced the following:
`define MESSAGE 3'b100
and changed my comparision line to:
if (message == MESSAGE)
it complains that "MESSAGE" is undefined.
i thought i could "alias" 3'b100 to MESSAGE so i could change the
detection sequence by only changing the alias and not touching the meat
of the code.
could someone tell me what's wrong here? i am pasting my code below:
`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
sequence (in this case, 100) is detected.
the code works fine. however, after i introduced the following:
`define MESSAGE 3'b100
and changed my comparision line to:
if (message == MESSAGE)
it complains that "MESSAGE" is undefined.
i thought i could "alias" 3'b100 to MESSAGE so i could change the
detection sequence by only changing the alias and not touching the meat
of the code.
could someone tell me what's wrong here? i am pasting my code below:
`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