Altera_Forum
Honored Contributor
16 years agoit's weird that my state machine got into a wrong state
I'm writing some verilog code to communicate with my usb controller, the simulation result is good , but it seems that my fpga hangs after running 1~2 houres. At last I display the state on LEDs, to my astonishment, when fpga hangs the leds output is not defined(no led flashes).
I'm using Quartus 9.0 for Linux, Terasic DE0 board (cyclon III EP3C16F484C6N ) Can someone give me some hints? Thanks! My code are as follows: localparam IDEL = 8'b00000001, STATE1 = 8'b00000010, STATE2 = 8'b00000100, STATE3 = 8'b00001000, STATE4 = 8'b00010000, STOPTX = 8'b00100000, STOPTX2= 8'b01000000; always @(posedge clk or negedge reset_n) begin if(!reset_n) begin state_next<=IDEL; ... end else begin case(state_next) idel: begin if(!fifo_empty) state_next<=STATE1; pktend_next<=1'b1; endstate1: begin fifo_addr_reg<=2'b10; state_next<=STATE2; end state2: begin if(full!=1'b0) //usb buffer not full begin if(!fifo_empty)//output fifo is not empty begin slwr_next<=1'b0; data_next<=_fifo_[rdptr]; last_out<=_fifo_[rdptr]; state_next<=STATE3; end else state_next<=IDEL; end else state_next<=IDEL; end state3: begin usb_count<=usb_count+1; slwr_next<=1'b1;//write into usb state_next<=STATE4; rdptr<=(rdptr+1)%FIFO_LEN; end state4: begin if(!fifo_empty) begin state_next<=STATE2; end else state_next<=IDEL; end stoptx: begin pktend_next<=1'b0; state_next<=STOPTX2; end stoptx2: begin pktend_next<=1'b1; state_next<=IDEL; end default:
state_next<=idel; endcase end end