Explorar el Código

PWM Logic updated

namrota ghosh hace 7 meses
padre
commit
b5a953ea63
Se han modificado 2 ficheros con 17 adiciones y 17 borrados
  1. 16 16
      src/controller/controller.c
  2. 1 1
      src/controller/controller.h

+ 16 - 16
src/controller/controller.c

@@ -90,21 +90,21 @@ void controller_ClearError(uint8_t const TARGET_ADDRESS, uint8_t slot_id){
 
 //Logic to handle Power Burning PWM on the controller side: is there any clamping required between a certain range?
 void controller_EvaluateBatterySlotState(uint8_t slot_id, BatteryMeasurement *measurement){
-    if(measurement->slot_state== SLOT_ERR_HOV){
-        battery_data[slot_id].pwm_value+= PWM_INCREMENT_VALUE;
-        DL_TimerG_setCaptureCompareValue(PWM_0_INST, battery_data[slot_id].pwm_value, DL_TIMER_CC_0_INDEX);    
-        DL_TimerG_startCounter(PWM_0_INST);
-        printf("[Power Burning PWM] HOV state: Increased power burn PWM to %d\n", battery_data[slot_id].pwm_value);
-    }else if(measurement->slot_state == SLOT_STATE_SOV){
-        battery_data[slot_id].pwm_value+= PWM_INCREMENT_VALUE;
-        DL_TimerG_setCaptureCompareValue(PWM_0_INST, battery_data[slot_id].pwm_value, DL_TIMER_CC_0_INDEX);    
-        DL_TimerG_startCounter(PWM_0_INST);  
-        printf("[Power Burning PWM] SOV state: Increased power burn PWM to %d\n", battery_data[slot_id].pwm_value);  
-    }
-    else{
-        battery_data[slot_id].pwm_value-= PWM_DECREMENT_VALUE;
-        DL_TimerG_setCaptureCompareValue(PWM_0_INST, battery_data[slot_id].pwm_value, DL_TIMER_CC_0_INDEX);    
-        DL_TimerG_startCounter(PWM_0_INST); 
-        printf("[Power Burning PWM] OK state: Decreased power burn PWM to %d\n", battery_data[slot_id].pwm_value);
+    if((measurement->slot_state== SLOT_ERR_HOV) || (measurement->slot_state == SLOT_STATE_SOV)){
+        if(battery_data[slot_id].pwm_value < (PWM_MAX_VALUE - PWM_INCREMENT_VALUE)){
+            battery_data[slot_id].pwm_value+= PWM_INCREMENT_VALUE; 
+            printf("[Power Burning PWM] SOV/HOV state: Increased power burn PWM to %d\n", battery_data[slot_id].pwm_value);
+            DL_TimerG_setCaptureCompareValue(PWM_0_INST, battery_data[slot_id].pwm_value, DL_TIMER_CC_0_INDEX); 
+        }
+         
+    }else if(measurement->slot_state== SLOT_STATE_OK){
+        if(battery_data[slot_id].pwm_value >= (INITIAL_PWM_VALUE + PWM_DECREMENT_VALUE)){
+            battery_data[slot_id].pwm_value-= PWM_DECREMENT_VALUE;
+            printf("[Power Burning PWM] OK state: Decreased power burn PWM to %d\n", battery_data[slot_id].pwm_value);
+            DL_TimerG_setCaptureCompareValue(PWM_0_INST, battery_data[slot_id].pwm_value, DL_TIMER_CC_0_INDEX);
+        }
+    }else{
+        printf("[Power Burning PWM] initial state: %d\n", battery_data[slot_id].pwm_value);
+        DL_TimerG_setCaptureCompareValue(PWM_0_INST, INITIAL_PWM_VALUE, DL_TIMER_CC_0_INDEX); 
     }
 }

+ 1 - 1
src/controller/controller.h

@@ -19,5 +19,5 @@ typedef enum{
 
 void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, int16_t current_mA);
 bool controller_GetBatteryMeasurement(uint8_t const TARGET_ADDRESS, uint8_t slot_id, BatteryMeasurement *measurement);
-
+void controller_EvaluateBatterySlotState(uint8_t slot_id, BatteryMeasurement *measurement);
 #endif