Преглед изворни кода

Load algorithm improvements

The code now supports two algorithms, you can decide at compile time.
The first algorithm (the default) will turn on the load when the
battery is not fully discharged and there is no solar power. You'd use
that for lighting. The second algorithm turns on the load when the
battery is fully charged and there is solar power. You'd use that as
a dump circuit (if you have something to do with excess power).
Ron Kuris пре 10 година
родитељ
комит
98f0543aa8
1 измењених фајлова са 22 додато и 10 уклоњено
  1. 22 10
      MPPT_Code_ESP8266/MPPT_Code_ESP8266.ino

+ 22 - 10
MPPT_Code_ESP8266/MPPT_Code_ESP8266.ino

@@ -57,6 +57,11 @@
 // Turn this on to use the ESP8266 chip. If you set this to 0, the periodic updates will not happen
 #define ENABLE_DATALOGGER 1
 
+// Load control algorithm
+// 0 - NIGHT LIGHT: Load ON when there is no solar power and battery is above LVD (low voltage disconnect)
+// 1 - POWER DUMP: Load ON when there is solar power and the battery is above BATT_FLOAT (charged)
+#define LOAD_ALGORITHM 0
+
 #define SOL_AMPS_CHAN 1                // Defining the adc channel to read solar amps
 #define SOL_VOLTS_CHAN 0               // defining the adc channel to read solar volts
 #define SOL_AMPS_CHAN 1                // Defining the adc channel to read solar amps
@@ -234,7 +239,7 @@ unsigned long time = 0;               // variable to store time the back light c
 int delta = PWM_INC;                  // variable used to modify pwm duty cycle for the ppt algorithm
 int pwm = 0;                          // pwm duty cycle 0-100%
 int back_light_pin_State = 0;         // variable for storing the state of the backlight button
-int load_status = 0;                  // variable for storing the load output state (for writing to LCD)
+boolean load_status = false;                  // variable for storing the load output state (for writing to LCD)
   
 enum charger_mode {off, on, bulk, bat_float} charger_state;    // enumerated variable that holds state for charger state machine
 // set the LCD address to 0x27 for a 20 chars 4 line display
@@ -480,15 +485,22 @@ void run_charger(void) {
 //----------------------------------------------------------------------------------------------------------------------
 /////////////////////////////////////////////LOAD CONTROL/////////////////////////////////////////////////////
 //----------------------------------------------------------------------------------------------------------------------  
-  
+
 void load_control(){
-  if ((sol_watts < MIN_SOL_WATTS) && (bat_volts > LVD)){   // If the panel isn't producing, it's probably night
-    digitalWrite(LOAD_PIN, LOW);                           // turn the load on
-    load_status = 1;                                       // record that the load is on
-  }
-  else{                                                    // If the panel is producing, it's day time
-    digitalWrite(LOAD_PIN, HIGH);                          // turn the load off
-    load_status = 0;                                       // record that the load is off
+#if LOAD_ALGORITHM == 0
+  // turn on loads at night when the solar panel is not producing power
+  // as long as the battery voltage is above LVD
+  load_on(sol_watts < MIN_SOL_WATTS && bat_volts > LVD);
+#else
+  // dump excess solar energy into the load circuit
+  load_on(sol_watts > MIN_SOL_WATTS && bat_volts > BATT_FLOAT);
+#endif
+}
+
+void load_on(boolean new_status) {
+  if (load_status != new_status) {
+    load_status = new_status;
+    digitalWrite(LOAD_PIN, new_status ? HIGH : LOW);
   }
 }
 
@@ -642,7 +654,7 @@ void lcd_display()
  lcd.setCursor(15,2);
  lcd.print("Load");
  lcd.setCursor(15,3);
- if (load_status == 1)
+ if (load_status)
  {
     lcd.print("On  ");
  }