 	sampleTime = millis();			// sample (etc) immediately
   printTime = millis();
 	heaterPeriodTime = millis();	// start new period immediately
+  turnOffTime = millis() + TURNOFF_TIME_MS;
 }
 
 #ifdef OPEN_LOOP_MODE

#define PGAIN 2
#define IGAIN 0.1
#define DGAIN 0
#define IMIN -25    // IMIN = iTerm min/IGAIN
#define IMAX 25     // IMAX = iTerm max/IGAIN

#define TARGET 23.5 // ~20.5C ambient + 23.5C rise = 44C'ish

#define TEMP_TO_DUTY_SLOPE 0.1
#define TEMP_TO_DUTY_OFFSET 0.0

//#define DRIVE_MAX 100
//#define DRIVE_MIN 10

struct SPid
{

    DEBUG2(F("pidDrive        = "), pidDrive);
    DEBUG2(F("heaterDutyCycle = "), heaterDutyCycle);
  }
  
  if (turnOffTimeLeft < 0) 
  { 
    heaterOff();
    
    turnOnTime = millis() + TURNON_TIME_MS;
    do {
      turnOnTimeLeft = turnOnTime - millis();
      delay(1000);
    } while (turnOnTimeLeft > 0);

    tempZero = tempAvg.getAverage();
    
    if (++iStateLimIterator >= iStateLimSize) { while(1) {/*take a nop*/} }
    pid.init();
    pid.iMax = iStateLim[iStateLimIterator];
    pid.iMin = -iStateLim[iStateLimIterator];

    pidDrive = updatePID(&pid,getErr(),getPos());
    
    timeZero = millis();
    sampleTime = millis();
    printTime = millis();
    heaterPeriodTime = millis();
    turnOffTime = millis() + TURNOFF_TIME_MS;
  }
}
#endif // PID_MODE
