Some MPP tuning
This commit is contained in:
parent
11d0878864
commit
8ed36f6770
49
src/main.c
49
src/main.c
|
@ -380,10 +380,13 @@ struct MPPState {
|
|||
int32_t mppMaxPWM;
|
||||
};
|
||||
|
||||
#define MPP_TEST_DURATION 10 /* ms */
|
||||
#define MPP_TEST_IGNORE_DURATION 5 /* ms */
|
||||
#define MPP_TEST_ACCU_DURATION 20 /* ms */
|
||||
|
||||
#define MPP_TEST_STEPS 4
|
||||
const int32_t mpp_pwm_offsets[MPP_TEST_STEPS] = {-3, 4, -21, 20};
|
||||
#define MPP_TEST_DURATION (MPP_TEST_IGNORE_DURATION + MPP_TEST_ACCU_DURATION)
|
||||
|
||||
#define MPP_TEST_STEPS 6
|
||||
const int32_t mpp_pwm_offsets[MPP_TEST_STEPS] = {-3, 4, -16, 15};
|
||||
|
||||
static void mpp_run(
|
||||
uint32_t time_in_state, struct MPPState *mpp_state,
|
||||
|
@ -410,14 +413,33 @@ static void mpp_run(
|
|||
/* test running */
|
||||
|
||||
/* accumulation */
|
||||
mpp_state->powerAccu = fxp_add(mpp_state->powerAccu,
|
||||
fxp_mult(power_state->vout, power_state->current));
|
||||
mpp_state->powerSamples++;
|
||||
if(time_in_state > (mpp_state->nextTestStepTime - MPP_TEST_ACCU_DURATION)) {
|
||||
mpp_state->powerAccu = fxp_add(mpp_state->powerAccu,
|
||||
fxp_mult(power_state->vout, power_state->current));
|
||||
mpp_state->powerSamples++;
|
||||
}
|
||||
|
||||
if(time_in_state > mpp_state->nextTestStepTime) {
|
||||
/* averaging */
|
||||
mpp_state->powerAccu = fxp_div(mpp_state->powerAccu, fxp_from_int(mpp_state->powerSamples));
|
||||
|
||||
#ifdef DEBUG
|
||||
char msg[16];
|
||||
debug_send_string("Accu: ");
|
||||
fxp_format(mpp_state->powerAccu, msg, 3);
|
||||
debug_send_string(msg);
|
||||
debug_send_string(" ");
|
||||
fxp_format_int(mpp_state->powerSamples, msg);
|
||||
debug_send_string(msg);
|
||||
debug_send_string(" PWM: ");
|
||||
fxp_format_int(*pwm, msg);
|
||||
debug_send_string(msg);
|
||||
debug_send_string(" Idx: ");
|
||||
fxp_format_int(mpp_state->testIdx, msg);
|
||||
debug_send_string(msg);
|
||||
debug_send_string("\r\n");
|
||||
#endif
|
||||
|
||||
if(mpp_state->powerAccu > mpp_state->maxPower) {
|
||||
mpp_state->maxPower = mpp_state->powerAccu;
|
||||
mpp_state->maxPWM = *pwm;
|
||||
|
@ -439,18 +461,19 @@ static void mpp_run(
|
|||
} else if(mpp_state->testIdx == MPP_TEST_STEPS) {
|
||||
/* finalize test */
|
||||
if(mpp_state->maxPower > mpp_state->refPower) {
|
||||
/* better PWM value found -> initiate new test to reach MPP */
|
||||
mpp_state->testIdx = -1;
|
||||
|
||||
mpp_state->refPower = mpp_state->maxPower;
|
||||
*pwm = mpp_state->maxPWM;
|
||||
|
||||
/* test again after a short time */
|
||||
mpp_state->testIdx++;
|
||||
mpp_state->nextTestStepTime = time_in_state + 250;
|
||||
} else {
|
||||
/* We were already at the maximum power point */
|
||||
*pwm = mpp_state->refPWM;
|
||||
|
||||
/* test again after some time */
|
||||
mpp_state->testIdx++;
|
||||
mpp_state->nextTestStepTime = time_in_state + 5000;
|
||||
mpp_state->nextTestStepTime = time_in_state + 20000;
|
||||
}
|
||||
} else {
|
||||
/* no test active, just holding PWM */
|
||||
|
@ -526,7 +549,7 @@ int main(void)
|
|||
fxp_t VOUT_SCALE = fxp_from_float(12.6f / 1620.0f);
|
||||
fxp_t CURRENT_SCALE = fxp_from_float(9.01f / 4095.0f);
|
||||
|
||||
fxp_t CURRENT_OFFSET = fxp_from_float(0.049);
|
||||
fxp_t CURRENT_OFFSET = fxp_from_float(0.045);
|
||||
|
||||
/* if power changes by more than this factor, MPP is tested again */
|
||||
MPP_MAX_POWER_CHANGE_FACTOR = fxp_from_float(0.2f);
|
||||
|
@ -747,6 +770,8 @@ int main(void)
|
|||
// limit has gone too low -> retry at maximum
|
||||
mpp_state.mppMaxPWM = CONV_PWM_MAX;
|
||||
}
|
||||
|
||||
pwm = mpp_state.mppMaxPWM;
|
||||
}
|
||||
|
||||
if(power_state.vout_avg > MAX_VOLTAGE) {
|
||||
|
@ -797,7 +822,9 @@ int main(void)
|
|||
lcd_send_string(") ");
|
||||
while(lcd_process() == 0); // send everything immediately
|
||||
|
||||
#ifndef DEBUG
|
||||
deepsleep(sleep_time);
|
||||
#endif
|
||||
|
||||
// Woke up again.
|
||||
lcd_set_cursor_pos(0, 0);
|
||||
|
|
Loading…
Reference in a new issue