   
   static int old_sol_watts = 0;
   static int off_count = OFF_NUM;
-  static int delta = PWM_INC;                        // variable used to modify pwm duty cycle for the ppt algorithm
+  static int delta = PWM_INC;                   // variable used to modify pwm duty cycle for the ppt algorithm
 
   int pwm = power_status.pwm_duty;
   int sol_watts = power_status.sol_watts;

  Serial.print("  ");

  Serial.print("charger = ");
  if (power_status.mode == off)              Serial.print("off    ");
  else if (power_status.mode == mppt_on)     Serial.print("mppt   ");
  else if (power_status.mode == auto_off)    Serial.print("autooff");
  else if (power_status.mode == bulk)        Serial.print("bulk   ");
  else if (power_status.mode == bat_float)   Serial.print("float  ");
  else if (power_status.mode == const_volt)  Serial.print("volt   ");
  else if (power_status.mode == const_power) Serial.print("watt   ");
  else if (power_status.mode == const_pwm)   Serial.print("pwm    ");
  Serial.print("  ");

  Serial.print("target = ");

  int sol_volts = power_status.sol_volts;
  
  switch (power_status.mode) {
    case MODE_MPPT_ON:                                        
      if (sol_watts < MIN_SOL_WATTS) {          //if watts input from the solar panel is less than
        power_status.mode = MODE_MPPT_OFF;      //the minimum solar watts then it is getting dark so
        off_count = OFF_NUM;                    //go to the charger off state
        TURN_OFF_MOSFETS; 
      }
      else if (bat_volts > MAX_BAT_VOLTS) {       //else if the battery voltage has gotten above the float
        power_status.mode = MODE_MPPT_BAT_FLOAT;  //battery float voltage go to the charger battery float state
      }
      else if (sol_watts < LOW_SOL_WATTS) {     //else if the solar input watts is less than low solar watts
        pwm = PWM_MAX;                          //it means there is not much power being generated by the solar panel
        set_pwm_duty(pwm);			                //so we just set the pwm = 100% so we can get as much of this power as possible
      }                                         //and stay in the charger on state
      else {                                          
        pwm = ((bat_volts * 10) / (sol_volts / 10)) + 5;  //else if we are making more power than low solar watts figure out what the pwm
        power_status.mode = MODE_MPPT_BULK;               //value should be and change the charger to bulk state 
      }
      break;
    case MODE_MPPT_BULK:
      if (sol_watts < MIN_SOL_WATTS) {         //if watts input from the solar panel is less than
        power_status.mode = MODE_MPPT_OFF;     //the minimum solar watts then it is getting dark so
        off_count = OFF_NUM;                   //go to the charger off state
        TURN_OFF_MOSFETS; 
      }
      else if (bat_volts > MAX_BAT_VOLTS) {      //else if the battery voltage has gotten above the float
        power_status.mode = MODE_MPPT_BAT_FLOAT; //battery float voltage go to the charger battery float state
      }
      else if (sol_watts < LOW_SOL_WATTS) {    //else if the solar input watts is less than low solar watts
        power_status.mode = MODE_MPPT_ON;      //it means there is not much power being generated by the solar panel
        TURN_ON_MOSFETS;                       //so go to charger on state
      }
      else {                                   // this is where we do the Peak Power Tracking ro Maximum Power Point algorithm
        if (old_sol_watts >= sol_watts) {      // if previous watts are greater change the value of
          delta = -delta;			                 // delta to make pwm increase or decrease to maximize watts
        }
        pwm += delta;                          // add delta to change PWM duty cycle for PPT algorythm 
        old_sol_watts = sol_watts;             // load old_watts with current watts value for next time
        set_pwm_duty(pwm);			               // set pwm duty cycle to pwm value
      }
      break;
    case MODE_MPPT_BAT_FLOAT:
      if (sol_watts < MIN_SOL_WATTS) {         //if watts input from the solar panel is less than
        power_status.mode = MODE_MPPT_OFF;     //the minimum solar watts then it is getting dark so
        off_count = OFF_NUM;                   //go to the charger off state
        set_pwm_duty(pwm);					
        TURN_OFF_MOSFETS; 
      }
