Limit max. PWM value in MPP if power is lost too often

This commit is contained in:
Thomas Kolb 2016-08-21 19:05:27 +02:00
parent 56b44e8d1e
commit 9e353c3248
1 changed files with 16 additions and 2 deletions

View File

@ -376,6 +376,8 @@ struct MPPState {
fxp_t powerAccu;
int32_t powerSamples;
int32_t mppMaxPWM;
};
#define MPP_TEST_DURATION 10 /* ms */
@ -533,6 +535,8 @@ int main(void)
power_state.vout_avg = 0;
power_state.current_avg = 0;
mpp_state.mppMaxPWM = CONV_PWM_MAX;
init_clock();
init_rtc();
init_gpio();
@ -719,18 +723,24 @@ int main(void)
mpp_run(time_in_state, &mpp_state, &power_state, &pwm);
if(pwm > CONV_PWM_MAX) {
pwm = CONV_PWM_MAX;
if(pwm > mpp_state.mppMaxPWM) {
pwm = mpp_state.mppMaxPWM;
} else if(pwm < CONV_PWM_PERIOD/100) {
pwm = CONV_PWM_PERIOD/100;
}
timer_set_oc_value(TIM1, TIM_CH_CONV, pwm);
if((mpp_state.mppMaxPWM < CONV_PWM_MAX) && (mpp_state.mppMaxPWM > CONV_PWM_MAX/10) &&
time_in_state > 5000 && ((time_in_state % 3000) == 10)) {
mpp_state.mppMaxPWM++;
}
if(time_in_state > 5000 && power_state.current_avg < CURRENT_THRESHOLD) {
operState = Bootstrap;
nextState = ConvMPP;
mpp_state.testIdx = -1;
mpp_state.mppMaxPWM -= 10;
}
if(power_state.vout_avg > MAX_VOLTAGE) {
@ -743,6 +753,7 @@ int main(void)
if(power_state.vin_avg < power_state.vout_avg) {
operState = Idle;
mpp_state.mppMaxPWM = CONV_PWM_MAX;
}
#ifdef DEBUG
@ -750,6 +761,9 @@ int main(void)
debug_send_string("PWM: ");
fxp_format_int(pwm, msg);
debug_send_string(msg);
debug_send_string(" Limit: ");
fxp_format_int(mpp_state.mppMaxPWM, msg);
debug_send_string(msg);
sentSomething = 1;
}
#endif