Getting different calculation result and i dont know why

// Constant, won't change
const int Interval = 300;

// Values, will change

float displacement_old = 0;
float displacement = 0;
int setSpeed_actuator = 100;       // The speed of 2nd time extention after the pause
int futher_extend_interval = 2000;
unsigned long currentTime = 0;
unsigned long currentTime_further = 0;
unsigned long currentTime_displacement = 0;
unsigned long previousTime = 0;
unsigned long previousTime2 = 0;
unsigned long previousTime_displacement = 0;
unsigned long previousTime_torsion = 0;
unsigned long previousButtonMillis =0; 

void setup(){
  Serial.begin(9600);
}
void loop() {

// Calculation
currentTime_displacement = millis();
displacement = displacement_old + ((0.000625*setSpeed_actuator)/1000);
displacement_old = displacement; 
  Serial.println(displacement, 5);



// result shows up every "Interval" seconds
if (currentTime_displacement - previousTime_displacement >= Interval){ 
   Serial.println(displacement, 5);  
   previousTime_displacement = currentTime_displacement;
}
}

**The purpose of this code is to run a calculation in the background, then pop out the result every 300 milliseconds **
The two Serial.println(displacement) give me the same result.
But if comments the one inside the calculation.
Then I will get a different result in the results part.

This is what the correct calculation looks like:

This is what i end up getting using millis() if i want it to show result every 300 milliseconds.

doesn't the first print, the unconditional print report the value after each iteration and the 2nd print every 300 msec?

the value reported in the 2nd print depends on how many iterations of loop occurred between reports and won't the first print affect the time between each iteration?

gcjr:
doesn't the first print, the unconditional print report the value after each iteration and the 2nd print every 300 msec?

the value reported in the 2nd print depends on how many iterations of loop occurred between reports and won't the first print affect the time between each iteration?

I'm not sure how it affects.
Instead of showing the result every millisecond as the first part of the calculation.
I need it to show me the result for only every 300 msec.

f129luke:
I'm not sure how it affects.

the unconditional print takes time and will reduce the number of loop iterations every 300 msec