一段式状态机代码如下:
always@(posedge ui_clk)begin
if(ui_rstn) begin
M_S <= IDLE;
Counter0 <= 10'd0;
Send_Req <= 1'b0;
Addr_cnt <= 12'd0;
Tx_busy <= 1'b0;
FIFO_rst <= 1'b1;
end
else begin
case(M_S)
IDLE: begin
Counter0 <= 10'd0; Send_Req <= 1'b0; Addr_cnt <= 12'd0; Tx_busy <= 1'b0; if(empty) M_S <= FIFO_RST; FIFO_RST: begin Tx_busy <= 1'b1; if(Counter0 >= 10'd100) M_S <= SEND_REQ; FIFO_rst <= (Counter0 <= 10'd80); Counter0 <= Counter0 + 1'b1; end SEND_REQ:begin if(Addr_cnt >= 12'd2047) M_S <= IDLE; else if(empty) begin M_S <=SEND_DATA; Send_Req <= 1'b1; Counter0 <= 10'd0; end end SEND_DATA: begin Send_Req <= 1'b0; if(Send_done) begin M_S <= SEND_REQ; Addr_cnt <= Addr_cnt + 4'd8; end end end
end
请大神帮忙改写为三段式状态机。自己试着写过,在状态数量不变的情况下,难以实现。
|