DC Motor Speed Measurement using Rotary Encoder

The idea was that as soon as I get equal encoder counts in a specific time period,the motor will have attained steady speed.

If you actually get the same number of counts, the conditional test should be valid. You may want to have a small window of +/- some number of counts

Use the safe copy of the encoder counts in the test, and for the assignment to encodercount_previous.

if(copy_encodercount==encodercount_previous&&copy_encodercount!=0)
  encodercount_previous=copy_encodercount;

The interrupts are disabled only to read data from the volatile variables into a copy to be used elsewhere in loop.