From e48b87a11ecb7fcd854eea17e0757aa44abc3a3e Mon Sep 17 00:00:00 2001 From: hamza Date: Sun, 2 Jun 2024 23:06:07 +0300 Subject: [PATCH] added delay for CAN --- Core/Inc/can.h | 2 +- Core/Src/can.c | 7 +++++++ Core/Src/main.c | 8 +++++--- Core/Src/state_machine.c | 6 +++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Core/Inc/can.h b/Core/Inc/can.h index 8b6651f..82e2b64 100644 --- a/Core/Inc/can.h +++ b/Core/Inc/can.h @@ -9,7 +9,7 @@ #define CAN_ID_IN 0x501 #define CAN_ID_OUT 0x502 - +#define CAN_STATUS_FREQ 1000 void can_init(CAN_HandleTypeDef* hcan); void can_handle_send_status(); diff --git a/Core/Src/can.c b/Core/Src/can.c index 9b71da5..5b46127 100644 --- a/Core/Src/can.c +++ b/Core/Src/can.c @@ -7,9 +7,11 @@ #include "can.h" #include "ADBMS_Abstraction.h" #include "state_machine.h" +#include "stm32f3xx_hal.h" //#define CAN_ID_IN 0x501 //#define CAN_ID_OUT 0x502 +int can_delay_manager = 0; void can_init(CAN_HandleTypeDef* hcan) { ftcan_init(hcan); } /* @@ -33,6 +35,11 @@ bit 51-62: temperature of the cell with highest temperature (12 bits moved 4 bit */ void can_handle_send_status() { + if (can_delay_manager > HAL_GetTick()) + return; + else + can_delay_manager = HAL_GetTick() + CAN_STATUS_FREQ; + uint8_t data[8] = {}; data[0] = (state.current_state << 5); // save 5 bit since codes are from 0-7 61 bits left //data[1] = // in 8 bits from 0-100% diff --git a/Core/Src/main.c b/Core/Src/main.c index 07e81b8..5360001 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -134,6 +134,7 @@ int main(void) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ + /* int ttt = HAL_GetTick() + 45000; PWM_powerground_control(0); while (HAL_GetTick() < ttt){} @@ -143,11 +144,12 @@ int main(void) PWM_powerground_control(15); ttt = HAL_GetTick() + 5000; while (HAL_GetTick() < ttt){} + */ - //AMS_Loop(); - //sm_update(); + AMS_Loop(); + sm_update(); //sm_test_cycle_states(); - //can_handle_send_status(); + can_handle_send_status(); } /* USER CODE END 3 */ } diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index 1558250..9b44794 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -11,9 +11,9 @@ void sm_init(){ } void sm_update(){ - RELAY_BAT_SIDE_VOLTAGE = mV_from_ADBMS6830(module.auxVoltages[0]); - RELAY_ESC_SIDE_VOLTAGE = mV_from_ADBMS6830(module.auxVoltages[1]); - CURRENT_MEASUREMENT = mV_from_ADBMS6830(module.auxVoltages[2]); + RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[0] * 11.989; + RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[1] * 11.989; + CURRENT_MEASUREMENT = module.auxVoltages[2] ; switch (state.current_state) { case STATE_INACTIVE: