The BMS software focuses on monitoring our 48V lithium-ion battery in order to make sure there are no malfunctions that can result in disasters. It has 4 main parts: Cell Voltage & Monitoring, Current Measurement, Temperature Measurement, and finally Relay Control Logic:
Cell Voltage Reading & Monitoring: The cell voltage reading and monitoring is done through a battery monitoring chip and the communication to the main BMS ATmega via SPI communication. The code modifies registers on the battery monitoring chip to set it to the correct mode and get cell data from it.
Current Reading: The current reading is mostly handled by the electronics circuit and the amplified signal is given to the analog pin of the ATmega chip. The code scales the voltage value to find the real current.
Temperature Measurement: The temperature measurement is done through a MUX chip and the ATmega chip loops through the 16 input pins of the MUX by changing 4 digital output pins. This allows ATmega to monitor all thermistors and it reads their output from an analog pin.
Relay Control Logic: The relay control logic compares all readings with maximum and minimum values and closes or opens the circuit based on the readings.
The main Arduino circuit code focuses on getting inputs from motor controllers and the sensors and giving outputs to the motor controllers for motor functions. It has inputs from the brake, throttle, and the direction knob from the user. It also inputs the motor speeds from the motor controllers, allowing us to implement a PID loop to balance the motor speeds.
The PID Loop: The PID loop operates from the outputs of the speed meters from the motor controllers. We check for the speed differences and if there is a speed difference, the PID loop corrects the error by adding PIDOutput values to the motor speed outputs of the Arduino.