diff --git a/src/core/tasks.c b/src/core/tasks.c index ed6096461..99548a3ba 100644 --- a/src/core/tasks.c +++ b/src/core/tasks.c @@ -20,9 +20,6 @@ #include "rx/rx.h" void util_task() { - // battery low logic - vbat_calc(); - // check gestures gestures(); @@ -45,6 +42,7 @@ FAST_RAM task_t tasks[TASK_MAX] = { [TASK_IMU] = CREATE_TASK("IMU", TASK_MASK_ALWAYS, TASK_PRIORITY_REALTIME, imu_calc, 0), [TASK_PID] = CREATE_TASK("PID", TASK_MASK_ALWAYS, TASK_PRIORITY_REALTIME, control, 0), [TASK_RX] = CREATE_TASK("RX", TASK_MASK_ALWAYS, TASK_PRIORITY_REALTIME, rx_update, 0), + [TASK_VBAT] = CREATE_TASK("VBAT", TASK_MASK_ALWAYS, TASK_PRIORITY_HIGH, vbat_calc, 1000), [TASK_UTIL] = CREATE_TASK("UTIL", TASK_MASK_ALWAYS, TASK_PRIORITY_HIGH, util_task, 0), [TASK_BLACKBOX] = CREATE_TASK("BLACKBOX", TASK_MASK_ALWAYS, TASK_PRIORITY_MEDIUM, blackbox_update, 0), [TASK_OSD] = CREATE_TASK("OSD", TASK_MASK_ALWAYS, TASK_PRIORITY_MEDIUM, osd_display, 8000), diff --git a/src/core/tasks.h b/src/core/tasks.h index e523303c5..bd8f1feb9 100644 --- a/src/core/tasks.h +++ b/src/core/tasks.h @@ -10,6 +10,7 @@ typedef enum { TASK_IMU, TASK_PID, TASK_RX, + TASK_VBAT, TASK_UTIL, TASK_BLACKBOX, TASK_OSD, diff --git a/src/io/vbat.c b/src/io/vbat.c index 5b3ee7dee..57e4e8714 100644 --- a/src/io/vbat.c +++ b/src/io/vbat.c @@ -19,7 +19,7 @@ void vbat_init() { int count = 0; while (count < 5000) { state.vbat = adc_read(ADC_CHAN_VBAT); - lpf(&state.vbat_filtered, state.vbat, 0.9968f); + lpf(&state.vbat_filtered, state.vbat, lpfcalc(1, 500)); count++; } @@ -87,12 +87,12 @@ void vbat_calc() { // read acd and scale based on processor voltage state.ibat = adc_read(ADC_CHAN_IBAT); - lpf(&state.ibat_filtered, state.ibat, lpfcalc(1000, 5000e3)); + lpf(&state.ibat_filtered, state.ibat, lpfcalc(1, 10000)); // li-ion battery model compensation time decay ( 18 seconds ) state.vbat = adc_read(ADC_CHAN_VBAT); - lpf(&state.vbat_filtered, state.vbat, 0.9968f); - lpf(&state.vbat_filtered_decay, state.vbat_filtered, lpfcalc(1000, 18000e3)); + lpf(&state.vbat_filtered, state.vbat, lpfcalc(1, 500)); + lpf(&state.vbat_filtered_decay, state.vbat_filtered, lpfcalc(1, 18000)); state.vbat_cell_avg = state.vbat_filtered_decay / (float)state.lipo_cell_count; @@ -100,7 +100,7 @@ void vbat_calc() { // filter motorpwm so it has the same delay as the filtered voltage // ( or they can use a single filter) static float thrfilt = 0; - lpf(&thrfilt, state.thrsum, 0.9968f); // 0.5 sec at 1.6ms loop time + lpf(&thrfilt, state.thrsum, lpfcalc(1, 500)); const float tempvolt = state.vbat_filtered * (1.00f + CF1) - state.vbat_filtered_decay * (CF1);