   int sol_volts = power_status.sol_volts;
   
   switch (power_status.mode) {
-    case mppt_on:                                        
-      if (sol_watts < MIN_SOL_WATTS) {              //if watts input from the solar panel is less than
-        power_status.mode = auto_off;               //the minimum solar watts then it is getting dark so
-        off_count = OFF_NUM;                        //go to the charger off state
+    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 = 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 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 = bulk;                              //value should be and change the charger to bulk state 
-      }
-      break;
-    case bulk:
-      if (sol_watts < MIN_SOL_WATTS) {          //if watts input from the solar panel is less than
-        power_status.mode = auto_off;                    //the minimum solar watts then it is getting dark so
-        off_count = OFF_NUM;                    //go to the charger off state
+        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 = 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 = 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
+      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 bat_float:
-      if (sol_watts < MIN_SOL_WATTS) {          //if watts input from the solar panel is less than
-        power_status.mode = auto_off;                    //the minimum solar watts then it is getting dark so
-        off_count = OFF_NUM;                    //go to the charger off state
+        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; 
       }

        pwm += 1;                              //increment the pwm to get it back up to the float voltage
        set_pwm_duty(pwm);					
        if (pwm >= 100) {                      //if pwm gets up to 100 it means we can't keep the battery at
          power_status.mode = bulk;                //float voltage so jump to charger bulk state to charge the battery
        }
      }
      break;
    case auto_off:                                  //when we jump into the charger off state, off_count is set with OFF_NUM
      if (off_count > 0) {                     //this means that we run through the off state OFF_NUM of times with out doing
        off_count--;                           //anything, this is to allow the battery voltage to settle down to see if the  
      }                                        //battery has been disconnected
      else if ((bat_volts > HIGH_BAT_VOLTS) && (bat_volts < MAX_BAT_VOLTS) && (sol_volts > bat_volts)) {
        power_status.mode = bat_float;             //if battery voltage is still high and solar volts are high
        set_pwm_duty(pwm);		       //change charger state to battery float			
        TURN_ON_MOSFETS; 
      }
      else if ((bat_volts > MIN_BAT_VOLTS) && (bat_volts < MAX_BAT_VOLTS) && (sol_volts > bat_volts)) {
        pwm = PWM_START;                        // if battery volts aren't quite so high but we have solar volts
        set_pwm_duty(pwm);			                // greater than battery volts showing it is day light then	
        power_status.mode = mppt_on;            // change charger state to on so we start charging
        TURN_ON_MOSFETS; 
      }
      break;
    default:
      TURN_OFF_MOSFETS;                        //else stay in the off state
      break;
  }
}

  lpf_out_volts.Init();
  lpf_in_amps.Init();

  state_switch(MODE_OFF);                     // start with charger state as off
  //state_switch(MODE_CONST_VOLT, 300);                       // start with charger state as off
}

//------------------------------------------------------------------------------------------------------
