2013-02-17 219 views
0

我有此样品模块Verilog输出是1个时钟周期

module control(input clk,input [5:0] x, input [6:0] y, 
input [7:0] done_gamestate, 
output [7:0] gamestateout 
    ); 

    wire [7:0] connector; 
    state_ctrl a(clk,x,y,done_gamestate,connector); 
    datapath_ctrl b(clk,connector,gamestateout); 

endmodule 

和这里延迟是输出波形enter image description here

基本上,我们怎样才能使模块B响应在所述第一正边缘时钟?看来,输出延迟了1个正沿周期。

这里是state_ctrl模块

module state_ctrl(input clk,input [5:0] x, input [6:0] y, 
input [7:0] done_gamestate, 
output reg [7:0] gamestate 
    ); 
initial begin 
gamestate = 0; 
end 

[email protected](posedge clk) 
begin 
case(done_gamestate) 
8'b0000_0001 : gamestate <= 8'b0000_0100; // init -> offsets 
8'b0000_0100 : gamestate <= 8'b0000_0010; // offsets -> getcells 
8'b0000_0010 : gamestate <= 8'b0001_0000; // getcells -> countcells 
8'b0001_0000 : gamestate <= 8'b0000_1000; // countcells -> applyrules 
8'b0000_1000 : gamestate <= 8'b0010_0000; 
8'b0010_0000 : 
    begin 
     if(x==8'd62 && y==8'd126) 
      gamestate <= 8'b1000_0000; 
     else 
      gamestate <= 8'b0000_0100; 
    end 
8'b1000_0000 : gamestate <= 8'b0100_0000; // copy -> delay 
8'b0100_0000 : gamestate <= 8'b0000_0100; // delay -> offset 
default : begin 
    gamestate <= 8'b00000000; 
    $display ("error, check done_gamestate %b",done_gamestate); 
    end 
endcase 
end 

endmodule 

这里是datapath_ctrl模块

module datapath_ctrl(input clk,input [7:0] gamestate,output reg [7:0] gamestateout 
    ); 

initial begin 
gamestateout = 0; 
end 

[email protected](posedge clk) 
begin 
    #1 case(gamestate) 
    8'b00000001: gamestateout = 8'b00000001; //init 
    8'b00000010: gamestateout = 8'b00000010; //getcells 
    8'b00000100: gamestateout = 8'b00000100; //offsets 
    8'b00001000: gamestateout = 8'b00001000; //applyrules 
    8'b00010000: gamestateout = 8'b00010000; //countcells 
    8'b00100000: gamestateout = 8'b00100000; //writecell 
    8'b01000000: gamestateout = 8'b01000000; //delay 
    8'b10000000: gamestateout = 8'b10000000; //copy 
    default : begin 
    gamestateout = 8'b00000000; 
    $display ("error, check gamestate %b",gamestate); 
    end 
endcase 
end 
endmodule 

回答

3

没有足够的信息说,如果有在执行一个错误,但我猜测,我有是1周期延迟,因为它是同步逻辑。数据发生变化并在下一个时钟沿采样,因此状态在其输入发生变化后似乎会改变1个周期。

如果您需要立即更改输出,那么您必须使用组合逻辑。

+0

更新了更多信息 – WantIt 2013-02-17 10:58:31