   attachInterrupt(D5, lencode, CHANGE); // Setup Interrupt 
   attachInterrupt(D6, rencode, CHANGE); // Setup Interrupt 
   sei();                                // Enable interrupts  
+ 
   int currentTime = millis();
   int cloopTime = currentTime;
   os_timer_setfn(&myTimer, tic, NULL);
   os_timer_arm(&myTimer, period, true);   // timer in ms
   lPID.SetSampleTime(period);
   rPID.SetSampleTime(period); 
-  tPID.SetSampleTime(period);  
+  lPID.SetOutputLimits(0, 1023);  
+  rPID.SetOutputLimits(0, 1023);  
   lPID.SetMode(AUTOMATIC);
   rPID.SetMode(AUTOMATIC);
-  tPID.SetMode(AUTOMATIC);
   Serial.begin(115200);
   Serial.println("Ready");
 }

    } else {
      rdir=-1;
    }
    if(lpwm>1023) lpwm=1023;
    if(rpwm>1023) rpwm=1023;
    if(lpwm<0) lpwm=0;
    if(rpwm<0) rpwm=0;
    analogWrite(D1, lpwm);
    analogWrite(D2, rpwm);
    digitalWrite(D3, llevel);

#include <ESP8266WiFi.h>
#include <PID_v1.h>
extern "C" {
#include "user_interface.h"
}

int lpwm=0, rpwm=0;  // motor pwm
int lmc=0,  rmc=0;   // left motor counter
int lmc0=0, rmc0=0;  // last encoder value 
int ldir=1, rdir=1;  // motor direction
double whesep= 0.135; // wheel separtion in m
double whedia= 0.7;   // wheel diameter in m
int CPR = 40;     // Encoder Count per Revolutions (double of holes using up & down interrupt)
int period=200;   // sample timer period in ms
double lv=0, rv=0;// motor speed innumber tics per period
int ti=0;         // tic timer counter
double lOut,rOut,lSet,rSet;   // PID output and demands
double lkp=1,lki=0,lkd=0;     // Left wheel PID constants
double rkp=1,rki=0,rkd=0;     // Right wheel PID constants
int kt=1000/period; // number of periods in 1sec

//PID(&Input, &Output, &Setpoint, Kp, Ki, Kd, Direction)
PID lPID(&lv, &lOut, &lSet, lkp, lki, lkd, DIRECT);
PID rPID(&rv, &rOut, &rSet, rkp, rki, rkd, DIRECT);

os_timer_t myTimer;

// start of timerCallback
void tic(void *pArg) {
  lv=(lmc-lmc0)*kt;    // left instant velocity tic/period
  lmc0=lmc;
  rv=(rmc-rmc0)*kt;    // rv right install velocity
  rmc0=rmc;
  ti+=1;                  // tic counter

}

void stop(void){      // Stop both motors
