 //------------------------------------------------------------------------------------------------------
 
 void MPPT_state_machine(void) {
-  
-  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
-
-  int pwm = power_status.pwm_duty;
+
+  // MPPT Skip: only run every MPPT_SKIP_COUNT
+  static unsigned int mppt_skip_counter = 0;
+  mppt_skip_counter++;
+  if (mppt_skip_counter < MPPT_SKIP_COUNT) return;
+  mppt_skip_counter = 0;
+
+  static int off_count = MPPT_OFF_COUNT;       // Off counter
+
   int sol_watts = power_status.sol_watts;
   int bat_volts = power_status.bat_volts;
   int sol_volts = power_status.sol_volts;

#define BAT_VOLTS_SCALE     2.7           // the scaling value for raw adc reading to get battery volts scaled by 100 [((10+2.2)/2.2)*(5/1023)*100]

#define ONE_SECOND          50000         // count for number of interrupt in 1 second on interrupt period of 20us
#define LOW_SOL_WATTS       500           // value of solar watts scaled by 100 so this is 5.00 watts
#define MIN_SOL_WATTS       100           // value of solar watts scaled by 100 so this is 1.00 watts
#define MIN_BAT_VOLTS       1100          // value of battery voltage scaled by 100 so this is 11.00 volts          
#define MAX_BAT_VOLTS       1410          // value of battery voltage scaled by 100 so this is 14.10 volts  
#define HIGH_BAT_VOLTS      1300          // value of battery voltage scaled by 100 so this is 13.00 volts  
#define SOL_BAT_VOLT_DIFF   200           // For modified MPPT to start, solar voltage must be this much higher than battery side
#define OFF_NUM             9             // number of iterations of off charger state
  
#define PIN_LED             13            // LED connected to digital pin 13
#define BUFF_MAX            16            // Maximum buffer size for receiving from serial


}		

//------------------------------------------------------------------------------------------------------
// MPPT Algorithm
//------------------------------------------------------------------------------------------------------

void MPPT_PWM_Adjust(void) {
  
  static int old_sol_watts = 0;
  static int delta =  PWM_MPPT_INC;         // variable used to modify pwm duty cycle for the ppt algorithm

  int sol_watts = power_status.sol_watts;

  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
  }
  
  int pwm = power_status.pwm_duty + delta;  // add delta to change PWM duty cycle for PPT algorithm 
  
  if (pwm < PWM_MPPT_MIN) {                 // Keep within MPPT min PWM duty cycle limit
    pwm = PWM_MPPT_MIN;
  }

  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
}

//------------------------------------------------------------------------------------------------------
// MPPT State Machine.
//
//  To adjust for the LPF, the machine will only switch states  
//
//  On State - this is charger state for solar watts > MIN_SOL_WATTS. This is where we run the 
//      Peak Power Tracking alogorithm. In this state we try and run the maximum amount
//      of current that the solar panels are generating into the other side.
