本帖最后由 fpgaw 于 2010-7-18 12:37 编辑
有哪位高人给指点一下:下面的程序时序仿真总出错谁能给仿真一下阿?多谢了
module rxd(reset,clk460800,in,ready,out);
input reset;
input clk460800;
input in;
output ready;
output [7:0]out;
reg ready;
reg [7:0]out;
reg [2:0]counter;
reg [9:0]state;
parameter idle = 10'b00_0000_0000,
start = 10'b00_0000_0001,
first = 10'b00_0000_0010,
second = 10'b00_0000_0100,
third = 10'b00_0000_1000,
fourth = 10'b00_0001_0000,
fifth = 10'b00_0010_0000,
sixth = 10'b00_0100_0000,
seventh = 10'b00_1000_0000,
eighth = 10'b01_0000_0000,
stop = 10'b10_0000_0000;
always@(posedge clk460800)
begin
if (!reset)
begin
state <= idle;
ready <= 0;
counter <= 3'b000;
end
else
case (state)
idle: begin
if (in)
begin
state <= idle;
end
else
begin
state <= start;
end
end
start: begin
if ((counter < 3) && (in == 0))
begin
counter <= counter + 3'b001;
end
else
if (counter == 3)
begin
counter <= 3'b000;
state <= first;
end
else
begin
counter <= 3'b000;
state <= idle;
end
end
first: begin
if (counter <3)
begin
counter <= counter + 3'b001;
if (counter == 1)
begin
out[0]<= in;
end
end
else
begin
state <= second;
counter = 3'b000;
end
end
second: begin
if (counter < 3)
begin
counter <= counter + 3'b001;
if (counter == 1)
begin
out[1]<= in;
end
end
else
begin
state <= third;
counter <= 3'b000;
end
end
third: begin
if (counter < 3)
begin
counter <= counter + 3'b001;
if (counter == 1)
begin
out[2]<= in;
end
end
else
begin
state <= fourth;
counter <= 3'b000;
end
end
fourth: begin
if (counter < 3)
begin
counter <= counter + 3'b001;
if (counter == 1)
begin
out[3]<= in;
end
end
else
begin
state <= fifth;
counter <= 3'b000;
end
end
fifth: begin
if (counter < 3)
begin
counter <= counter + 3'b001;
if (counter == 1)
begin
out[4]<= in;
end
end
else
begin
state <= sixth;
counter <= 3'b000;
end
end
sixth: begin
if (counter < 3)
begin
counter <= counter + 3'b001;
if (counter == 1)
begin
out[5]<= in;
end
end
else
begin
state <= seventh;
counter <= 3'b000;
end
end
seventh:begin
if (counter < 3)
begin
counter <= counter + 3'b001;
if (counter == 1)
begin
out[6]<= in;
end
end
else
begin
state <= eighth;
counter <= 3'b000;
end
end
eighth: begin
if (counter < 3)
begin
counter <= counter + 3'b001;
if (counter == 1)
begin
out[7]<= in;
end
end
else
begin
state <= stop;
counter <= 3'b000;
end
end
stop: begin
if (counter <2)
begin
counter <= counter + 3'b001;
if (counter == 0)
begin
ready <= 1;
end
else
begin
ready <= 0;
end
end
else
begin
state <= idle;
counter <= 3'b000;
end
end
default: state <= idle;
endcase
end
endmodule |