Replaced exponential avg. by block-average for MPP measurement
This commit is contained in:
parent
0e59b70465
commit
56b44e8d1e
25
src/main.c
25
src/main.c
|
@ -373,9 +373,12 @@ struct MPPState {
|
||||||
|
|
||||||
fxp_t maxPower;
|
fxp_t maxPower;
|
||||||
int32_t maxPWM;
|
int32_t maxPWM;
|
||||||
|
|
||||||
|
fxp_t powerAccu;
|
||||||
|
int32_t powerSamples;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MPP_TEST_DURATION 25 /* ms */
|
#define MPP_TEST_DURATION 10 /* ms */
|
||||||
|
|
||||||
#define MPP_TEST_STEPS 4
|
#define MPP_TEST_STEPS 4
|
||||||
const int32_t mpp_pwm_offsets[MPP_TEST_STEPS] = {-51, -4, 5, 50};
|
const int32_t mpp_pwm_offsets[MPP_TEST_STEPS] = {-51, -4, 5, 50};
|
||||||
|
@ -397,12 +400,24 @@ static void mpp_run(
|
||||||
mpp_state->maxPower = 0;
|
mpp_state->maxPower = 0;
|
||||||
mpp_state->maxPWM = *pwm;
|
mpp_state->maxPWM = *pwm;
|
||||||
|
|
||||||
|
mpp_state->powerAccu = 0;
|
||||||
|
mpp_state->powerSamples = 0;
|
||||||
|
|
||||||
*pwm = *pwm + mpp_pwm_offsets[0];
|
*pwm = *pwm + mpp_pwm_offsets[0];
|
||||||
} else if(mpp_state->testIdx < MPP_TEST_STEPS) {
|
} else if(mpp_state->testIdx < MPP_TEST_STEPS) {
|
||||||
/* test running */
|
/* 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) {
|
if(time_in_state > mpp_state->nextTestStepTime) {
|
||||||
if(power_state->power_avg > mpp_state->maxPower) {
|
/* averaging */
|
||||||
mpp_state->maxPower = power_state->power_avg;
|
mpp_state->powerAccu = fxp_div(mpp_state->powerAccu, fxp_from_int(mpp_state->powerSamples));
|
||||||
|
|
||||||
|
if(mpp_state->powerAccu > mpp_state->maxPower) {
|
||||||
|
mpp_state->maxPower = mpp_state->powerAccu;
|
||||||
mpp_state->maxPWM = *pwm;
|
mpp_state->maxPWM = *pwm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,6 +427,10 @@ static void mpp_run(
|
||||||
*pwm = mpp_state->refPWM + mpp_pwm_offsets[mpp_state->testIdx];
|
*pwm = mpp_state->refPWM + mpp_pwm_offsets[mpp_state->testIdx];
|
||||||
|
|
||||||
mpp_state->nextTestStepTime = time_in_state + MPP_TEST_DURATION;
|
mpp_state->nextTestStepTime = time_in_state + MPP_TEST_DURATION;
|
||||||
|
|
||||||
|
mpp_state->powerAccu = 0;
|
||||||
|
mpp_state->powerSamples = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue