问题背后的想法不是很清楚,但我的猜测是你想在发送数据之前等待 4 个时钟周期,如果是下面的情况 sn-p 可能会有所帮助,计数器在 4 之前等待时钟周期可以解决问题
module top (input clk,rst,
input [31:0] dataIn,
output [7:0] dataOut
);
reg [31:0] tmp;
reg [31:0] inter;
integer count;
always @(posedge clk)
begin
if (rst) begin
count <= 0;
tmp <= '0;
end
else
begin
if (count < 3) begin
tmp <= dataIn << 4;
count <= count +1; end
else if (count == 3)
begin
inter <= tmp;
count <= 0;
end
else
begin
tmp <= dataIn;
end
end
end
assign dataOut = inter[7:0];
endmodule
但是用 tb http://www.edaplayground.com/x/4Cg 测试有一些限制
注意:请忽略前面的代码它不会工作(我不清楚所以
尝试不同)
编辑:
如果我正确理解您的问题,一个简单的方法是
一)
module top ( input rst,clk,
input [31:0] dataIn,
output [7:0] dataOut);
reg [1:0] cnt;
always @(posedge clk) begin
if (rst) cnt <= 'b0;
else cnt <= cnt + 1;
end
assign dataOut = (cnt == 0) ? dataIn [7:0] :
(cnt == 1) ? dataIn [15:8] :
(cnt == 2) ? dataIn [23:16] :
(cnt == 3) ? dataIn [31:24] :
'0;
endmodule
如果你不想单独写,for循环会派上用场,让它更简单
b)
module top ( input rst,clk,
input [31:0] dataIn,
output reg [7:0] dataOut);
reg [1:0] cnt;
integer i;
always @(posedge clk) begin
if (rst) cnt <= 'b0;
else cnt <= cnt + 1;
end
always @ * begin
for ( i =0;i < cnt ; i=i+1) begin
dataOut <= dataIn[(i*8)+:8]; end
end
endmodule
我已经尝试了两个测试用例,发现都可以工作,tc 在场@
a) http://www.edaplayground.com/x/VCF
b) http://www.edaplayground.com/x/4Cg
你可以试试看