need some help here

i got some some confusing trouble that my code wont looping above 36000, when my data “X data” or “Y data” more than 4, my target pulse “jumlahpulsax” or “jumlahpulsay” wont count up and got floating in 16564,any suggestion why this could happen?

this is the code that wont run correctly

#include <EEPROM.h>  

/* Blink without Delay
 
 Turns on and off a light emitting diode(LED) connected to a digital  
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.
 
 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.
 
 
 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen
 
 This example code is in the public domain.

 
 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// constants won't change. Used herre to 
// set pin numbers:
const int pulsex =  5;      // the number of the LED pin
const int pulsey =  4;
const int PWMSpin =  7;
const int DIRx =  8;
const int DIRy =  9;
// Variables will change:
int pulseStatex = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long previousMillis2 = 0;
int pulseStatey = LOW;  
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 80;           // interval at which to blink (milliseconds)
char flag=0;
int intervaly;
int intervaly_adr=200;
int intervalx;
int intervalx_adr=200;
uint16_t counterpulsex = 8000;
uint16_t counterpulsey = 8000;
int jumlahpulsax = 0;
int jumlahpulsay = 0;
int x0,x1,x2,x3,x4,x5,x6,x7,y0,y1,y2,y3,y4,y5,y6,y7;
int dx1,dx2,dx3,dx4,dx5,dx6,dx7,dy1,dy2,dy3,dy4,dy5,dy6,dy7;

int STEP; //shift register perhitungan
int n,o,p,hasil;
long m ;
long fm ; // fmax*fmax = 2500 * 2500 = 6250000;
long f;
int x,y;

void setup() 
{
  // set the digital pin as output:
 pinMode(pulsex, OUTPUT); 
 pinMode(pulsey, OUTPUT);    
 pinMode(PWMSpin, OUTPUT);
 pinMode(DIRx, OUTPUT);
 pinMode(DIRy, OUTPUT);
 Serial.begin(9600);
 intervaly = EEPROM.read(intervaly_adr);
 intervalx = EEPROM.read(intervalx_adr);
}

void loop()
{
  serial ();
  stepper();
  hitung ();
}


void stepper()
{ 
  unsigned long currentMillis = micros();
  if (jumlahpulsax <= counterpulsex*2)
  { 
   if(currentMillis - previousMillis > intervalx) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   
    jumlahpulsax++;
    // if the LED is off turn it on and vice-versa:
    if (pulseStatex == LOW)
      pulseStatex = HIGH;
    
    else
      pulseStatex = LOW;
    // set the LED with the ledState of the variable:
    digitalWrite(pulsex, pulseStatex);
    }
  }
    
  if (jumlahpulsay <= counterpulsey*2)
   { 
    if(currentMillis - previousMillis2 > intervaly) {
    // save the last time you blinked the LED 
   previousMillis2 = currentMillis;   
   jumlahpulsay++;
   //if the LED is off turn it on and vice-versa:
   if (pulseStatey == LOW)
   pulseStatey = HIGH;
   else
   pulseStatey = LOW;
   // set the LED with the ledState of the variable:
    digitalWrite(pulsey, pulseStatey);
  }
 }
}


void serial()
 {
  if (Serial.available())
    { 
      flag=Serial.read();
      if (flag=='a')
       {
        digitalWrite(8,HIGH);
        } 
     if (flag=='b')
       {
        digitalWrite(8,LOW);
       }
     if (flag=='c')
       {
        digitalWrite(9,HIGH);
        } 
     if (flag=='d')
       {
        digitalWrite(9,LOW);
       }
     if (flag=='m')
       {
  
       }
      if (flag=='r')
       {
        jumlahpulsax = 0;
        jumlahpulsay = 0;
       }  
       
     if (flag=='e')
     {
        intervalx = Serial.parseInt();
        Serial.print("Set: interval sumbu x ");
        Serial.print(intervalx);
        Serial.println("us.");
        EEPROM.write(intervalx_adr, intervalx);
    }
     if (flag=='f')
     {
        intervaly = Serial.parseInt();
        Serial.print("Set: interval sumbu y ");
        Serial.print(intervaly);
        Serial.println("us.");
        EEPROM.write(intervaly_adr, intervaly);
    }    
  } 
 }
 
 
 void datamasuk()
{
}
 
 
 
 void hitung()
 {
  fm = 6250000; // fmax*fmax = 2500 * 2500 = 625000
  x=1; // input dx
  y=2; // input dy
  if (x<0){x=x*-1; digitalWrite(8,HIGH);}
  if (y<0){y=y*-1; digitalWrite(9,HIGH);}
  f= 1000000/(2*(sqrt(fm/(sq(x)+sq(y)))));
  intervalx= f/x;
  intervaly= f/y; 
  counterpulsex = 8000*x;
  counterpulsey = 8000*y;
}
 
 void langkah()
 {
  if (STEP == 1){
  dx1 = x1 - x0;
  dy1 = y2 - y0;
  fm = 6250000; // fmax*fmax = 2500 * 2500 = 625000
  x=1; // input dx
  y=2; // input dy
  if (x<0){x=x*-1; digitalWrite(8,HIGH);}
  if (y<0){y=y*-1; digitalWrite(9,HIGH);}
  f= 1000000/(2*(sqrt(fm/(sq(x)+sq(y)))));
  intervalx= f/x;
  intervaly= f/y; 
  counterpulsex = 8000*x;
  counterpulsey = 8000*y;
  }
  if (STEP == 2){
  dx2 = x2 - x1;
  dy2 = y2 - y1;  
  }
  
  if (STEP == 3){
  dx3 = x3 - x2;
  dy3 = y3 - y2;  
  }
  
  if (STEP == 4){
  dx4 = x4 - x3;
  dy4 = y4 - y3;  
  }
  
  if (STEP == 5){
  dx5 = x5 - x4;
  dy5 = y5 - y4;  
  }
  
  if (STEP == 6){
  dx6 = x6 - x5;
  dy6 = y6 - y5;  
  }
  
  if (STEP == 7){
  dx7 = x7 - x6;
  dy7 = sqrt(y7 - y6); 
  
  }
}

and this one is the reference

float frek;
float steps = 0;
void setup ()
{
Serial.begin(9600);
}
void loop ()
{
  if (steps <= 40000)
  {
  steps++;
  //frek = 2500 * 2500 ;
  Serial.println(steps);
  delayMicroseconds(10);}
}

long previousMillis = 0; // will store last time LED was updated
long previousMillis2 = 0;

Use "unsigned long"

LarryD:
long previousMillis = 0; // will store last time LED was updated
long previousMillis2 = 0;

Use "unsigned long"

thanks larry for the answer i will try it and give the result as fast as i can

LarryD:
long previousMillis = 0; // will store last time LED was updated
long previousMillis2 = 0;

Use "unsigned long"

i've try it but nothing changing,any other suggestion?

I can’t see where the figure of 36000 comes from.
32767 seems more likely to me.

AWOL:
I can’t see where the figure of 36000 comes from.
32767 seems more likely to me.

oh yes sorry for my mistake the 36000 should be 32000 it come from interval*x or y for turn off the millis, if i want more from 32767 what type of data variable i should use?

Use
unsigned long

Does this make sense to you?
unsigned long currentMillis = micros() ;

In lines like this the “variable” should also be unsigned long
if(currentMillis - previousMillis2 > variable)

You are probably overflowing a 16 bit integer somewhere. There are lots of possibilities.

Note:
signed constants > 32767 should be terminated with L.
unsigned constants > 65535 should be terminated with UL.
floating point constants should have a decimal point.

e.g.

  fm = 6250000L; // fmax*fmax = 2500 * 2500 = 625000