Some MPPT tweaks (not final yet)
This commit is contained in:
parent
c93c3d41fb
commit
473253f5ab
66
src/main.c
66
src/main.c
|
@ -355,14 +355,17 @@ static void report_status(fxp_t vin, fxp_t vout, fxp_t current,
|
|||
|
||||
int main(void)
|
||||
{
|
||||
uint16_t cpuload = 0;
|
||||
uint32_t cpuload = 0;
|
||||
uint64_t timebase_ms = 0;
|
||||
uint32_t time_in_state = 0;
|
||||
char msg[128];
|
||||
char number[FXP_STR_MAXLEN];
|
||||
uint8_t sentSomething = 0;
|
||||
|
||||
fxp_t prevPower = 0;
|
||||
int32_t prevPWM = 0;
|
||||
int32_t pwm = 0;
|
||||
int32_t mpp_step = 5;
|
||||
|
||||
enum OperState operState = Bootstrap;
|
||||
enum OperState nextState = ConvConstVoltage;
|
||||
|
@ -378,6 +381,7 @@ int main(void)
|
|||
fxp_t testPower[2];
|
||||
int32_t testPWM[2];
|
||||
int testPWMStep = 5;
|
||||
uint32_t next_power_test = 0;
|
||||
|
||||
uint32_t sleep_time = 10;
|
||||
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 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_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);
|
||||
}
|
||||
|
||||
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;
|
||||
nextState = ConvConstVoltage;
|
||||
}
|
||||
|
@ -582,7 +586,7 @@ int main(void)
|
|||
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;
|
||||
nextState = ConvConstCurrent;
|
||||
}
|
||||
|
@ -600,7 +604,7 @@ int main(void)
|
|||
// bootstrap off
|
||||
timer_set_oc_value(TIM1, TIM_CH_BOOTSTRAP, 0);
|
||||
|
||||
if((time_in_state % 50) == 0) {
|
||||
if((time_in_state % 10) == 0) {
|
||||
switch(testPWMStep) {
|
||||
case 0:
|
||||
case 2:
|
||||
|
@ -614,14 +618,28 @@ int main(void)
|
|||
break;
|
||||
|
||||
case 4:
|
||||
if(testPower[1] > testPower[0]) {
|
||||
if(testPower[1] > prevPower) {
|
||||
pwm = testPWM[1];
|
||||
} else {
|
||||
next_power_test = time_in_state + 10;
|
||||
mpp_step++;
|
||||
} else if(testPower[0] > prevPower) {
|
||||
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)) {
|
||||
pwm = 3 * CONV_PWM_PERIOD / 4;
|
||||
if(mpp_step > 30) {
|
||||
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) {
|
||||
pwm = CONV_PWM_MAX;
|
||||
}
|
||||
|
@ -630,12 +648,14 @@ int main(void)
|
|||
break;
|
||||
|
||||
case 5:
|
||||
// power test is currently idle, but power has changed
|
||||
// too much.
|
||||
// -> start a new one.
|
||||
testPWM[0] = pwm + 4;
|
||||
testPWM[1] = pwm - 3;
|
||||
// initiate a new power test
|
||||
if(time_in_state >= next_power_test) {
|
||||
testPWM[0] = pwm + mpp_step + 1;
|
||||
testPWM[1] = pwm - mpp_step;
|
||||
testPWMStep = 0;
|
||||
prevPower = power_avg;
|
||||
prevPWM = pwm;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -643,12 +663,16 @@ int main(void)
|
|||
break;
|
||||
}
|
||||
|
||||
if(testPWMStep < 5) {
|
||||
testPWMStep++;
|
||||
}
|
||||
}
|
||||
|
||||
if(time_in_state > 5000 && current < CURRENT_THRESHOLD) {
|
||||
if(time_in_state > 5000 && current_avg < CURRENT_THRESHOLD) {
|
||||
operState = Bootstrap;
|
||||
nextState = ConvMPP;
|
||||
pwm = 8 * CONV_PWM_PERIOD / 10;
|
||||
next_power_test = 0;
|
||||
}
|
||||
|
||||
if(vout_avg > MAX_VOLTAGE) {
|
||||
|
@ -663,6 +687,18 @@ int main(void)
|
|||
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;
|
||||
|
||||
case Idle:
|
||||
|
|
Loading…
Reference in a new issue