Some MPPT tweaks (not final yet)

This commit is contained in:
Thomas Kolb 2016-08-17 22:05:01 +02:00
parent c93c3d41fb
commit 473253f5ab

View file

@ -355,14 +355,17 @@ static void report_status(fxp_t vin, fxp_t vout, fxp_t current,
int main(void) int main(void)
{ {
uint16_t cpuload = 0; uint32_t cpuload = 0;
uint64_t timebase_ms = 0; uint64_t timebase_ms = 0;
uint32_t time_in_state = 0; uint32_t time_in_state = 0;
char msg[128]; char msg[128];
char number[FXP_STR_MAXLEN]; char number[FXP_STR_MAXLEN];
uint8_t sentSomething = 0; uint8_t sentSomething = 0;
fxp_t prevPower = 0;
int32_t prevPWM = 0;
int32_t pwm = 0; int32_t pwm = 0;
int32_t mpp_step = 5;
enum OperState operState = Bootstrap; enum OperState operState = Bootstrap;
enum OperState nextState = ConvConstVoltage; enum OperState nextState = ConvConstVoltage;
@ -378,6 +381,7 @@ int main(void)
fxp_t testPower[2]; fxp_t testPower[2];
int32_t testPWM[2]; int32_t testPWM[2];
int testPWMStep = 5; int testPWMStep = 5;
uint32_t next_power_test = 0;
uint32_t sleep_time = 10; uint32_t sleep_time = 10;
uint64_t force_display_update_time = 1000; uint64_t force_display_update_time = 1000;
@ -389,7 +393,7 @@ int main(void)
fxp_t PGAIN_CC = fxp_from_float( 50.000f); fxp_t PGAIN_CC = fxp_from_float( 50.000f);
fxp_t IGAIN_CC = fxp_from_float( 0.300f); fxp_t IGAIN_CC = fxp_from_float( 0.300f);
fxp_t CURRENT_THRESHOLD = fxp_from_float(0.002f); fxp_t CURRENT_THRESHOLD = fxp_from_float(0.001f);
fxp_t AVG_FACT = fxp_from_float(0.10f); fxp_t AVG_FACT = fxp_from_float(0.10f);
fxp_t AVG_FACT_INV = fxp_sub(fxp_from_int(1), AVG_FACT); fxp_t AVG_FACT_INV = fxp_sub(fxp_from_int(1), AVG_FACT);
@ -537,7 +541,7 @@ int main(void)
timer_set_oc_value(TIM1, TIM_CH_CONV, 0); timer_set_oc_value(TIM1, TIM_CH_CONV, 0);
} }
if(time_in_state > 5000 && pwm > CONV_PWM_MAX && current < CURRENT_THRESHOLD) { if(time_in_state > 5000 && pwm > CONV_PWM_MAX && current_avg < CURRENT_THRESHOLD) {
operState = Bootstrap; operState = Bootstrap;
nextState = ConvConstVoltage; nextState = ConvConstVoltage;
} }
@ -582,7 +586,7 @@ int main(void)
timer_set_oc_value(TIM1, TIM_CH_CONV, 0); timer_set_oc_value(TIM1, TIM_CH_CONV, 0);
} }
if(time_in_state > 5000 && pwm > CONV_PWM_MAX && current < CURRENT_THRESHOLD) { if(time_in_state > 5000 && pwm > CONV_PWM_MAX && current_avg < CURRENT_THRESHOLD) {
operState = Bootstrap; operState = Bootstrap;
nextState = ConvConstCurrent; nextState = ConvConstCurrent;
} }
@ -600,7 +604,7 @@ int main(void)
// bootstrap off // bootstrap off
timer_set_oc_value(TIM1, TIM_CH_BOOTSTRAP, 0); timer_set_oc_value(TIM1, TIM_CH_BOOTSTRAP, 0);
if((time_in_state % 50) == 0) { if((time_in_state % 10) == 0) {
switch(testPWMStep) { switch(testPWMStep) {
case 0: case 0:
case 2: case 2:
@ -614,14 +618,28 @@ int main(void)
break; break;
case 4: case 4:
if(testPower[1] > testPower[0]) { if(testPower[1] > prevPower) {
pwm = testPWM[1]; pwm = testPWM[1];
} else { next_power_test = time_in_state + 10;
mpp_step++;
} else if(testPower[0] > prevPower) {
pwm = testPWM[0]; pwm = testPWM[0];
next_power_test = time_in_state + 10;
mpp_step++;
} else {
pwm = prevPWM;
next_power_test = time_in_state + 200;
mpp_step--;
} }
if(pwm < (CONV_PWM_PERIOD/2)) { if(mpp_step > 30) {
pwm = 3 * CONV_PWM_PERIOD / 4; mpp_step = 30;
} else if(mpp_step < 1) {
mpp_step = 1;
}
if(pwm < CONV_PWM_MAX / 10) {
pwm = CONV_PWM_MAX / 10;
} else if(pwm > CONV_PWM_MAX) { } else if(pwm > CONV_PWM_MAX) {
pwm = CONV_PWM_MAX; pwm = CONV_PWM_MAX;
} }
@ -630,12 +648,14 @@ int main(void)
break; break;
case 5: case 5:
// power test is currently idle, but power has changed // initiate a new power test
// too much. if(time_in_state >= next_power_test) {
// -> start a new one. testPWM[0] = pwm + mpp_step + 1;
testPWM[0] = pwm + 4; testPWM[1] = pwm - mpp_step;
testPWM[1] = pwm - 3;
testPWMStep = 0; testPWMStep = 0;
prevPower = power_avg;
prevPWM = pwm;
}
break; break;
default: default:
@ -643,12 +663,16 @@ int main(void)
break; break;
} }
if(testPWMStep < 5) {
testPWMStep++; testPWMStep++;
} }
}
if(time_in_state > 5000 && current < CURRENT_THRESHOLD) { if(time_in_state > 5000 && current_avg < CURRENT_THRESHOLD) {
operState = Bootstrap; operState = Bootstrap;
nextState = ConvMPP; nextState = ConvMPP;
pwm = 8 * CONV_PWM_PERIOD / 10;
next_power_test = 0;
} }
if(vout_avg > MAX_VOLTAGE) { if(vout_avg > MAX_VOLTAGE) {
@ -663,6 +687,18 @@ int main(void)
operState = Idle; operState = Idle;
} }
#ifdef DEBUG
if((time_in_state % 100) == 0) {
debug_send_string("PWM: ");
fxp_format_int(pwm, msg);
debug_send_string(msg);
debug_send_string(" Step: ");
fxp_format_int(mpp_step, msg);
debug_send_string(msg);
sentSomething = 1;
}
#endif
break; break;
case Idle: case Idle: