module sum_control(
					Reset,
					pulse_sum_in,
					step_sum,
					wave_out
					);

output wave_out;
input  Reset;
input  [23:0] step_sum; //总脉冲数（由步进电机走的总路程决定）
input  pulse_sum_in;


reg [23:0] step_counter;
reg out_control;


always @(posedge pulse_sum_in)
begin
  if(Reset == 1'b1)
  begin
    step_counter <= 24'b0;
    out_control  <= 1'b0;
  end
  else
  begin
    if(step_counter == ((step_sum & 24'b111111111111111111111101) + 24'b1))
      out_control  <= 1'b0;
    else if(step_counter == 24'b111111111111111111111111)
      step_counter <= 24'b0;
    else
    begin
      step_counter <= step_counter + 24'b1;
      out_control  <= 1'b1;
    end       
  end 
end


assign wave_out = pulse_sum_in & out_control;


endmodule