Skip to content

Commit

Permalink
Fix: Competition current threshold modification (#151)
Browse files Browse the repository at this point in the history
Co-authored-by: Ishan Joshi <joshi.ishan23@gmail.com>
  • Loading branch information
mjohal67 and ishanjoshi23 authored Jul 18, 2024
1 parent fb6b699 commit 9a209c4
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions components/bms/bms_master/Core/Inc/analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
#define FLT_SHORT_THRESHOLD 5000U // 0.5000 V
#define FLT_TEMP_RANGE_LOW_THRESHOLD 0.0 // degrees C
#define FLT_TEMP_RANGE_HIGH_THRESHOLD 150.0 // degrees C
#define FLT_OT_THRESHOLD 65.0 // degrees C
#define FLT_OT_DCH_THRESHOLD 65.0 // degrees C
#define FLT_OT_CH_THRESHOLD 45.0

// Trips
#define TRIP_HLIM_THRESHOLD 42000U // 4.2000 V
#define TRIP_LLIM_THRESHOLD 27100U // 2.7100 V
#define TRIP_CHARGE_OT_THRESHOLD 45.0 // degrees C
#define TRIP_CHARGE_OT_THRESHOLD 44.0 // degrees C

// Warnings
#define WARN_HIGH_V_THRESHOLD 41500U // 4.1500 V
Expand Down
3 changes: 3 additions & 0 deletions components/bms/bms_master/Core/Inc/bms_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#define INC_BMS_MAIN_H_

#include "pack.h"
#include "can.h"

extern ECU_Data_t ecu_data;

/*============================================================================*/
/* FUNCTION PROTOTYPES */
Expand Down
1 change: 1 addition & 0 deletions components/bms/bms_master/Core/Inc/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct{

ECU_StatusCode_t status;
ECU_ADC_Data_t adc_data;
bool is_charging; // true means charging

} ECU_Data_t;

Expand Down
7 changes: 6 additions & 1 deletion components/bms/bms_master/Core/Src/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "analysis.h"
#include "bms_main.h"

/*============================================================================*/
/* PRIVATE FUNCTION IMPLEMENTATIONS */
Expand Down Expand Up @@ -61,11 +62,15 @@ void findModuleTempState(Pack_BatteryStatusCode_t *status, float temperature)
// Some conditionals here have no else because faults don't clear

// Faults
if (temperature >= FLT_OT_THRESHOLD)
if (temperature >= FLT_OT_DCH_THRESHOLD)
{
status->bits.fault_over_temperature = true;
}

if (temperature >= FLT_OT_CH_THRESHOLD && ecu_data.is_charging == true){
status->bits.fault_over_temperature = true;
}

if (temperature >= FLT_TEMP_RANGE_HIGH_THRESHOLD || temperature <= FLT_TEMP_RANGE_LOW_THRESHOLD)
{
status->bits.fault_temperature_expected_range = true;
Expand Down
4 changes: 3 additions & 1 deletion components/bms/bms_master/Core/Src/bms_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/*============================================================================*/
/* PRIVATE VARIABLES */
static ECU_Data_t ecu_data = {0};
ECU_Data_t ecu_data = {0};

/*============================================================================*/
/* PRIVATE FUNCTION DEFINITIONS */
Expand Down Expand Up @@ -167,6 +167,8 @@ void BMS_MAIN_updatePackData(Pack_t *pack)
pack->status.bits.fault_over_current = true; // set FLT_DOC_COC bit
}

printf("ecu current direction: %d\r\n", ecu_data.is_charging);

pack->status.bits.warning_no_ecu_message = !new_ecu_can_message_received;

// TODO: isolation sensor check (if it's BMS's responsibilty)
Expand Down
7 changes: 7 additions & 0 deletions components/bms/bms_master/Core/Src/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "main.h"
#include <float.h>
#include <string.h>
#include "analysis.h"

/*============================================================================*/
/* DEFINITIONS */
Expand Down Expand Up @@ -465,6 +466,12 @@ bool CAN_GetMessage0x450Data(uint32_t *rx_timestamp, ECU_Data_t *ecu_data)
ecu_data->status.raw = CAN_data.rx_message_0x450.data[5];
*rx_timestamp = CAN_data.rx_message_0x450.timestamp;

if((float)(ecu_data->adc_data.batt_current) / 65.535 < 0){
ecu_data->is_charging = true;
}
else{
ecu_data->is_charging = false;
}
}

HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); // Start critical section
Expand Down
2 changes: 1 addition & 1 deletion components/ecu/ecu_firmware/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static void MX_ADC1_Init(void)
*/
AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_SINGLE_REG;
AnalogWDGConfig.HighThreshold = 2710;
AnalogWDGConfig.LowThreshold = 2071;
AnalogWDGConfig.LowThreshold = 2105;
AnalogWDGConfig.Channel = ADC_CHANNEL_14;
AnalogWDGConfig.ITMode = ENABLE;
if (HAL_ADC_AnalogWDGConfig(&hadc1, &AnalogWDGConfig) != HAL_OK)
Expand Down
4 changes: 2 additions & 2 deletions components/ecu/ecu_firmware/ecu_firmware.ioc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#MicroXplorer Configuration settings - do not modify
ADC1.AWD1HighThreshold=2710
ADC1.AWD1ITMode=ENABLE
ADC1.AWD1LowThreshold=2071
ADC1.AWD1LowThreshold=2105
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_5
ADC1.Channel-1\#ChannelRegularConversion=ADC_CHANNEL_6
ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_7
Expand Down Expand Up @@ -358,7 +358,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_CAN_Init-CAN-false-HAL-true,6-MX_UART5_Init-UART5-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_IWDG_Init-IWDG-false-HAL-true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_CAN_Init-CAN-false-HAL-true,6-MX_UART5_Init-UART5-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_IWDG_Init-IWDG-false-HAL-true,9-MX_TIM2_Init-TIM2-false-HAL-true
RCC.ADCFreqValue=12000000
RCC.ADCPresc=RCC_ADCPCLK2_DIV6
RCC.AHBFreq_Value=72000000
Expand Down

0 comments on commit 9a209c4

Please sign in to comment.