From cfb327628ebcabf3b5794b7e0aa44ed715a58f65 Mon Sep 17 00:00:00 2001 From: Leonid Pozdneev Date: Fri, 17 May 2019 23:22:09 -0400 Subject: [PATCH 1/4] added activation of accumulator fans when BMS is balancing --- Vehicle/Main_Control_Unit/Main_Control_Unit.ino | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Vehicle/Main_Control_Unit/Main_Control_Unit.ino b/Vehicle/Main_Control_Unit/Main_Control_Unit.ino index 9f4f25d5..15410ba7 100644 --- a/Vehicle/Main_Control_Unit/Main_Control_Unit.ino +++ b/Vehicle/Main_Control_Unit/Main_Control_Unit.ino @@ -410,6 +410,16 @@ void parse_can_message() { if (rx_msg.id == ID_BMS_STATUS) { bms_status.load(rx_msg.buf); + + /* + * Turn on fans when BMS is balancing + */ + if (bms_satus.get_state() > BMS_STATE_CHARGING) { + digitalWrite(FAN_1, HIGH); + } + else { + digitalWrite(FAN_1, LOW); + } } if (rx_msg.id == ID_BMS_TEMPERATURES) { From 60f4598887e1ab8e9057cdc3c2a8675fea93a976 Mon Sep 17 00:00:00 2001 From: Leonid Pozdneev Date: Sat, 18 May 2019 16:05:17 -0400 Subject: [PATCH 2/4] added proper temperature calculation for MCU thermistor --- .../Main_Control_Unit/Main_Control_Unit.ino | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Vehicle/Main_Control_Unit/Main_Control_Unit.ino b/Vehicle/Main_Control_Unit/Main_Control_Unit.ino index 15410ba7..50487aa1 100644 --- a/Vehicle/Main_Control_Unit/Main_Control_Unit.ino +++ b/Vehicle/Main_Control_Unit/Main_Control_Unit.ino @@ -366,11 +366,6 @@ void loop() { */ if (mcu_status.get_state() < MCU_STATE_READY_TO_DRIVE && timer_motor_controller_send.check()) { MC_command_message mc_command_message = MC_command_message(0, 0, 1, 0, 0, 0); - - // if (mcu_status.get_state() >= MCU_STATE_ENABLING_INVERTER) { - // mc_command_message.set_inverter_enable(true); - // } - mc_command_message.write(tx_msg.buf); tx_msg.id = ID_MC_COMMAND_MESSAGE; tx_msg.len = 8; @@ -412,9 +407,9 @@ void parse_can_message() { bms_status.load(rx_msg.buf); /* - * Turn on fans when BMS is balancing + * Turn on accumulator fans when BMS is balancing */ - if (bms_satus.get_state() > BMS_STATE_CHARGING) { + if (bms_status.get_state() > BMS_STATE_CHARGING) { digitalWrite(FAN_1, HIGH); } else { @@ -531,9 +526,22 @@ void read_status_values() { mcu_status.set_shutdown_f_above_threshold(analogRead(SENSE_SHUTDOWN_F) > SHUTDOWN_F_HIGH); /* - * Measure the temperature from on-board thermistors + * Calculate the resistance of the thermistor based on the ADC reading + * R = 10k * ((5V / Vout) + 1) */ - mcu_status.set_temperature(ADC.read_adc(ADC_TEMPSENSE_CHANNEL) * 100); // send temperatures in 0.01 C + double thermistor_resistance = 1e4 * ((4095.0 / ADC.read_adc(ADC_TEMPSENSE_CHANNEL)) + 1); + + /* + * Temperature equation (in Kelvin) based on resistance is the following: + * 1/T = 1/T0 + (1/B) * ln(R/R0) (R = thermistor resistance) + * T = 1/(1/T0 + (1/B) * ln(R/R0)) + */ + double T0 = 298.15; // 25C in Kelvin + double b = 3380; // B constant of the thermistor + double R0 = 10000; // Resistance of thermistor at 25C + double temperature = 1 / ((1 / T0) + (1 / b) * log(thermistor_resistance / R0)) - (double) 273.15; + + mcu_status.set_temperature(temperature * 100); // send temperatures in 0.01 C } /* From 824b29ff6c3d5e280144c47eaae7ca85493597db Mon Sep 17 00:00:00 2001 From: Leonid Pozdneev Date: Sat, 20 Jul 2019 13:04:49 -0400 Subject: [PATCH 3/4] testing can --- .../can_send_and_receive_test.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Utilities/can_send_and_receive_test/can_send_and_receive_test.ino b/Utilities/can_send_and_receive_test/can_send_and_receive_test.ino index 77b0576a..7764d31a 100644 --- a/Utilities/can_send_and_receive_test/can_send_and_receive_test.ino +++ b/Utilities/can_send_and_receive_test/can_send_and_receive_test.ino @@ -7,8 +7,9 @@ FlexCAN CAN(500000); CAN_message_t msg; -Metro timer_can = Metro(1000); +Metro timer_can = Metro(10); Metro timer_light = Metro(3); +long count = 0; void setup() { Serial.begin(115200); // Initialize serial for PC communication @@ -21,7 +22,7 @@ void setup() { } void loop() { - + if (timer_can.check()) { // Send a message on CAN uint32_t t = millis(); msg.id = 0x1; @@ -35,9 +36,12 @@ void loop() { Serial.print(msg.buf[i]); Serial.print(" "); } + Serial.print("MICROS: "); + Serial.print(micros() - count); Serial.println(); + count = micros(); } - + while (CAN.read(msg)) { // Receive a message on CAN Serial.print("Received 0x"); Serial.print(msg.id, HEX); From b2fe960f98477d1967f3ce81f38fe2a39ec93055 Mon Sep 17 00:00:00 2001 From: Leonid Pozdneev Date: Sat, 10 Aug 2019 18:23:53 -0400 Subject: [PATCH 4/4] reverted changes to CAN testing code --- .../can_send_and_receive_test.ino | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Utilities/can_send_and_receive_test/can_send_and_receive_test.ino b/Utilities/can_send_and_receive_test/can_send_and_receive_test.ino index 7764d31a..77b0576a 100644 --- a/Utilities/can_send_and_receive_test/can_send_and_receive_test.ino +++ b/Utilities/can_send_and_receive_test/can_send_and_receive_test.ino @@ -7,9 +7,8 @@ FlexCAN CAN(500000); CAN_message_t msg; -Metro timer_can = Metro(10); +Metro timer_can = Metro(1000); Metro timer_light = Metro(3); -long count = 0; void setup() { Serial.begin(115200); // Initialize serial for PC communication @@ -22,7 +21,7 @@ void setup() { } void loop() { - + if (timer_can.check()) { // Send a message on CAN uint32_t t = millis(); msg.id = 0x1; @@ -36,12 +35,9 @@ void loop() { Serial.print(msg.buf[i]); Serial.print(" "); } - Serial.print("MICROS: "); - Serial.print(micros() - count); Serial.println(); - count = micros(); } - + while (CAN.read(msg)) { // Receive a message on CAN Serial.print("Received 0x"); Serial.print(msg.id, HEX);