Remove millis() calls from precharge control

This commit is contained in:
Daniel Öster 2025-05-11 21:21:42 +03:00
parent 1b8f3eaf55
commit 03860b17a8
3 changed files with 6 additions and 7 deletions

View file

@ -244,7 +244,7 @@ void core_loop(void*) {
led_exe(); led_exe();
handle_contactors(); // Take care of startup precharge/contactor closing handle_contactors(); // Take care of startup precharge/contactor closing
#ifdef PRECHARGE_CONTROL #ifdef PRECHARGE_CONTROL
handle_precharge_control(); handle_precharge_control(currentMillis);
#endif // PRECHARGE_CONTROL #endif // PRECHARGE_CONTROL
#ifdef FUNCTION_TIME_MEASUREMENT #ifdef FUNCTION_TIME_MEASUREMENT
END_TIME_MEASUREMENT_MAX(time_10ms, datalayer.system.status.time_10ms_us); END_TIME_MEASUREMENT_MAX(time_10ms, datalayer.system.status.time_10ms_us);

View file

@ -35,8 +35,7 @@ void init_precharge_control() {
} }
// Main functions // Main functions
void handle_precharge_control() { void handle_precharge_control(unsigned long currentMillis) {
unsigned long currentTime = millis();
#ifdef MEB_BATTERY #ifdef MEB_BATTERY
int32_t target_voltage = datalayer.battery.status.voltage_dV; int32_t target_voltage = datalayer.battery.status.voltage_dV;
int32_t external_voltage = datalayer_extended.meb.BMS_voltage_intermediate_dV; int32_t external_voltage = datalayer_extended.meb.BMS_voltage_intermediate_dV;
@ -63,7 +62,7 @@ void handle_precharge_control() {
freq = Precharge_default_PWM_Freq; freq = Precharge_default_PWM_Freq;
ledcAttachChannel(PRECHARGE_PIN, freq, PWM_Res, PWM_Precharge_Channel); ledcAttachChannel(PRECHARGE_PIN, freq, PWM_Res, PWM_Precharge_Channel);
ledcWriteTone(PRECHARGE_PIN, freq); // Set frequency and set dutycycle to 50% ledcWriteTone(PRECHARGE_PIN, freq); // Set frequency and set dutycycle to 50%
prechargeStartTime = currentTime; prechargeStartTime = currentMillis;
datalayer.system.status.precharge_status = AUTO_PRECHARGE_PRECHARGING; datalayer.system.status.precharge_status = AUTO_PRECHARGE_PRECHARGING;
#ifdef DEBUG_LOG #ifdef DEBUG_LOG
logging.printf("Precharge: Starting sequence\n"); logging.printf("Precharge: Starting sequence\n");
@ -110,7 +109,7 @@ void handle_precharge_control() {
#ifdef DEBUG_LOG #ifdef DEBUG_LOG
logging.printf("Precharge: Disabling Precharge bms not standby/active or equipment stop\n"); logging.printf("Precharge: Disabling Precharge bms not standby/active or equipment stop\n");
#endif #endif
} else if (currentTime - prechargeStartTime >= MAX_PRECHARGE_TIME_MS || } else if (currentMillis - prechargeStartTime >= MAX_PRECHARGE_TIME_MS ||
datalayer.battery.status.real_bms_status == BMS_FAULT) { datalayer.battery.status.real_bms_status == BMS_FAULT) {
pinMode(PRECHARGE_PIN, OUTPUT); pinMode(PRECHARGE_PIN, OUTPUT);
digitalWrite(PRECHARGE_PIN, LOW); digitalWrite(PRECHARGE_PIN, LOW);

View file

@ -17,11 +17,11 @@ void init_precharge_control();
/** /**
* @brief Handle contactors * @brief Handle contactors
* *
* @param[in] void * @param[in] unsigned long currentMillis
* *
* @return void * @return void
*/ */
void handle_precharge_control(); void handle_precharge_control(unsigned long currentMillis);
/** /**
* @brief Handle contactors of battery 2 * @brief Handle contactors of battery 2