Working version
This commit is contained in:
@ -7,8 +7,7 @@
|
||||
|
||||
#include "AIR_State_Maschine.h"
|
||||
|
||||
ADC_HandleTypeDef* air_current_adc = {0};
|
||||
ADC_HandleTypeDef* sdc_voltage_adc = {0};
|
||||
#include "stm32g4xx_hal.h"
|
||||
|
||||
DMA_HandleTypeDef* air_current_dma = {0};
|
||||
DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
||||
@ -16,25 +15,11 @@ DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
||||
uint8_t air_adc_complete = 0;
|
||||
uint8_t sdc_adc_complete = 0;
|
||||
|
||||
AIRStateHandler init_AIR_State_Maschine(ADC_HandleTypeDef* relay_adc,
|
||||
ADC_HandleTypeDef* sc_adc,
|
||||
DMA_HandleTypeDef* relay_dma,
|
||||
DMA_HandleTypeDef* sc_dma) {
|
||||
air_current_adc = relay_adc;
|
||||
sdc_voltage_adc = sc_adc;
|
||||
|
||||
air_current_dma = relay_dma;
|
||||
sdc_voltage_dma = sc_dma;
|
||||
|
||||
AIRStateHandler init_AIR_State_Maschine() {
|
||||
AIRStateHandler airstate = {0};
|
||||
|
||||
airstate.targetTSState = TS_INACTIVE;
|
||||
airstate.currentTSState = TS_INACTIVE;
|
||||
airstate.ShutdownCircuitVoltage = 0;
|
||||
airstate.RelaisSupplyVoltage = 0;
|
||||
airstate.AIRNegativeCurrent = 0;
|
||||
airstate.AIRPositiveCurrent = 0;
|
||||
airstate.AIRPrechargeCurrent = 0;
|
||||
airstate.BatteryVoltageBatterySide = 0;
|
||||
airstate.BatteryVoltageVehicleSide = 0;
|
||||
|
||||
@ -65,16 +50,6 @@ void Update_AIR_Info(AIRStateHandler* airstate) {
|
||||
status = HAL_ADC_PollForConversion(air_current_adc, 10);
|
||||
uint32_t adcval5 = HAL_ADC_GetValue(air_current_adc);
|
||||
HAL_ADC_Stop(air_current_adc);*/
|
||||
|
||||
uint32_t startmils = HAL_GetTick() + ADC_READ_TIMEOUT;
|
||||
|
||||
{
|
||||
airstate->RelaisSupplyVoltage = 3000;
|
||||
airstate->AIRPositiveCurrent = 0;
|
||||
airstate->AIRNegativeCurrent = 0;
|
||||
airstate->AIRPrechargeCurrent = 0;
|
||||
airstate->ShutdownCircuitVoltage = 3000;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Update_AIR_State(AIRStateHandler* airstate) {
|
||||
@ -91,25 +66,7 @@ uint8_t Update_AIR_State(AIRStateHandler* airstate) {
|
||||
|
||||
if (airstate->currentTSState == TS_ERROR) // No Escape from TS Error State
|
||||
{
|
||||
return TS_ERROR;
|
||||
}
|
||||
|
||||
else if ((airstate->currentTSState == TS_INACTIVE) &&
|
||||
(airstate->targetTSState ==
|
||||
TS_ACTIVE)) // Transition from Inactive to Active via Precharge
|
||||
{
|
||||
if ((airstate->RelaisSupplyVoltage) > SDC_LOWER_THRESHOLD) {
|
||||
airstate->currentTSState = TS_PRECHARGE;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Is it correct that we also go from precharge to discharge?
|
||||
else if ((airstate->currentTSState == TS_ACTIVE ||
|
||||
airstate->currentTSState == TS_PRECHARGE) &&
|
||||
(airstate->targetTSState ==
|
||||
TS_INACTIVE)) // Transition from Active to Inactive via Discharge
|
||||
{
|
||||
airstate->currentTSState = TS_DISCHARGE;
|
||||
// Don't change anything, but prevent any other if from being entered
|
||||
}
|
||||
|
||||
else if (airstate->targetTSState ==
|
||||
@ -118,6 +75,41 @@ uint8_t Update_AIR_State(AIRStateHandler* airstate) {
|
||||
airstate->currentTSState = TS_ERROR;
|
||||
}
|
||||
|
||||
else if ((airstate->currentTSState == TS_INACTIVE) &&
|
||||
(airstate->targetTSState ==
|
||||
TS_ACTIVE)) // Transition from Inactive to Active via Precharge
|
||||
{
|
||||
airstate->currentTSState = TS_PRECHARGE;
|
||||
airstate->precharge95ReachedTimestamp = 0;
|
||||
}
|
||||
|
||||
else if ((airstate->currentTSState == TS_INACTIVE) &&
|
||||
(airstate->targetTSState == TS_CHARGING)) {
|
||||
airstate->currentTSState = TS_CHARGING_CHECK;
|
||||
airstate->chargingCheckTimestamp = HAL_GetTick();
|
||||
}
|
||||
|
||||
// TODO: Is it correct that we also go from precharge to discharge?
|
||||
else if ((airstate->currentTSState == TS_ACTIVE ||
|
||||
airstate->currentTSState == TS_PRECHARGE ||
|
||||
airstate->currentTSState == TS_CHARGING_CHECK ||
|
||||
airstate->currentTSState == TS_CHARGING) &&
|
||||
(airstate->targetTSState ==
|
||||
TS_INACTIVE)) // Transition from Active to Inactive via Discharge
|
||||
{
|
||||
airstate->currentTSState = TS_DISCHARGE;
|
||||
}
|
||||
|
||||
else if ((airstate->targetTSState == TS_CHARGING) &&
|
||||
(airstate->currentTSState == TS_CHARGING_CHECK)) {
|
||||
if (airstate->BatteryVoltageVehicleSide >
|
||||
airstate->BatteryVoltageBatterySide) {
|
||||
airstate->currentTSState = TS_CHARGING;
|
||||
} else if (HAL_GetTick() > airstate->chargingCheckTimestamp + 2000) {
|
||||
airstate->currentTSState = TS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
else if (airstate->currentTSState ==
|
||||
TS_PRECHARGE) // Change from Precharge to Active at 95% TS Voltage at
|
||||
// Vehicle Side
|
||||
@ -125,15 +117,20 @@ uint8_t Update_AIR_State(AIRStateHandler* airstate) {
|
||||
if ((airstate->BatteryVoltageVehicleSide >
|
||||
LOWER_VEHICLE_SIDE_VOLTAGE_LIMIT)) {
|
||||
if (airstate->BatteryVoltageVehicleSide >
|
||||
(airstate->BatteryVoltageBatterySide * 0.90)) {
|
||||
airstate->currentTSState = TS_ACTIVE;
|
||||
(airstate->BatteryVoltageBatterySide * 0.95)) {
|
||||
if (airstate->precharge95ReachedTimestamp == 0) {
|
||||
airstate->precharge95ReachedTimestamp = HAL_GetTick();
|
||||
} else if (HAL_GetTick() - airstate->precharge95ReachedTimestamp >=
|
||||
PRECHARGE_95_DURATION) {
|
||||
airstate->currentTSState = TS_ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (airstate->currentTSState ==
|
||||
TS_DISCHARGE) // Change from Discharge to Inactive at 95% TS Voltage
|
||||
// at Vehicle Side
|
||||
TS_DISCHARGE) // Change from Discharge to Inactive at 95% TS
|
||||
// Voltage at Vehicle Side
|
||||
{
|
||||
airstate->currentTSState = TS_INACTIVE;
|
||||
}
|
||||
@ -149,6 +146,14 @@ uint8_t Update_AIR_State(AIRStateHandler* airstate) {
|
||||
AIR_Discharge_Position();
|
||||
}
|
||||
|
||||
if (airstate->currentTSState == TS_CHARGING_CHECK) {
|
||||
AIR_Precharge_Position();
|
||||
}
|
||||
|
||||
if (airstate->currentTSState == TS_CHARGING) {
|
||||
AIR_Active_Position();
|
||||
}
|
||||
|
||||
if (airstate->currentTSState == TS_ACTIVE) {
|
||||
AIR_Active_Position();
|
||||
}
|
||||
@ -218,14 +223,3 @@ void AIR_Error_Position() {
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||
if (hadc == air_current_adc) {
|
||||
air_adc_complete = 1;
|
||||
HAL_ADC_Stop_DMA(air_current_adc);
|
||||
}
|
||||
if (hadc == sdc_voltage_adc) {
|
||||
sdc_adc_complete = 1;
|
||||
HAL_ADC_Stop_DMA(sdc_voltage_adc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user