Your implementation is based on the state machines, this a descrete one. Pretty hard coded right.
LMIN_SOL_WATTS to 5 watts , and etc etc..
Anyway this is not the pure dynamic implementation of MPPT algorithm. It's a binary search like
algorithm where it divides the search space by 2 and it's time complexity is lg(N).
Anyway I like your code. Only disadvantage is when somebody plug a different solar cell into your
design , he need to change the firmware values, cos it does not calculate it dynamically. I'm not
bugging anybody here, but with little study or review of that white paper, you could easily implement it.
Or change this existing code to work according to that.
This is like a reflexive agent, but will work with the solar cell that you planing. Problem is when somebody
connected another solar cell. that's I told this is hardcoded. Anyway one little simple effort. I'm not familiar with
arduno but your code is easy to read anyway. So I can't introduce a patch into this, I could not bug the author
at all.So nice work, but need some little more effort. There's no magic in that white paper.
I love state machine based implementation, keep up good coding.
And you could use [ code ] You Code [ / code ] tags.
like bellow -V
Code: Select all
void run_charger(void) {
static int off_count = OFF_NUM;
switch (charger_state) {
case on:
if (sol_watts < MIN_SOL_WATTS) { //if watts input from the solar panel is less than
charger_state = 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
charger_state = 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(); //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
charger_state = 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
charger_state = 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
charger_state = 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
charger_state = 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(); // 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
charger_state = off; //the minimum solar watts then it is getting dark so
off_count = OFF_NUM; //go to the charger off state
set_pwm_duty();
TURN_OFF_MOSFETS;
}
else if (bat_volts > MAX_BAT_VOLTS) { //since we're in the battery float state if the battery voltage
pwm -= 1; //is above the float voltage back off the pwm to lower it
set_pwm_duty();
}
else if (bat_volts < MAX_BAT_VOLTS) { //else if the battery voltage is less than the float voltage
pwm += 1; //increment the pwm to get it back up to the float voltage
set_pwm_duty();
if (pwm >= 100) { //if pwm gets up to 100 it means we can't keep the battery at
charger_state = bulk; //float voltage so jump to charger bulk state to charge the battery
}
}
break;
case 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)) {
charger_state = bat_float; //if battery voltage is still high and solar volts are high
set_pwm_duty(); //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(); //greater than battery volts showing it is day light then
charger_state = on; //change charger state to on so we start charging
TURN_ON_MOSFETS;
} //else stay in the off state
break;
default:
TURN_OFF_MOSFETS;
break;
}
}