From cb4b5cb53efb98b5832e7082ce921be7d91de654 Mon Sep 17 00:00:00 2001 From: Hamza Date: Tue, 28 May 2024 19:43:24 +0200 Subject: [PATCH] added sm_test_cycle_states(); --- Core/Inc/state_machine.h | 5 +++++ Core/Src/state_machine.c | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Core/Inc/state_machine.h b/Core/Inc/state_machine.h index 9442090..6e85d96 100644 --- a/Core/Inc/state_machine.h +++ b/Core/Inc/state_machine.h @@ -5,6 +5,9 @@ #include #include "ADBMS_LL_Driver.h" #include "AMS_HighLevel.h" +#include "PWM_control.h" +#include "TMP1075.h" +#include // Minimum vehicle side voltage to exit precharge #define MIN_VEHICLE_SIDE_VOLTAGE 150000 // mV @@ -87,4 +90,6 @@ void sm_handle_ams_in(const uint8 *data); void sm_check_errors(); void sm_set_error(ErrorKind error_kind, bool is_errored); +void sm_test_cycle_states(); + #endif /* "INC_STATE_MACHINE_H" */ \ No newline at end of file diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index 8f232df..5360fb5 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -1,11 +1,8 @@ #include "state_machine.h" -#include "ADBMS_LL_Driver.h" -#include "TMP1075.h" -#include "common_defs.h" -#include +#include "stm32f3xx_hal.h" StateHandle state; -static int16_t timestamp; +static uint32_t timestamp; void sm_init(){ state.current_state = STATE_INACTIVE; @@ -16,7 +13,7 @@ void sm_init(){ void sm_update(){ RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[0]; RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[1]; - CURRENT_MEASUREMENT_VOLTAGE = module.auxVoltages[2]; + CURRENT_MEASUREMENT = module.auxVoltages[2]; switch (state.current_state) { case STATE_INACTIVE: @@ -232,3 +229,30 @@ void sm_check_errors(){ state.error_source = (1 << 10); } } + +void sm_test_cycle_states(){ + if (timestamp > HAL_GetTick()) + return; + switch (state.current_state) { + case STATE_INACTIVE: + state.current_state = STATE_PRECHARGE; + timestamp = HAL_GetTick() + 10000; + return; + case STATE_PRECHARGE: + state.current_state = STATE_READY; + timestamp = HAL_GetTick() + 10000; + return; + case STATE_READY: + state.current_state = STATE_ACTIVE; + timestamp = HAL_GetTick() + 10000; + return; + case STATE_ACTIVE: + state.current_state = STATE_DISCHARGE; + timestamp = HAL_GetTick() + 10000; + return; + case STATE_DISCHARGE: + state.current_state = STATE_INACTIVE; + timestamp = HAL_GetTick() + 10000; + return; + } +} \ No newline at end of file