EEPROM

          duration1=pulseIn(encoderPinA,HIGH);
                      duration1=pulseIn(encoderPinA,HIGH);
                      if(duration1==duration2){

You never set duration2 to anything. So yo are comparing duration1 to nothing.

Even if we make the obvious change to this code, how is the duration of some physical process going to be identical down to MICROseconds? You need to allow a tolerance of at least a few microseconds. Maybe thousands of microseconds.