Compare commits
4 Commits
stm32h7a3-
...
998f9c93e4
| Author | SHA1 | Date | |
|---|---|---|---|
| 998f9c93e4 | |||
| 94a1794764 | |||
| b68d26decb | |||
| a4fd5d26f5 |
@ -42,6 +42,7 @@ extern "C" {
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
extern int sdc_closed;
|
||||
extern int sdc_closed_nodelay;
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
@ -23,7 +23,8 @@ void can_init(FDCAN_HandleTypeDef *handle) {
|
||||
|
||||
HAL_StatusTypeDef can_send_status() {
|
||||
uint8_t data[8];
|
||||
data[0] = ts_state.current_state | (sdc_closed << 7);
|
||||
data[0] =
|
||||
ts_state.current_state | (sdc_closed << 7); // | (sdc_closed_nodelay << 6);
|
||||
data[1] = roundf(current_soc);
|
||||
ftcan_marshal_unsigned(&data[2], min_voltage, 2);
|
||||
ftcan_marshal_signed(&data[4], max_temp, 2);
|
||||
|
||||
@ -60,6 +60,7 @@ UART_HandleTypeDef huart1;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
int sdc_closed = 0;
|
||||
int sdc_closed_nodelay = 0;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@ -88,6 +89,16 @@ static void loop_delay() {
|
||||
}
|
||||
last_loop = HAL_GetTick();
|
||||
}
|
||||
|
||||
static void update_sdc() {
|
||||
static int last[2] = {0, 0};
|
||||
sdc_closed_nodelay = HAL_GPIO_ReadPin(SDC_VOLTAGE_GPIO_Port, SDC_VOLTAGE_Pin) == GPIO_PIN_SET;
|
||||
if (last[0] == last[1] && last[0] == sdc_closed_nodelay) {
|
||||
sdc_closed = sdc_closed_nodelay;
|
||||
}
|
||||
last[0] = last[1];
|
||||
last[1] = sdc_closed_nodelay;
|
||||
}
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@ -138,8 +149,7 @@ int main(void)
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
sdc_closed = HAL_GPIO_ReadPin(SDC_VOLTAGE_GPIO_Port, SDC_VOLTAGE_Pin) ==
|
||||
GPIO_PIN_SET;
|
||||
update_sdc();
|
||||
|
||||
slaves_check();
|
||||
shunt_check();
|
||||
|
||||
@ -53,7 +53,7 @@ void soc_update() {
|
||||
// Otherwise, use the current counter to update SoC
|
||||
float as_delta = shunt_data.current_counter - mAs_before_current;
|
||||
float soc_delta = as_delta / SOC_ESTIMATION_BATTERY_CAPACITY * 100;
|
||||
current_soc = soc_before_current + soc_delta;
|
||||
current_soc = soc_before_current - soc_delta;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user