module cube_gen(CLK, reset, lock, init, busy, done, Ax, Ay, Az, Bx, By, Bz); input CLK, reset, lock, init; wire CLK, reset, lock, init; output busy, done; reg busy, done; output [15:0] Ax, Ay, Az, Bx, By, Bz; reg [15:0] Ax, Ay, Az, Bx, By, Bz; reg [3:0] state; reg [15:0] d_step; reg [15:0] cur_step; parameter done_looping = 4'd0, looping = 4'd1, wait_for_init_low = 4'd2; reg [4:0] counter; always @(posedge CLK) begin if (reset) begin cur_step <= 16'd0; Ax <= 16'd0; Ay <= 16'd0; Az <= 16'd0; Bx <= 16'd0; By <= 16'd0; Bz <= 16'd0; busy <= 1'b0; done <= 1'b0; state <= done_looping; $display("cube_gen being reset"); end else if (lock) begin case (state) done_looping: begin if (init == 1'b1) begin // not busy yet (no valid results out) busy <= 1'b0; // not done yet done <= 1'b0; counter <= 3'b0; state <= looping; $display("cube_gen: done_looping with init high"); end // if (init == 1'b1) else begin $display("cube_gen: done_looping with init low"); busy <= 1'b0; done <= 1'b0; end end looping: begin // not done yet. busy <= 1'b1; done <= 1'b0; if (counter == 0) begin Ax <= 16'h4000; Ay <= 16'h4000; Az <= 16'h4000; Bx <= 16'hc000; By <= 16'h4000; Bz <= 16'h4000; end else if (counter == 1) begin Ax <= 16'h4000; Ay <= 16'h4000; Az <= 16'h4000; Bx <= 16'h4000; By <= 16'hc000; Bz <= 16'h4000; end else if (counter == 2) begin Ax <= 16'h4000; Ay <= 16'h4000; Az <= 16'h4000; Bx <= 16'h4000; By <= 16'h4000; Bz <= 16'hc000; end else if (counter == 3) begin Ax <= 16'hc000; Ay <= 16'h4000; Az <= 16'hc000; Bx <= 16'h4000; By <= 16'h4000; Bz <= 16'hc000; end else if (counter == 4) begin Ax <= 16'h4000; Ay <= 16'hc000; Az <= 16'hc000; Bx <= 16'h4000; By <= 16'h4000; Bz <= 16'hc000; end else if (counter == 5) begin Ax <= 16'hc000; Ay <= 16'h4000; Az <= 16'h4000; Bx <= 16'hc000; By <= 16'h4000; Bz <= 16'hc000; end else if (counter == 6) begin Ax <= 16'h4000; Ay <= 16'hc000; Az <= 16'h4000; Bx <= 16'h4000; By <= 16'hc000; Bz <= 16'hc000; end else if (counter == 7) begin Ax <= 16'h4000; Ay <= 16'hc000; Az <= 16'h4000; Bx <= 16'hc000; By <= 16'hc000; Bz <= 16'h4000; end else if (counter == 8) begin Ax <= 16'hc000; Ay <= 16'hc000; Az <= 16'h4000; Bx <= 16'hc000; By <= 16'hc000; Bz <= 16'h4000; end else if (counter == 9) begin Ax <= 16'hc000; Ay <= 16'hc000; Az <= 16'hc000; Bx <= 16'hc000; By <= 16'hc000; Bz <= 16'h4000; end else if (counter == 10) begin Ax <= 16'hc000; Ay <= 16'hc000; Az <= 16'hc000; Bx <= 16'hc000; By <= 16'h4000; Bz <= 16'hc000; end else if (counter == 11) begin Ax <= 16'hc000; Ay <= 16'hc000; Az <= 16'hc000; Bx <= 16'h4000; By <= 16'hc000; Bz <= 16'hc000; state <= wait_for_init_low; end counter <= counter + 1; end // case: looping wait_for_init_low: begin // now we're done busy <= 1'b0; done <= 1'b1; if (~init) begin state <= done_looping; end end endcase // case (state) end end // always @ (posedge CLK) endmodule // cube_gen