Limit max. PWM value in MPP if power is lost too often
This commit is contained in:
parent
56b44e8d1e
commit
9e353c3248
18
src/main.c
18
src/main.c
|
@ -376,6 +376,8 @@ struct MPPState {
|
||||||
|
|
||||||
fxp_t powerAccu;
|
fxp_t powerAccu;
|
||||||
int32_t powerSamples;
|
int32_t powerSamples;
|
||||||
|
|
||||||
|
int32_t mppMaxPWM;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MPP_TEST_DURATION 10 /* ms */
|
#define MPP_TEST_DURATION 10 /* ms */
|
||||||
|
@ -533,6 +535,8 @@ int main(void)
|
||||||
power_state.vout_avg = 0;
|
power_state.vout_avg = 0;
|
||||||
power_state.current_avg = 0;
|
power_state.current_avg = 0;
|
||||||
|
|
||||||
|
mpp_state.mppMaxPWM = CONV_PWM_MAX;
|
||||||
|
|
||||||
init_clock();
|
init_clock();
|
||||||
init_rtc();
|
init_rtc();
|
||||||
init_gpio();
|
init_gpio();
|
||||||
|
@ -719,18 +723,24 @@ int main(void)
|
||||||
|
|
||||||
mpp_run(time_in_state, &mpp_state, &power_state, &pwm);
|
mpp_run(time_in_state, &mpp_state, &power_state, &pwm);
|
||||||
|
|
||||||
if(pwm > CONV_PWM_MAX) {
|
if(pwm > mpp_state.mppMaxPWM) {
|
||||||
pwm = CONV_PWM_MAX;
|
pwm = mpp_state.mppMaxPWM;
|
||||||
} else if(pwm < CONV_PWM_PERIOD/100) {
|
} else if(pwm < CONV_PWM_PERIOD/100) {
|
||||||
pwm = CONV_PWM_PERIOD/100;
|
pwm = CONV_PWM_PERIOD/100;
|
||||||
}
|
}
|
||||||
|
|
||||||
timer_set_oc_value(TIM1, TIM_CH_CONV, pwm);
|
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) {
|
if(time_in_state > 5000 && power_state.current_avg < CURRENT_THRESHOLD) {
|
||||||
operState = Bootstrap;
|
operState = Bootstrap;
|
||||||
nextState = ConvMPP;
|
nextState = ConvMPP;
|
||||||
mpp_state.testIdx = -1;
|
mpp_state.testIdx = -1;
|
||||||
|
mpp_state.mppMaxPWM -= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(power_state.vout_avg > MAX_VOLTAGE) {
|
if(power_state.vout_avg > MAX_VOLTAGE) {
|
||||||
|
@ -743,6 +753,7 @@ int main(void)
|
||||||
|
|
||||||
if(power_state.vin_avg < power_state.vout_avg) {
|
if(power_state.vin_avg < power_state.vout_avg) {
|
||||||
operState = Idle;
|
operState = Idle;
|
||||||
|
mpp_state.mppMaxPWM = CONV_PWM_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -750,6 +761,9 @@ int main(void)
|
||||||
debug_send_string("PWM: ");
|
debug_send_string("PWM: ");
|
||||||
fxp_format_int(pwm, msg);
|
fxp_format_int(pwm, msg);
|
||||||
debug_send_string(msg);
|
debug_send_string(msg);
|
||||||
|
debug_send_string(" Limit: ");
|
||||||
|
fxp_format_int(mpp_state.mppMaxPWM, msg);
|
||||||
|
debug_send_string(msg);
|
||||||
sentSomething = 1;
|
sentSomething = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue