|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
请高手指教一下啊,这个程序是从外界输入4个数,然后并行输出,怎样写才能达到同步输出呢?
我这样写的话最后一个数总是落后一个周期才输出结果。
module SP ( clk, rst_n, idin,
dout_0, dout_1, dout_2, dout_3
);
input clk, rst_n;
input [7:0] idin;
output [7:0] dout_0, dout_1, dout_2, dout_3;
wire sp_done;
reg [1:0] cnt;
reg [7:0] dout_buf_0, dout_buf_1, dout_buf_2, dout_buf_3;
reg [7:0] dout_0, dout_1, dout_2, dout_3;
assign sp_done = (cnt == 'b11) ? 1 : 0;
always @ (posedge clk or negedge rst_n)
if (!rst_n )
cnt <= 'b0_0000;
else
cnt <= cnt + 'b1;
always @ (sp_done)
begin
dout_0 = dout_buf_0;
dout_1 = dout_buf_1;
dout_2 = dout_buf_2;
dout_3 = dout_buf_3;
end
always @ (posedge clk or negedge rst_n)
if (!rst_n)
begin
dout_buf_0 <= 'b0;
dout_buf_1 <= 'b0;
dout_buf_2 <= 'b0;
dout_buf_3 <= 'b0;
end
else
case (cnt)
'b00: dout_buf_0 = idin;
'b01: dout_buf_1 = idin;
'b10: dout_buf_2 = idin;
'b11: dout_buf_3 = idin;
endcase
endmodule
|
|