This commit is contained in:
hamza 2024-07-08 14:44:01 +03:00
parent 39f124efc6
commit 17e8cee0ac
7 changed files with 36 additions and 20 deletions

View File

@ -29,3 +29,11 @@ V1.5
- int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES] to float - int16_t auxVoltages[MAXIMUM_AUX_VOLTAGES] to float
- errors out when no messages are recieved for CAN_TIMEOUT messages - errors out when no messages are recieved for CAN_TIMEOUT messages
- void set_error_source(int source); -> void set_error_source(SlaveErrorKind source); - void set_error_source(int source); -> void set_error_source(SlaveErrorKind source);
V1.6
- set temperature limit to 59
- precharge and discharge durations are now 5 seconds
- RELAY_BAT/ESC_SIDE and CURRENT_MEASUREMENT to int32_t
- CAN messages are now correctly formated
- minimum cell voltage is now set to 3200 mV
- powerground calibration is now done in STATE_PRECHARGE (well yes but actually no)

View File

@ -18,9 +18,9 @@
// Time to wait after reaching 95% of battery voltage before exiting precharge // 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 // Set this to 1000 in scruti to demonstrate the voltage on the multimeter
#define PRECHARGE_DURATION 3000 // ms #define PRECHARGE_DURATION 5000 // ms
// Time to wait for discharge // Time to wait for discharge
#define DISCHARGE_DURATION 3000 // ms #define DISCHARGE_DURATION 5000 // ms
// Time to wait for charger voltage before going to TS_ERROR // Time to wait for charger voltage before going to TS_ERROR
#define MAX_CHARGING_CHECK_DURATION 2000 // ms #define MAX_CHARGING_CHECK_DURATION 2000 // ms
// Time to wait between closing relays // Time to wait between closing relays
@ -62,9 +62,9 @@ typedef struct {
} StateHandle; } StateHandle;
extern StateHandle state; extern StateHandle state;
extern int16_t RELAY_BAT_SIDE_VOLTAGE; extern int32_t RELAY_BAT_SIDE_VOLTAGE;
extern int16_t RELAY_ESC_SIDE_VOLTAGE; extern int32_t RELAY_ESC_SIDE_VOLTAGE;
extern int16_t CURRENT_MEASUREMENT; extern int32_t CURRENT_MEASUREMENT;
extern uint8_t powerground_status; extern uint8_t powerground_status;

View File

@ -136,7 +136,7 @@ uint8_t AMS_Idle_Loop() {
int any_voltage_error = 0; int any_voltage_error = 0;
for (size_t i = 0; i < numberofCells; i++) { for (size_t i = 0; i < numberofCells; i++) {
if (module.cellVoltages[i] < 2500) { if (module.cellVoltages[i] < 3200) {
any_voltage_error = 1; any_voltage_error = 1;
error_data.data_kind = SEK_UNDERVOLT; error_data.data_kind = SEK_UNDERVOLT;
error_data.data[0] = i; error_data.data[0] = i;

View File

@ -51,6 +51,7 @@ void PWM_powerground_control(uint8_t percent){
if (percent > 100){ //something went wrong if (percent > 100){ //something went wrong
__HAL_TIM_SET_COMPARE(powerground, TIM_CHANNEL_3, 0); __HAL_TIM_SET_COMPARE(powerground, TIM_CHANNEL_3, 0);
__HAL_TIM_SET_COMPARE(powerground, TIM_CHANNEL_4, 0); __HAL_TIM_SET_COMPARE(powerground, TIM_CHANNEL_4, 0);
powerground_status = 0;
return; return;
} }
powerground_status = percent; powerground_status = percent;

View File

@ -1,6 +1,6 @@
#include "TMP1075.h" #include "TMP1075.h"
#define MAX_TEMP ((int16_t)(30 / 0.0625f)) #define MAX_TEMP ((int16_t)(59 / 0.0625f))
#define MAX_FAILED_TEMP 2 //TODO: change value for compliance with the actual number of sensors #define MAX_FAILED_TEMP 2 //TODO: change value for compliance with the actual number of sensors
#warning "change value for compliance with the actual number of sensors" #warning "change value for compliance with the actual number of sensors"

View File

@ -67,10 +67,10 @@ void can_handle_send_status() {
data[0] = ((state.current_state << 4) | (powerground_status >> 4)); // 1 bit emptyy | 3 bit state | 4 bit powerground data[0] = ((state.current_state << 4) | (powerground_status >> 4)); // 1 bit emptyy | 3 bit state | 4 bit powerground
data[1] = ((powerground_status << 4) | (state.error_source >> 4)); // 4 bit powerground | 4 bit error data[1] = ((powerground_status << 4) | (state.error_source >> 4)); // 4 bit powerground | 4 bit error
data[2] = ((state.error_source << 4) | (0)); // 4 bit error | 4 bit state of charge data[2] = ((state.error_source << 4) | (0)); // 4 bit error | 4 bit state of charge
data[3] = ((0) + (RELAY_BAT_SIDE_VOLTAGE >> 12)); // 4 bit state of charge | 4 bit battery voltage data[3] = ((RELAY_BAT_SIDE_VOLTAGE >> 8)); // 4 bit state of charge | 4 bit battery voltage
data[4] = ((RELAY_BAT_SIDE_VOLTAGE >> 4)); data[4] = ((RELAY_BAT_SIDE_VOLTAGE >> 0));
data[5] = ((CURRENT_MEASUREMENT >> 8)); data[5] = ((CURRENT_MEASUREMENT >> 8));
data[6] = ((CURRENT_MEASUREMENT & 0x00F0) | (highest_temp >> 12)); data[6] = ((CURRENT_MEASUREMENT & 0x000F) | (highest_temp >> 12));
data[7] = ((highest_temp) >> 4); data[7] = ((highest_temp) >> 4);
//data[7] = state.error_source; //data[7] = state.error_source;
ftcan_transmit(CAN_ID_OUT, data, sizeof(data)); ftcan_transmit(CAN_ID_OUT, data, sizeof(data));
@ -110,6 +110,14 @@ void can_handle_send_status() {
data[7] = 0; data[7] = 0;
ftcan_transmit(CAN_ID_OUT, data, sizeof(data)); ftcan_transmit(CAN_ID_OUT, data, sizeof(data));
021E 30
0232 50
0238 60
0246 70
0250 80
025A 90
0264 100
*/ */
} }

View File

@ -16,10 +16,11 @@
#include <stdint.h> #include <stdint.h>
StateHandle state; StateHandle state;
int16_t RELAY_BAT_SIDE_VOLTAGE; int32_t RELAY_BAT_SIDE_VOLTAGE;
int16_t RELAY_ESC_SIDE_VOLTAGE; int32_t RELAY_ESC_SIDE_VOLTAGE;
int16_t CURRENT_MEASUREMENT; int32_t CURRENT_MEASUREMENT;
bool CURRENT_MEASUREMENT_ON; bool CURRENT_MEASUREMENT_ON;
float base_offset = 0;
uint8_t powerground_status; uint8_t powerground_status;
uint32_t precharge_timer; uint32_t precharge_timer;
@ -44,15 +45,14 @@ void sm_update(){
sm_check_errors(); sm_check_errors();
sm_precharge_discharge_manager(); sm_precharge_discharge_manager();
sm_calibrate_powerground(); sm_calibrate_powerground();
if (CAN_timer < HAL_GetTick()) //if (CAN_timer < HAL_GetTick())
state.current_state = state.target_state = STATE_ERROR; // state.current_state = state.target_state = STATE_ERROR;
int16_t base_offset = 0;
if (state.current_state == STATE_INACTIVE){ if (state.current_state == STATE_INACTIVE){
base_offset = module.auxVoltages[0]; base_offset = module.auxVoltages[0];
} }
CURRENT_MEASUREMENT = (module.auxVoltages[0] - base_offset) * 300; CURRENT_MEASUREMENT = roundf((module.auxVoltages[0] - base_offset) * 350);
CURRENT_MEASUREMENT_ON = (module.auxVoltages[1] > 2400); CURRENT_MEASUREMENT_ON = (module.auxVoltages[1] > 2400);
RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[2] * 11.711; RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[2] * 11.711;
RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[3] * 11.711; // the calculation says the factor is 11. 11.711 yields the better result RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[3] * 11.711; // the calculation says the factor is 11. 11.711 yields the better result
@ -120,7 +120,6 @@ State sm_update_ready(){
case STATE_DISCHARGE: // if CAN Signal 0000 0000 then shutdown case STATE_DISCHARGE: // if CAN Signal 0000 0000 then shutdown
return STATE_DISCHARGE; return STATE_DISCHARGE;
default: default:
sm_calibrate_powerground();
return STATE_READY; return STATE_READY;
} }
} }
@ -266,7 +265,7 @@ void sm_calibrate_powerground(){
if (powerground_calibration_stage != 4 && state.current_state == STATE_READY){ if (powerground_calibration_stage != 4 && state.current_state == STATE_READY){
switch (powerground_calibration_stage) { switch (powerground_calibration_stage) {
case 0: case 0:
powerground_calibration_timer = HAL_GetTick() + 5000; powerground_calibration_timer = HAL_GetTick() + 0;
powerground_calibration_stage = 1; powerground_calibration_stage = 1;
return; return;
case 1: case 1:
@ -348,7 +347,7 @@ void sm_check_errors(){
state.error_type.bms_timeout = (error_data.error_sources & (1 << 7)) ? 1 : 0; state.error_type.bms_timeout = (error_data.error_sources & (1 << 7)) ? 1 : 0;
state.error_type.bms_fault = (error_data.error_sources & (1 << 8) || error_data.error_sources & (1 << 10) || error_data.error_sources & (1 << 9)) ? 1 : 0; state.error_type.bms_fault = (error_data.error_sources & (1 << 8) || error_data.error_sources & (1 << 10) || error_data.error_sources & (1 << 9)) ? 1 : 0;
//SEK_EEPROM_ERR: state.error_type.eeprom_error = 1; //SEK_EEPROM_ERR: state.error_type.eeprom_error = 1;
state.error_type.current_error = (powerground_status > 10 && CURRENT_MEASUREMENT < 1000) ? 1 : 0; //state.error_type.current_error = (powerground_status > 10 && CURRENT_MEASUREMENT < 500) ? 1 : 0;
state.error_type.current_sensor_missing = (!CURRENT_MEASUREMENT_ON) ? 1 : 0; state.error_type.current_sensor_missing = (!CURRENT_MEASUREMENT_ON) ? 1 : 0;
state.error_type.voltage_missing = (RELAY_BAT_SIDE_VOLTAGE < 1000) ? 1 : 0; state.error_type.voltage_missing = (RELAY_BAT_SIDE_VOLTAGE < 1000) ? 1 : 0;