Reinitialize MPPT whenever it becomes active
This commit is contained in:
parent
3806536c07
commit
1d5b7e74ff
28
src/main.c
28
src/main.c
|
@ -436,6 +436,18 @@ struct MPPState {
|
||||||
#define MPP_TEST_STEPS 6
|
#define MPP_TEST_STEPS 6
|
||||||
const int32_t mpp_pwm_offsets[MPP_TEST_STEPS] = {-1, 2, -6, 5};
|
const int32_t mpp_pwm_offsets[MPP_TEST_STEPS] = {-1, 2, -6, 5};
|
||||||
|
|
||||||
|
static void mpp_init(struct MPPState *mpp_state)
|
||||||
|
{
|
||||||
|
mpp_state->powerSamples = 0;
|
||||||
|
mpp_state->powerAccu = 0;
|
||||||
|
mpp_state->maxPower = 0;
|
||||||
|
mpp_state->refPower = 0;
|
||||||
|
mpp_state->nextTestStepTime = 0;
|
||||||
|
mpp_state->testIdx = -1;
|
||||||
|
mpp_state->maxPWM = CONV_PWM_MAX;
|
||||||
|
mpp_state->refPWM = CONV_PWM_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
static void mpp_run(
|
static void mpp_run(
|
||||||
uint32_t time_in_state, struct MPPState *mpp_state,
|
uint32_t time_in_state, struct MPPState *mpp_state,
|
||||||
struct PowerState *power_state, int32_t *pwm)
|
struct PowerState *power_state, int32_t *pwm)
|
||||||
|
@ -635,14 +647,7 @@ int main(void)
|
||||||
power_state.temp_avg = fxp_from_int(-999);
|
power_state.temp_avg = fxp_from_int(-999);
|
||||||
|
|
||||||
/* initialize mpp_state */
|
/* initialize mpp_state */
|
||||||
mpp_state.powerSamples = 0;
|
mpp_init(&mpp_state);
|
||||||
mpp_state.powerAccu = 0;
|
|
||||||
mpp_state.maxPower = 0;
|
|
||||||
mpp_state.refPower = 0;
|
|
||||||
mpp_state.nextTestStepTime = 0;
|
|
||||||
mpp_state.testIdx = -1;
|
|
||||||
mpp_state.maxPWM = CONV_PWM_MAX;
|
|
||||||
mpp_state.refPWM = CONV_PWM_MAX;
|
|
||||||
|
|
||||||
init_clock();
|
init_clock();
|
||||||
init_rtc();
|
init_rtc();
|
||||||
|
@ -830,7 +835,6 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(time_in_state > 1000 && power_state.vout_avg < VOLTAGE_THR_CV_TO_MPP) {
|
if(time_in_state > 1000 && power_state.vout_avg < VOLTAGE_THR_CV_TO_MPP) {
|
||||||
pwm = CONV_PWM_PERIOD * 8 / 10;
|
|
||||||
operState = ConvMPP;
|
operState = ConvMPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -896,7 +900,6 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(time_in_state > 1000 && power_state.vout_avg < VOLTAGE_THR_FLOAT_TO_MPP) {
|
if(time_in_state > 1000 && power_state.vout_avg < VOLTAGE_THR_FLOAT_TO_MPP) {
|
||||||
pwm = CONV_PWM_MAX * 8 / 10;
|
|
||||||
operState = ConvMPP;
|
operState = ConvMPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -952,6 +955,11 @@ int main(void)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConvMPP:
|
case ConvMPP:
|
||||||
|
if(time_in_state == 0) {
|
||||||
|
pwm = CONV_PWM_MAX * 8 / 10;
|
||||||
|
mpp_init(&mpp_state);
|
||||||
|
}
|
||||||
|
|
||||||
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 > CONV_PWM_MAX) {
|
||||||
|
|
Loading…
Reference in a new issue