|
本帖最后由 fpgaw 于 2011-7-30 13:32 编辑
自己写了个fifo程序!写入数据的速度快于读出数据的速度!我想将流水灯的数据写入fifo(速度快),然后每一秒读出一个数据,但是现象却不对,开始的时候流水灯正常,一个一个的亮,但是一会就不行了,就是隔一个亮一个了!不知道是怎么回事?求解!
写数据程序:
module write_module
(
clk,
rst_n,
full,
led_data,
write_en
);
input clk;
input rst_n;
input full;
output write_en;
output[7:0] led_data;
reg write_en;
always @ ( posedge clk or negedge rst_n )
if( !rst_n ) write_en <= 1'b0;
else if( !full ) write_en <= 1'b1;
else write_en <= 1'b0;
reg[7:0] led_data;
reg[3:0] state;
always @ ( posedge clk or negedge rst_n )
begin
if( !rst_n ) begin
state <= 4'd0;
led_data <= 8'h00;
end
else if( !full )
case( state )
4'd0: begin led_data <= 8'h01; state <= state + 1'b1; end
4'd1: begin led_data <= 8'h02; state <= state + 1'b1; end
4'd2: begin led_data <= 8'h04; state <= state + 1'b1; end
4'd3: begin led_data <= 8'h08; state <= state + 1'b1; end
4'd4: begin led_data <= 8'h10; state <= state + 1'b1; end
4'd5: begin led_data <= 8'h20; state <= state + 1'b1; end
4'd6: begin led_data <= 8'h40; state <= state + 1'b1; end
4'd7: begin led_data <= 8'h80; state <= 4'd0; end
endcase
end
endmodule |
|