Compare commits
4 Commits
77f600ddb3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a6a512d2e3 | |||
| 6dab1a5eb7 | |||
| 72c26fb758 | |||
| e3080b1f6e |
@ -25,6 +25,7 @@
|
||||
#define ADC_READ_TIMEOUT 500 // in ms
|
||||
#define SDC_LOWER_THRESHOLD 2500 // in ADC Values
|
||||
#define PRECHARGE_95_DURATION 1000 // in ms
|
||||
#define PRECHARGE_OPEN_AFTER 1000 // in ms
|
||||
// FIXME
|
||||
#define LOWER_VEHICLE_SIDE_VOLTAGE_LIMIT 150000 // in mV
|
||||
|
||||
@ -32,6 +33,7 @@ typedef struct {
|
||||
|
||||
int32_t BatteryVoltageVehicleSide;
|
||||
int32_t BatteryVoltageBatterySide;
|
||||
int32_t shuntCurrent;
|
||||
uint8_t targetTSState;
|
||||
uint8_t currentTSState;
|
||||
uint32_t precharge95ReachedTimestamp;
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define SLAVE_EMERGENCY_ADDRESS 0x001 // Emergency Frame
|
||||
#define CLOCK_SYNC_ADDRESS 0x002
|
||||
#define MASTER_HEARTBEAT_ADDRESS 0x010
|
||||
#define SLAVE_EEPROM_WRITE_ADDRESS 0x020
|
||||
|
||||
typedef struct {
|
||||
int16_t FrameID;
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
#include "stm32g441xx.h"
|
||||
|
||||
#define NUMBEROFSLAVES 7
|
||||
#define NUMBEROFSLAVES 9
|
||||
#define NUMBEROFCELLS 10
|
||||
#define NUMBEROFTEMPS 32
|
||||
|
||||
|
||||
@ -18,6 +18,10 @@ DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
||||
uint8_t air_adc_complete = 0;
|
||||
uint8_t sdc_adc_complete = 0;
|
||||
|
||||
static uint32_t pos_air_change_timestamp, neg_air_change_timestamp,
|
||||
precharge_change_timestamp;
|
||||
static GPIO_PinState neg_air_state, pos_air_state, precharge_state;
|
||||
|
||||
AIRStateHandler init_AIR_State_Maschine() {
|
||||
AIRStateHandler airstate = {0};
|
||||
|
||||
@ -113,6 +117,12 @@ uint8_t Update_AIR_State(AIRStateHandler* airstate) {
|
||||
}
|
||||
}
|
||||
|
||||
else if (airstate->currentTSState == TS_CHARGING) {
|
||||
if (airstate->shuntCurrent < 0) {
|
||||
airstate->currentTSState = TS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
else if (airstate->currentTSState ==
|
||||
TS_PRECHARGE) // Change from Precharge to Active at 95% TS Voltage at
|
||||
// Vehicle Side
|
||||
@ -198,10 +208,13 @@ void AIR_Discharge_Position() {
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void AIR_Active_Position() // TODO Deactivate Precharge after a while to
|
||||
// decrease current Consumption
|
||||
{
|
||||
void AIR_Active_Position() {
|
||||
if (pos_air_state == GPIO_PIN_SET &&
|
||||
HAL_GetTick() - pos_air_change_timestamp > PRECHARGE_OPEN_AFTER) {
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||
} else {
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||
}
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_SET);
|
||||
}
|
||||
@ -213,35 +226,41 @@ void AIR_Error_Position() {
|
||||
}
|
||||
|
||||
void Set_Relay_Position(Relay relay, GPIO_PinState position) {
|
||||
static GPIO_PinState neg = 0;
|
||||
static GPIO_PinState pos = 0;
|
||||
static GPIO_PinState precharge = 0;
|
||||
// Add a small delay after closing relays in order to not draw too much
|
||||
// current
|
||||
switch (relay) {
|
||||
case RELAY_AIR_NEG:
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
position);
|
||||
if (position == GPIO_PIN_SET && neg == GPIO_PIN_RESET) {
|
||||
if (position != neg_air_state) {
|
||||
neg_air_change_timestamp = HAL_GetTick();
|
||||
}
|
||||
if (position == GPIO_PIN_SET && neg_air_state == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
neg = position;
|
||||
neg_air_state = position;
|
||||
break;
|
||||
case RELAY_AIR_POS:
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
position);
|
||||
if (position == GPIO_PIN_SET && pos == GPIO_PIN_RESET) {
|
||||
if (position != pos_air_state) {
|
||||
pos_air_change_timestamp = HAL_GetTick();
|
||||
}
|
||||
if (position == GPIO_PIN_SET && pos_air_state == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
pos = position;
|
||||
pos_air_state = position;
|
||||
break;
|
||||
case RELAY_PRECHARGE:
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
position);
|
||||
if (position == GPIO_PIN_SET && precharge == GPIO_PIN_RESET) {
|
||||
if (position != precharge_state) {
|
||||
precharge_change_timestamp = HAL_GetTick();
|
||||
}
|
||||
if (position == GPIO_PIN_SET && precharge_state == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
precharge = position;
|
||||
precharge_state = position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,11 +14,8 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// 3 should be programmed with CAN id 2
|
||||
// const uint16_t slave_CAN_id_to_slave_index[7] = {
|
||||
// 255, 255, 0, 255, 255, 255, 1}; // TODO: Make this pretty pls
|
||||
const uint16_t slave_CAN_id_to_slave_index[7] = {
|
||||
0, 1, 2, 3, 4, 5, 6}; // TODO: Make this pretty pls
|
||||
const uint16_t slave_CAN_id_to_slave_index[10] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 255, 8}; // TODO: Make this pretty pls
|
||||
canFrame framebuffer[CANFRAMEBUFFERSIZE] = {0};
|
||||
uint32_t framebufferwritepointer = 0;
|
||||
uint32_t framebufferreadpointer = 0;
|
||||
|
||||
@ -348,7 +348,7 @@ void InterSTMFrame() {
|
||||
spirxbuf[0] << 24 | spirxbuf[1] << 16 | spirxbuf[2] << 8 | spirxbuf[3];
|
||||
spi_airstates->BatteryVoltageVehicleSide =
|
||||
spirxbuf[4] << 24 | spirxbuf[5] << 16 | spirxbuf[6] << 8 | spirxbuf[7];
|
||||
uint32_t current =
|
||||
spi_airstates->shuntCurrent =
|
||||
spirxbuf[8] << 24 | spirxbuf[9] << 16 | spirxbuf[10] << 8 | spirxbuf[11];
|
||||
spi_airstates->targetTSState = spirxbuf[12];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user