Current calibration of v1.1 (hopefully the final one)

This commit is contained in:
Thomas Kolb 2016-10-09 01:25:33 +02:00
parent c11cb28558
commit ba11fa287c

View file

@ -26,6 +26,8 @@
#define MAX_SLEEP_TIME 3600 #define MAX_SLEEP_TIME 3600
#define MAX_SLEEP_TIME_LOW_VOLTAGE 300 #define MAX_SLEEP_TIME_LOW_VOLTAGE 300
#define CURRENT_ADC_OFFSET 89
enum OperState { enum OperState {
Bootstrap, Bootstrap,
ConvConstVoltage, ConvConstVoltage,
@ -37,7 +39,7 @@ enum OperState {
volatile int wait_frame = 1; volatile int wait_frame = 1;
#define ADC_NUM_CHANNELS 3 #define ADC_NUM_CHANNELS 3
volatile uint16_t adc_values[ADC_NUM_CHANNELS]; volatile int16_t adc_values[ADC_NUM_CHANNELS];
static void unlock_rtc_access(void) static void unlock_rtc_access(void)
{ {
@ -535,7 +537,7 @@ int main(void)
fxp_t CURRENT_THRESHOLD = fxp_from_float(0.001f); fxp_t CURRENT_THRESHOLD = fxp_from_float(0.001f);
fxp_t AVG_FACT = fxp_from_float(0.05f); fxp_t AVG_FACT = fxp_from_float(0.01f);
fxp_t AVG_FACT_INV = fxp_sub(fxp_from_int(1), AVG_FACT); fxp_t AVG_FACT_INV = fxp_sub(fxp_from_int(1), AVG_FACT);
fxp_t MAX_VOLTAGE = fxp_from_float(14.400f); fxp_t MAX_VOLTAGE = fxp_from_float(14.400f);
@ -565,9 +567,7 @@ int main(void)
// Calibrated from measurements // Calibrated from measurements
fxp_t VIN_SCALE = fxp_from_float(36.41f / 4096.0f); fxp_t VIN_SCALE = fxp_from_float(36.41f / 4096.0f);
fxp_t VOUT_SCALE = fxp_from_float(30.87f / 4096.0f); fxp_t VOUT_SCALE = fxp_from_float(30.87f / 4096.0f);
fxp_t CURRENT_SCALE = fxp_from_float(9.10f / 4096.0f); fxp_t CURRENT_SCALE = fxp_from_float(8.60f / 4096.0f);
fxp_t CURRENT_OFFSET = fxp_from_float(0.196);
/* if power changes by more than this factor, MPP is tested again */ /* if power changes by more than this factor, MPP is tested again */
MPP_MAX_POWER_CHANGE_FACTOR = fxp_from_float(0.2f); MPP_MAX_POWER_CHANGE_FACTOR = fxp_from_float(0.2f);
@ -664,8 +664,7 @@ int main(void)
// convert read values // convert read values
power_state.vin = fxp_mult(fxp_from_int(adc_values[0]), VIN_SCALE); power_state.vin = fxp_mult(fxp_from_int(adc_values[0]), VIN_SCALE);
power_state.vout = fxp_mult(fxp_from_int(adc_values[1]), VOUT_SCALE); power_state.vout = fxp_mult(fxp_from_int(adc_values[1]), VOUT_SCALE);
power_state.current = fxp_mult(fxp_from_int(adc_values[2]), CURRENT_SCALE); power_state.current = fxp_mult(fxp_from_int(adc_values[2] - CURRENT_ADC_OFFSET), CURRENT_SCALE);
power_state.current = fxp_sub(power_state.current, CURRENT_OFFSET);
power_state.vin_avg = fxp_add(fxp_mult(power_state.vin, AVG_FACT), fxp_mult(power_state.vin_avg, AVG_FACT_INV)); power_state.vin_avg = fxp_add(fxp_mult(power_state.vin, AVG_FACT), fxp_mult(power_state.vin_avg, AVG_FACT_INV));
power_state.vout_avg = fxp_add(fxp_mult(power_state.vout, AVG_FACT), fxp_mult(power_state.vout_avg, AVG_FACT_INV)); power_state.vout_avg = fxp_add(fxp_mult(power_state.vout, AVG_FACT), fxp_mult(power_state.vout_avg, AVG_FACT_INV));