added battery voltage calibration, see config.h

This commit is contained in:
larsm 2018-07-21 13:56:23 +02:00
parent 38cb5992f2
commit dd5a128199
4 changed files with 9 additions and 6 deletions

View File

@ -8,6 +8,10 @@
#define DC_CUR_LIMIT 15 // Motor DC current limit in amps. it does not disable motors, it is a soft current limit.
// Battery voltage calibration: connect power source. use multimeter to measure real voltage and write it to BAT_CALIB_REAL_VOLTAGE. watch UART on one of the sensor board cables. write value nr 4 to BAT_CALIB_ADC. make and flash firmware. you can verify voltage on UART debug value 5 (devide it by 100.0 to get calibrated voltage).
#define BAT_CALIB_REAL_VOLTAGE 42.0 // input voltage measured by multimeter
#define BAT_CALIB_ADC 1667 // adc-value measured by mainboard (value nr 4 on UART debug output)
#define BAT_LOW_LVL1 36.0 // gently beeps at this voltage level. ~3.6V/cell
#define BAT_LOW_LVL2 33.0 // your battery is almost empty. Charge now! ~3.3V/cell
#define BAT_LOW_DEAD 31.0 // undervoltage lockout. ~3.1V/cell

View File

@ -123,8 +123,7 @@
#define DELAY_TIM_FREQUENCY_US 1000000
#define MOTOR_AMP_CONV_DC_AMP 0.02
#define ADC_BATTERY_VOLT 0.02647435897435897435897435897436
#define MOTOR_AMP_CONV_DC_AMP 0.02 // A per bit (12) on ADC.
#define MILLI_R (R * 1000)
#define MILLI_PSI (PSI * 1000)

View File

@ -161,8 +161,8 @@ void DMA1_Channel1_IRQHandler() {
return;
}
if (buzzerTimer % 100 == 0) {
batteryVoltage = batteryVoltage * 0.999 + ((float)adc_buffer.batt1 * ADC_BATTERY_VOLT) * 0.001;
if (buzzerTimer % 100 == 0) { // because you get float rounding errors if it would run every time
batteryVoltage = batteryVoltage * 0.999 + ((float)adc_buffer.batt1 * ((float)BAT_CALIB_REAL_VOLTAGE / (float)BAT_CALIB_ADC)) * 0.001;
}

View File

@ -217,8 +217,8 @@ int main(void) {
#endif
setScopeChannel(2, (int)speedR);
setScopeChannel(3, (int)speedL);
// setScopeChannel(4, (int));
// setScopeChannel(5, (int));
setScopeChannel(4, (int)adc_buffer.batt1); // for battery voltage calibration
setScopeChannel(5, (int)(batteryVoltage * 100.0f)); // for verifying battery voltage calibration
// setScopeChannel(6, (int));
// setScopeChannel(7, (int));