|
@@ -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?
|
|
//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){
|
|
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);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|