empty branch for mvbms
This commit is contained in:
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* ADBMS_Abstraction.h
|
||||
*
|
||||
* Created on: 14.07.2022
|
||||
* Author: max
|
||||
*/
|
||||
|
||||
#ifndef INC_ADBMS_ABSTRACTION_H_
|
||||
#define INC_ADBMS_ABSTRACTION_H_
|
||||
|
||||
#include "ADBMS_CMD_MAKROS.h"
|
||||
#include "ADBMS_LL_Driver.h"
|
||||
#include "main.h"
|
||||
|
||||
|
||||
#define MAXIMUM_CELL_VOLTAGES 16
|
||||
#define MAXIMUM_AUX_VOLTAGES 10
|
||||
#define MAXIMUM_GPIO 10
|
||||
|
||||
//see table 103 in datasheet (page 71)
|
||||
#define DEFAULT_UV 417 //VUV * 16 * 150 uV + 1.5 V Default Setting 2.5V
|
||||
#define DEFAULT_OV 1125 //VOV * 16 * 150 uV + 1.5 V Default Setting 4.2V
|
||||
|
||||
#define mV_from_ADBMS6830(x) (((((int16_t) (x))) * 0.150) + 1500)
|
||||
|
||||
struct ADBMS6830_Internal_Status {
|
||||
uint16 CS_FLT : 16; //ADC fault - mismatch between S- and C-ADC
|
||||
uint16 : 3;
|
||||
uint16 CCTS : 13; //Conversion counter
|
||||
uint16 VA_OV : 1; //5V analog supply overvoltage
|
||||
uint16 VA_UV : 1; //5V analog supply undervoltage
|
||||
uint16 VD_OV : 1; //3V digital supply overvoltage
|
||||
uint16 VD_UV : 1; //3V digital supply undervoltage
|
||||
uint16 CED : 1; //C-ADC single trim error (correctable)
|
||||
uint16 CMED : 1; //C-ADC multiple trim error (uncorrectable)
|
||||
uint16 SED : 1; //S-ADC single trim error (correctable)
|
||||
uint16 SMED : 1; //S-ADC multiple trim error (uncorrectable)
|
||||
uint16 VDEL : 1; //Latent supply voltage error
|
||||
uint16 VDE : 1; //Supply voltage error
|
||||
uint16 COMPARE : 1; //Comparasion between S- and C-ADC active
|
||||
uint16 SPIFLT : 1; //SPI fault
|
||||
uint16 SLEEP : 1; //Sleep mode previously entered
|
||||
uint16 THSD : 1; //Thermal shutdown
|
||||
uint16 TMODCHK : 1; //Test mode check
|
||||
uint16 OSCCHK : 1; //Oscillator check
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int16_t cellVoltages[MAXIMUM_CELL_VOLTAGES];
|
||||
int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES];
|
||||
|
||||
struct ADBMS6830_Internal_Status status;
|
||||
uint16 internalDieTemp;
|
||||
uint16 analogSupplyVoltage;
|
||||
uint16 digitalSupplyVoltage;
|
||||
uint16 sumOfCellMeasurements;
|
||||
uint16 refVoltage;
|
||||
|
||||
uint16 GPIO_Values[MAXIMUM_GPIO];
|
||||
|
||||
uint32 overVoltage;
|
||||
uint32 underVoltage;
|
||||
|
||||
} Cell_Module;
|
||||
|
||||
uint8 amsReset();
|
||||
|
||||
uint8 initAMS(SPI_HandleTypeDef* hspi, uint8 numofcells, uint8 numofaux);
|
||||
uint8 amsWakeUp();
|
||||
|
||||
uint8 amsCellMeasurement(Cell_Module* module);
|
||||
uint8 amsConfigCellMeasurement(uint8 numberofChannels);
|
||||
|
||||
uint8 amsAuxAndStatusMeasurement(Cell_Module* module);
|
||||
uint8 amsConfigAuxMeasurement(uint16 Channels);
|
||||
|
||||
uint8 amsConfigGPIO(uint16 gpios);
|
||||
uint8 amsSetGPIO(uint16 gpios);
|
||||
uint8 readGPIO(Cell_Module* module);
|
||||
|
||||
uint8 amsConfigBalancing(uint32 Channels, uint8 dutyCycle);
|
||||
uint8 amsStartBalancing(uint8 dutyCycle);
|
||||
uint8 amsStopBalancing();
|
||||
|
||||
uint8 amsSelfTest();
|
||||
|
||||
uint8 amsConfigOverUnderVoltage(uint16 overVoltage, uint16 underVoltage);
|
||||
|
||||
uint8 amsCheckUnderOverVoltage(Cell_Module* module);
|
||||
uint8 amsConfigOverVoltage(uint16 overVoltage);
|
||||
|
||||
uint8 amscheckOpenCellWire(Cell_Module* module);
|
||||
|
||||
uint8 amsClearStatus();
|
||||
uint8 amsClearAux();
|
||||
uint8 amsClearCells();
|
||||
|
||||
uint8 amsSendWarning();
|
||||
uint8 amsSendError();
|
||||
|
||||
uint8 amsClearWarning();
|
||||
uint8 amsClearError();
|
||||
|
||||
uint8 amsReadCellVoltages(Cell_Module* module);
|
||||
|
||||
#endif /* INC_ADBMS_ABSTRACTION_H_ */
|
||||
@ -1,171 +0,0 @@
|
||||
/*
|
||||
* ADBMS_CMD_MAKROS.h
|
||||
*
|
||||
* Created on: 14.07.2022
|
||||
* Author: max
|
||||
*/
|
||||
|
||||
#ifndef INC_ADBMS_CMD_MAKROS_H_
|
||||
#define INC_ADBMS_CMD_MAKROS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#define WRCFGA 0x0001 // Write Configuration Register Group A
|
||||
#define RDCFGA 0x0002 // Read Configuration Register Group A
|
||||
#define WRCFGB 0x0024 // Write Configuration Register Group B
|
||||
#define RDCFGB 0x0026 // Read Configuration Register Group B
|
||||
|
||||
#define WRPWMA 0x0020 // Write PWM Register Group A
|
||||
#define RDPWMA 0x0022 // Read PWM Register Group A
|
||||
#define WRPWMB 0x0021 // Write PWM Register Group B
|
||||
#define RDPWMB 0x0023 // Read PWM Register Group B
|
||||
|
||||
#define RDCVA 0x0004 // Read Cell Voltage Register Group A
|
||||
#define RDCVB 0x0006 // Read Cell Voltage Register Group B
|
||||
#define RDCVC 0x0008 // Read Cell Voltage Register Group C
|
||||
#define RDCVD 0x000A // Read Cell Voltage Register Group D
|
||||
#define RDCVE 0x0009 // Read Cell Voltage Register Group E
|
||||
#define RDCVF 0x000B // Read Cell Voltage Register Group F
|
||||
#define RDCVALL 0x000C // Read All Cell Voltage Register Groups
|
||||
|
||||
#define RDACA 0x0044 // Read averaged Cell Voltage Register Group A
|
||||
#define RDACB 0x0046 // Read averaged Cell Voltage Register Group B
|
||||
#define RDACC 0x0048 // Read averaged Cell Voltage Register Group C
|
||||
#define RDACD 0x004A // Read averaged Cell Voltage Register Group D
|
||||
#define RDACE 0x0049 // Read averaged Cell Voltage Register Group E
|
||||
#define RDACF 0x004B // Read averaged Cell Voltage Register Group F
|
||||
#define RDACALL 0x004C // Read averaged All Cell Voltage Register Groups
|
||||
|
||||
#define RDAUXA 0x0019 // Read Auxilliary Register Group A
|
||||
#define RDAUXB 0x001A // Read Auxilliary Register Group B
|
||||
#define RDAUXC 0x001B // Read Auxilliary Register Group C
|
||||
#define RDAUXD 0x001F // Read Auxilliary Register Group D
|
||||
|
||||
#define RDAUXALL 0x0035 // Read All Auxilliary and Status Register Groups
|
||||
|
||||
#define RDSTATA 0x0030 // Read Status Register Group A
|
||||
#define RDSTATB 0x0031 // Read Status Register Group B
|
||||
#define RDSTATC 0x0032 // Read Status Register Group C
|
||||
#define RDSTATD 0x0033 // Read Status Register Group D
|
||||
#define RDSTATE 0x0034 // Read Status Register Group E
|
||||
|
||||
#define ADCV 0x0260 // Start Cell Voltage Conversion with C-ADC
|
||||
#define ADCV_OW_0 (1u << 0)
|
||||
#define ADCV_OW_1 (1u << 1)
|
||||
#define ADCV_RSTF (1u << 2)
|
||||
#define ADCV_DCP (1u << 4)
|
||||
#define ADCV_CONT (1u << 7) // Continuous Mode
|
||||
#define ADCV_RD (1u << 8) // Redundancy Mode
|
||||
|
||||
#define ADSV 0x0168 // Start Cell Voltage Conversion with S-ADC
|
||||
#define ADSV_OW_0 (1u << 0)
|
||||
#define ADSV_OW_1 (1u << 1)
|
||||
#define ADSV_DCP (1u << 4)
|
||||
#define ADSV_CONT (1u << 7) // Continuous Mode
|
||||
|
||||
#define ADAX 0x0410 // Start GPIOs and Vref2 Conversion
|
||||
#define ADAX_CONV_ALL 0x0000 // Convert all GPIOs, VREF2, VD, VA, ITEMP
|
||||
#define ADAX_OW (1u << 8)
|
||||
|
||||
#define CLRCELL 0x0711 // Clear Cell Voltage Register Groups
|
||||
#define CLRAUX 0x0712 // Clear Auxiliary Register Groups
|
||||
#define CLOVUV 0x0715 // Clear Overvoltage and Undervoltage Flags
|
||||
#define CLRFLAG 0x0717 // Clear all Flags
|
||||
|
||||
#define PLADC 0x0718 // Poll ADC Conversion Status
|
||||
#define PLAUX 0x071E // Poll AUX Conversion Status
|
||||
|
||||
#define SRST 0x0027 //Soft reset
|
||||
|
||||
#define DIAGN 0x0715 // Diagnos MUX and Poll Status
|
||||
#define WRCOMM 0x0721 // Write COMM Register Group
|
||||
#define RDCOMM 0x0722 // Read COMM Register Group
|
||||
#define STCOMM 0x0723 // Start I2C/SPI Communication
|
||||
#define MUTE 0x0028 // Mute Discharge
|
||||
#define UNMUTE 0x0029 // Unmute Discharge
|
||||
|
||||
|
||||
|
||||
/* GPIO Selection for ADC Converion
|
||||
* 000: GPIO1 to 5, 2nd Reference, GPIO 6 to 9
|
||||
* 001: GPIO1 and GPIO6
|
||||
* 010 GPIO2 and GPIO7
|
||||
* 011 GPIO3 and GPIO8
|
||||
* 100 GPIO4 and GPIO9
|
||||
* 101 GPIO5
|
||||
* 110 2nd Reference
|
||||
*/
|
||||
|
||||
#define CHG000 (0x00)
|
||||
#define CHG001 (0x01)
|
||||
#define CHG010 (0x02)
|
||||
#define CHG011 (0x03)
|
||||
#define CHG100 (0x04)
|
||||
#define CHG101 (0x05)
|
||||
#define CHG110 (0x06)
|
||||
|
||||
/* Status Group Selection
|
||||
* 000: SC,ITMP,VA,VD
|
||||
* 001: SC
|
||||
* 010: ITMP
|
||||
* 011: VA
|
||||
* 100: VD
|
||||
*/
|
||||
|
||||
#define CHST000 (0x00)
|
||||
#define CHST001 (0x01)
|
||||
#define CHST010 (0x02)
|
||||
#define CHST011 (0x03)
|
||||
#define CHST100 (0x04)
|
||||
|
||||
#define PEC_FIELD_SIZE 2
|
||||
|
||||
#define CFG_GROUP_A_SIZE 6
|
||||
#define CFG_GROUP_B_SIZE 6
|
||||
|
||||
#define PWM_GROUP_A_SIZE 6
|
||||
#define PWM_GROUP_B_SIZE 2
|
||||
|
||||
#define CV_GROUP_A_SIZE 6
|
||||
#define CV_GROUP_B_SIZE 6
|
||||
#define CV_GROUP_C_SIZE 6
|
||||
#define CV_GROUP_D_SIZE 6
|
||||
#define CV_GROUP_E_SIZE 6
|
||||
#define CV_GROUP_F_SIZE 6
|
||||
|
||||
#define AUX_GROUP_A_SIZE 6
|
||||
#define AUX_GROUP_B_SIZE 6
|
||||
#define AUX_GROUP_C_SIZE 6
|
||||
#define AUX_GROUP_D_SIZE 6
|
||||
|
||||
#define STATUS_GROUP_A_SIZE 6
|
||||
#define STATUS_GROUP_B_SIZE 6
|
||||
#define STATUS_GROUP_C_SIZE 6
|
||||
#define STATUS_GROUP_D_SIZE 6
|
||||
#define STATUS_GROUP_E_SIZE 6
|
||||
#define COMM_GROUP_SIZE 6
|
||||
#define S_CONTROL_GROUP_SIZE 6
|
||||
#define PWM_GROUP_SIZE 6
|
||||
#define PWM_S_CONTROL_GROUP_B_SIZE 6
|
||||
|
||||
#define CFG_GROUP_A_ID 1
|
||||
#define CFG_GROUP_B_ID 2
|
||||
#define CV_GROUP_A_ID 3
|
||||
#define CV_GROUP_B_ID 4
|
||||
#define CV_GROUP_C_ID 5
|
||||
#define CV_GROUP_D_ID 6
|
||||
#define CV_GROUP_E_ID 7
|
||||
#define CV_GROUP_F_ID 8
|
||||
|
||||
#define AUX_GROUP_A_ID 9
|
||||
#define AUX_GROUP_B_ID 10
|
||||
#define AUX_GROUP_C_ID 11
|
||||
#define AUX_GROUP_D_ID 12
|
||||
|
||||
#define STATUS_GROUP_A_ID 13
|
||||
#define STATUS_GROUP_B_ID 14
|
||||
#define COMM_GROUP_ID 15
|
||||
#define S_CONTROL_GROUP_ID 16
|
||||
#define PWM_GROUP_ID 17
|
||||
#define PWM_S_CONTROL_GROUP_B_ID 18
|
||||
|
||||
#endif /* INC_ADBMS_CMD_MAKROS_H_ */
|
||||
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* ADBMS_LL_Driver.h
|
||||
*
|
||||
* Created on: 05.06.2022
|
||||
* Author: max
|
||||
*/
|
||||
|
||||
#ifndef ADBMS_LL_DRIVER_H_
|
||||
#define ADBMS_LL_DRIVER_H_
|
||||
|
||||
#define TARGET_STM32
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#ifdef TARGET_STM32
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
#endif
|
||||
|
||||
uint8 adbmsDriverInit(SPI_HandleTypeDef* hspi);
|
||||
uint8 calculateCommandPEC(uint8* data, uint8 datalen);
|
||||
uint16 updateCommandPEC(uint16 currentPEC, uint8 din);
|
||||
uint8 checkCommandPEC(uint8* data, uint8 datalen);
|
||||
|
||||
uint8 calculateDataPEC(uint8* data, uint8 datalen);
|
||||
uint16 updateDataPEC(uint16 currentPEC, uint8 din);
|
||||
uint8 checkDataPEC(uint8* data, uint8 datalen);
|
||||
|
||||
uint8 writeCMD(uint16 command, uint8* args, uint8 arglen);
|
||||
uint8 readCMD(uint16 command, uint8* buffer, uint8 buflen);
|
||||
uint8 pollCMD(uint16 command);
|
||||
|
||||
void mcuAdbmsCSLow();
|
||||
void mcuAdbmsCSHigh();
|
||||
|
||||
uint8 mcuSPITransmit(uint8* buffer, uint8 buffersize);
|
||||
uint8 mcuSPIReceive(uint8* buffer, uint8 buffersize);
|
||||
uint8 mcuSPITransmitReceive(uint8* rxbuffer, uint8* txbuffer, uint8 buffersize);
|
||||
|
||||
uint8 wakeUpCmd();
|
||||
void mcuDelay(uint16 delay);
|
||||
|
||||
#endif /* ADBMS_LL_DRIVER_H_ */
|
||||
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* AMS_HighLevel.h
|
||||
*
|
||||
* Created on: 20.07.2022
|
||||
* Author: max
|
||||
*/
|
||||
|
||||
#ifndef INC_AMS_HIGHLEVEL_H_
|
||||
#define INC_AMS_HIGHLEVEL_H_
|
||||
|
||||
#include "ADBMS_Abstraction.h"
|
||||
#include "ADBMS_CMD_MAKROS.h"
|
||||
#include "ADBMS_LL_Driver.h"
|
||||
#include "can.h"
|
||||
#include "TMP1075.h"
|
||||
#include "can-halal.h"
|
||||
#include "errors.h"
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
AMSDEACTIVE,
|
||||
AMSIDLE,
|
||||
AMSCHARGING,
|
||||
AMSIDLEBALANCING,
|
||||
AMSDISCHARGING,
|
||||
AMSWARNING,
|
||||
AMSERROR
|
||||
} amsState;
|
||||
|
||||
extern amsState currentAMSState;
|
||||
extern Cell_Module module;
|
||||
extern uint32_t balancedCells;
|
||||
extern uint8_t BalancingActive;
|
||||
extern uint8_t stateofcharge;
|
||||
|
||||
extern uint8_t amserrorcode;
|
||||
extern uint8_t amswarningcode;
|
||||
|
||||
extern uint8_t numberofCells;
|
||||
extern uint8_t numberofAux;
|
||||
|
||||
void AMS_Init(SPI_HandleTypeDef* hspi);
|
||||
void AMS_Loop();
|
||||
|
||||
uint8_t AMS_Balancing_Loop();
|
||||
uint8_t AMS_Idle_Loop();
|
||||
uint8_t AMS_Warning_Loop();
|
||||
uint8_t AMS_Error_Loop();
|
||||
uint8_t AMS_Charging_Loop();
|
||||
uint8_t AMS_Discharging_Loop();
|
||||
|
||||
uint8_t writeWarningLog(uint8_t warningCode);
|
||||
uint8_t writeErrorLog(uint8_t errorCode);
|
||||
uint8_t integrateCurrent();
|
||||
|
||||
#endif /* INC_AMS_HIGHLEVEL_H_ */
|
||||
@ -1,32 +0,0 @@
|
||||
#ifndef INC_PWM_CONTROL_H
|
||||
#define INC_PWM_CONTROL_H
|
||||
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include "ADBMS_LL_Driver.h"
|
||||
#include "state_machine.h"
|
||||
#include <stdint.h>
|
||||
#include "main.h"
|
||||
|
||||
/* The PWM period (1/FPWM) is defined by the following parameters:
|
||||
ARR value, the Prescaler value, and the internal clock itself which drives the timer module FCLK.
|
||||
F_PWM = (F_CLK)/((ARR + 1) * (PSC + 1))
|
||||
|
||||
F_CLK = 16 MHz
|
||||
|
||||
POWERGROUND ESC Signal: pulse every 20 ms, 1 ms = 0%, 2 ms = 100%
|
||||
FREQ = 50 Hz -> 16 MHz/50 Hz = 320000 = ((39999 + 1) * (7 + 1))
|
||||
DUTY CYCLE = 1/20 -> 0%, DUTY CYCLE = 2/20 -> 100%
|
||||
CCR * DUTY_CYCLE
|
||||
CCR: 1/20 -> 500, 2/20 -> 1000
|
||||
*/
|
||||
#define POWERGROUND_FREQ 50
|
||||
|
||||
//#define BATTERY_COOLING_FREQ 20000
|
||||
|
||||
void PWM_control_init(TIM_HandleTypeDef* powerground, TIM_HandleTypeDef* battery_cooling);
|
||||
|
||||
void PWM_powerground_control(uint8_t percent);
|
||||
void PWM_battery_cooling_control(uint8_t percent);
|
||||
void PWM_set_throttle();
|
||||
|
||||
#endif /* INC_CHANNEL_CONTROL_H */
|
||||
@ -1,20 +0,0 @@
|
||||
#ifndef INC_TMP1075_H_
|
||||
#define INC_TMP1075_H_
|
||||
|
||||
#include "can.h"
|
||||
#include "common_defs.h"
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include "TMP1075.h"
|
||||
#include "can-halal.h"
|
||||
#include "errors.h"
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint32_t tmp1075_failed_sensors;
|
||||
extern int16_t tmp1075_temps[N_TEMP_SENSORS];
|
||||
|
||||
HAL_StatusTypeDef tmp1075_init(I2C_HandleTypeDef* hi2c);
|
||||
HAL_StatusTypeDef tmp1075_measure();
|
||||
HAL_StatusTypeDef tmp1075_sensor_init(int n);
|
||||
HAL_StatusTypeDef tmp1075_sensor_read(int n, int16_t* res);
|
||||
|
||||
#endif // INC_TMP1075_H_
|
||||
@ -1,23 +0,0 @@
|
||||
#ifndef INC_CAN_H
|
||||
#define INC_CAN_H
|
||||
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include "ADBMS_Abstraction.h"
|
||||
#include "main.h"
|
||||
#include "can-halal.h"
|
||||
#include "AMS_HighLevel.h"
|
||||
#include "state_machine.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#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();
|
||||
|
||||
void can_handle_recieve_command(const uint8_t *data);
|
||||
|
||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data);
|
||||
|
||||
#endif /* "INC_CAN_H" */
|
||||
@ -1,14 +0,0 @@
|
||||
/*
|
||||
* common_defs.h
|
||||
*
|
||||
* Created on: 23 Mar 2022
|
||||
* Author: Jasper
|
||||
*/
|
||||
|
||||
#ifndef INC_COMMON_DEFS_H_
|
||||
#define INC_COMMON_DEFS_H_
|
||||
|
||||
#define N_CELLS 12
|
||||
#define N_TEMP_SENSORS 12
|
||||
|
||||
#endif /* INC_COMMON_DEFS_H_ */
|
||||
@ -1,41 +0,0 @@
|
||||
#ifndef INC_ERRORS_H
|
||||
#define INC_ERRORS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ERROR_SOURCE_VOLTAGES (1 << 0)
|
||||
#define ERROR_SOURCE_TEMPERATURES (1 << 1)
|
||||
#define ERROR_SOURCE_TOO_FEW_WORKING_TEMP_SENSORS (1 << 2)
|
||||
#define ERROR_SOURCE_OPEN_CELL_CONNECTION (1 << 3)
|
||||
#define ERROR_SOURCE_EEPROM (1 << 4)
|
||||
#define ERROR_SOURCE_INTERNAL (1 << 5)
|
||||
|
||||
#define ERROR_TIME_THRESH 150 // ms
|
||||
|
||||
typedef enum {
|
||||
SEK_OVERTEMP = 0x0,
|
||||
SEK_UNDERTEMP = 0x1,
|
||||
SEK_OVERVOLT = 0x2,
|
||||
SEK_UNDERVOLT = 0x3,
|
||||
SEK_TOO_FEW_TEMPS = 0x4,
|
||||
SEK_OPENWIRE = 0x5,
|
||||
SEK_EEPROM_ERR = 0x6,
|
||||
SEK_INTERNAL_BMS_TIMEOUT = 0x7,
|
||||
SEK_INTERNAL_BMS_CHECKSUM_FAIL = 0x8,
|
||||
SEK_INTERNAL_BMS_OVERTEMP = 0x9,
|
||||
SEK_INTERNAL_BMS_FAULT = 0xA,
|
||||
} SlaveErrorKind;
|
||||
|
||||
typedef struct {
|
||||
int error_sources;
|
||||
SlaveErrorKind data_kind;
|
||||
uint8_t data[4];
|
||||
uint32_t errors_since;
|
||||
} SlaveErrorData;
|
||||
|
||||
extern SlaveErrorData error_data;
|
||||
|
||||
void set_error_source(int source);
|
||||
void clear_error_source(int source);
|
||||
|
||||
#endif // INC_ERRORS_H
|
||||
@ -77,8 +77,10 @@ void Error_Handler(void);
|
||||
#define STATUS_LED_G_GPIO_Port GPIOB
|
||||
#define PRECHARGE_EN_Pin GPIO_PIN_11
|
||||
#define PRECHARGE_EN_GPIO_Port GPIOB
|
||||
#define PWM_Battery_Cooling_Pin GPIO_PIN_15
|
||||
#define PWM_Battery_Cooling_GPIO_Port GPIOB
|
||||
#define AUX_IN_Pin GPIO_PIN_13
|
||||
#define AUX_IN_GPIO_Port GPIOB
|
||||
#define AUX_OUT_Pin GPIO_PIN_14
|
||||
#define AUX_OUT_GPIO_Port GPIOB
|
||||
#define RELAY_BATT_SIDE_ON_Pin GPIO_PIN_8
|
||||
#define RELAY_BATT_SIDE_ON_GPIO_Port GPIOA
|
||||
#define RELAY_ESC_SIDE_ON_Pin GPIO_PIN_9
|
||||
|
||||
@ -1,96 +0,0 @@
|
||||
#ifndef INC_STATE_MACHINE_H
|
||||
#define INC_STATE_MACHINE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "ADBMS_LL_Driver.h"
|
||||
#include "AMS_HighLevel.h"
|
||||
#include "errors.h"
|
||||
#include "PWM_control.h"
|
||||
#include "TMP1075.h"
|
||||
#include <math.h>
|
||||
|
||||
// Minimum vehicle side voltage to exit precharge
|
||||
#define MIN_VEHICLE_SIDE_VOLTAGE 150000 // mV
|
||||
// Time to wait after reaching 95% of battery voltage before exiting precharge
|
||||
// Set this to 1000 in scruti to demonstrate the voltage on the multimeter
|
||||
#define PRECHARGE_95_DURATION 0 // ms
|
||||
// Time to wait for discharge
|
||||
#define DISCHARGE_DURATION 5000 // ms
|
||||
// Time to wait after there is no more error condition before exiting TS_ERROR
|
||||
#define NO_ERROR_TIME 1000 // ms
|
||||
// Time to wait for charger voltage before going to TS_ERROR
|
||||
#define MAX_CHARGING_CHECK_DURATION 2000 // ms
|
||||
// Time to wait between closing relays
|
||||
#define RELAY_CLOSE_WAIT 10 // ms
|
||||
|
||||
#warning
|
||||
typedef enum { // states -> 3 bit. valid transitions: (all could transition to error)
|
||||
STATE_INACTIVE, // INACTIVE -> PRECHARGE, CHARGING, ERROR
|
||||
STATE_PRECHARGE, // PRECHARGE -> INACTIVE, READY, DISCHARGE, ERROR
|
||||
STATE_READY, // READY -> ACTIVE, DISCHARGE, ERROR
|
||||
STATE_ACTIVE, // ACTIVE -> READY, DISCHARGE, ERROR
|
||||
STATE_DISCHARGE, // DISCHARGE -> INACTIVE, PRECHARGE, ERROR
|
||||
STATE_CHARGING_PRECHARGE,
|
||||
STATE_CHARGING, // CHARGING -> INACTIVE, DISCHARGE, ERROR
|
||||
STATE_ERROR, // ERROR -> INACTIVE, DISCHARGE, ERROR
|
||||
} State;
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint16_t bms_timeout : 1;
|
||||
uint16_t bms_fault : 1;
|
||||
uint16_t temperature_error : 1;
|
||||
uint16_t current_error : 1;
|
||||
uint16_t current_sensor_missing : 1;
|
||||
uint16_t voltage_error : 1;
|
||||
uint16_t voltage_missing : 1;
|
||||
uint16_t state_transition_fail : 1;
|
||||
|
||||
} ErrorKind;
|
||||
|
||||
//typedef enum {} WarningKind;
|
||||
|
||||
typedef struct {
|
||||
State current_state;
|
||||
State target_state;
|
||||
uint16_t error_source; // TSErrorSource (bitmask)
|
||||
ErrorKind error_type; // TSErrorKind
|
||||
} StateHandle;
|
||||
|
||||
extern StateHandle state;
|
||||
static bool relay_closed = 0;
|
||||
static bool precharge_closed = 0;
|
||||
extern int16_t RELAY_BAT_SIDE_VOLTAGE;
|
||||
extern int16_t RELAY_ESC_SIDE_VOLTAGE;
|
||||
extern int16_t CURRENT_MEASUREMENT;
|
||||
extern uint8_t powerground_status;
|
||||
|
||||
|
||||
void sm_init();
|
||||
void sm_update();
|
||||
|
||||
State sm_update_inactive();
|
||||
State sm_update_precharge();
|
||||
State sm_update_ready();
|
||||
State sm_update_active();
|
||||
State sm_update_discharge();
|
||||
State sm_update_charging_precharge();
|
||||
State sm_update_charging();
|
||||
State sm_update_error();
|
||||
|
||||
typedef enum { RELAY_MAIN, RELAY_PRECHARGE } Relay;
|
||||
void sm_set_relay_positions(State state);
|
||||
void sm_set_relay(Relay relay, bool closed);
|
||||
void sm_check_charging();
|
||||
void sm_check_battery_temperature(int8_t* id, int16_t* temp);
|
||||
|
||||
int16_t sm_return_cell_temperature(int id);
|
||||
int16_t sm_return_cell_voltage(int id);
|
||||
|
||||
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" */
|
||||
@ -81,7 +81,7 @@
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE ((uint32_t)16000000) /*!< Value of the External oscillator in Hz */
|
||||
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
/**
|
||||
|
||||
@ -55,8 +55,6 @@ void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void USB_LP_CAN_RX0_IRQHandler(void);
|
||||
void CAN_RX1_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
Reference in New Issue
Block a user