Sfoglia il codice sorgente

Logic added for controller handling Power Burning PWM

namrota ghosh 7 mesi fa
parent
commit
f1cebe6063
2 ha cambiato i file con 32 aggiunte e 1 eliminazioni
  1. 31 0
      src/controller/controller.c
  2. 1 1
      src/controller/controller.h

+ 31 - 0
src/controller/controller.c

@@ -56,6 +56,7 @@ void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, int16_
     data[0] = slot_id;
     data[1] = current_mA & 0xFF; //Current LSB
     data[2] = (current_mA >> 8) & 0xFF; //Current MSB
+    //battery_data[slot_id].charge_discharge= current_mA;
     controller_SetCommandRequest(TARGET_ADDRESS, CMD_SET_CURRENT, data, sizeof(data));
 }
 
@@ -77,3 +78,33 @@ bool controller_GetBatteryMeasurement(uint8_t const TARGET_ADDRESS, uint8_t slot
     return false;
 }
 
+//Clear error flag to the target
+//Format: command + ((slot_id) + data (optional))
+void controller_ClearError(uint8_t const TARGET_ADDRESS, uint8_t slot_id){
+    uint8_t command= CMD_CLEAR_ERR| (slot_id<<4); //shift slot_id to the left by 4 bits
+    printf("[MCU] Clear Error Bitmasked Command:: 0x%02X\n", command);
+    uint8_t data[1];
+    data[0] = slot_id;
+    controller_SetCommandRequest(TARGET_ADDRESS, CMD_CLEAR_ERR, data, sizeof(data));
+}
+
+//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);
+    }
+}

+ 1 - 1
src/controller/controller.h

@@ -14,7 +14,7 @@ typedef enum{
     CMD_SET_CURRENT= 0x05,
     CMD_GET_MEASUREMENT= 0x06, 
     //CMD_GET_BATTERY_STATE= 0x07, 
-    CMD_CELAR_ERR= 0x08
+    CMD_CLEAR_ERR= 0x08
 }mcu_I2C_command;
 
 void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, int16_t current_mA);