@@ -570,12 +570,9 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
570570 }
571571 powerHistory.push (INA260 ::power_mW);
572572#elif LOAD_STRATEGY == LOAD_STRATEGY_VOLTAGE_LIV
573-
574- #endif
575- constexpr int_fast16_t V1SP_mV = 10000 ; // CONFIG - 10 V
576- constexpr int_fast16_t V2SP_mV = 15000 ; // CONFIG - 15 V
577- constexpr int_fast16_t V3SP_mV = 18000 ; // CONFIG - 18 V
578- constexpr float FALL_HYSTERESIS = 0 .95f ; // CONFIG - 5% margin
573+ constexpr int_fast16_t V1SP_mV = 10000 ; // CONFIG - 10 V
574+ constexpr int_fast16_t V2SP_mV = 15000 ; // CONFIG - 15 V
575+ constexpr int_fast16_t V3SP_mV = 18000 ; // CONFIG - 18 V
579576 constexpr uint_fast8_t LOAD_GPIO_V0SP =
580577 63 ; // CONFIG - GPIO for V1 setpoint
581578 constexpr uint_fast8_t LOAD_GPIO_V1SP =
@@ -586,46 +583,27 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
586583 5 ; // CONFIG - GPIO for V3 setpoint, must be different from V1 and
587584 // V2
588585
589- if (INA260 ::voltage_mV <
590- static_cast <int_fast16_t >(V1SP_mV * FALL_HYSTERESIS )) {
591- /* Fall below minimum: (< 10*0.05 V) */
592- load.setLoadGPIO (LOAD_GPIO_V0SP );
593- ESP_LOGI (TAG , " Voltage below %d mV, setting load to %d" , V2SP_mV,
594- LOAD_GPIO_V0SP );
595- } else if ((INA260 ::voltage_mV > V1SP_mV) &&
596- (INA260 ::voltage_mV <= V2SP_mV)) {
597- /* Increase to stage 2: !(< 10*0.05 V) & (> 10 V & < 15 V) */
586+ // Note: Could be more efficient (?) but then I'd have to add more flow
587+ // control
588+ if ((INA260 ::voltage_mV > V1SP_mV) && (INA260 ::voltage_mV <= V2SP_mV)) {
589+ /* Increase to stage 2: (> 10 V & < 15 V) */
598590 load.setLoadGPIO (LOAD_GPIO_V1SP );
599591 ESP_LOGI (TAG , " Voltage between %d mV and %d mV, setting load to %d" ,
600592 V1SP_mV, V2SP_mV, LOAD_GPIO_V1SP );
601- } else if (INA260 ::voltage_mV <
602- static_cast <int_fast16_t >(V2SP_mV * FALL_HYSTERESIS )) {
603- /* Fall to stage 2: !(< 10*0.05 V) & !(> 10 V & < 15 V) &
604- (< 15*0.05 V) */
605- load.setLoadGPIO (LOAD_GPIO_V1SP );
606- ESP_LOGI (TAG , " Voltage below %d mV, setting load to %d" , V2SP_mV,
607- LOAD_GPIO_V1SP );
608593 } else if ((INA260 ::voltage_mV > V2SP_mV) &&
609594 (INA260 ::voltage_mV <= V3SP_mV)) {
610- /* Increase to stage 3: !(< 10*0.05 V) & !(> 10 V & < 15 V) &
611- !(< 15*0.05 V) & (> 15 V & <= 18 V) */
595+ /* Increase to stage 3: !(> 10 V & < 15 V) & (> 15 V & <= 18 V) */
612596 load.setLoadGPIO (LOAD_GPIO_V2SP );
613597 ESP_LOGI (TAG , " Voltage above %d mV, setting load to %d" , V1SP_mV,
614598 LOAD_GPIO_V2SP );
615- } else if (INA260 ::voltage_mV <
616- static_cast <int_fast16_t >(V3SP_mV * FALL_HYSTERESIS )) {
617- /* Fall to stage 3: !(< 10*0.05 V) & !(> 10 V & < 15 V) &
618- !(< 15*0.05 V) & !(> 15 V & <= 18 V) & (< 18*0.05 V) */
619- load.setLoadGPIO (LOAD_GPIO_V2SP );
620- ESP_LOGI (TAG , " Voltage below %d mV, setting load to %d" , V3SP_mV,
621- LOAD_GPIO_V2SP );
622599 } else if (INA260 ::voltage_mV > V3SP_mV) {
623600 /* Increase to stage 4: !(< 10*0.05 V) & !(> 10 V & < 15 V) &
624601 !(< 15*0.05 V) & !(> 15 V) & !(< 18*0.05 V) & (> 18 V) */
625602 load.setLoadGPIO (LOAD_GPIO_V3SP );
626603 ESP_LOGI (TAG , " Voltage above %d mV, setting load to %d" , V3SP_mV,
627604 LOAD_GPIO_V3SP );
628605 }
606+ #endif
629607
630608 delay (RUN ::TASK_INTERVALS ::TI_ADJUST_LOAD_mS);
631609 }
0 commit comments