0% found this document useful (0 votes)
161 views19 pages

BMS File Converter Code Overview

This document discusses coding for battery monitoring using an Mbed microcontroller and LTC6804-2 IC. It provides an overview of the components including cells, microcontroller, and IC. It then describes constructing code to configure the IC registers, start ADC conversions, read cell and auxiliary pin values, and store them temporarily. Key functions are explained like initializing the ICs, configuring ADC states, reading cell voltages and auxiliary pins, clearing registers, and SPI communication. The goal is to understand how to code the battery monitoring system using the provided IC functions.

Uploaded by

boby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views19 pages

BMS File Converter Code Overview

This document discusses coding for battery monitoring using an Mbed microcontroller and LTC6804-2 IC. It provides an overview of the components including cells, microcontroller, and IC. It then describes constructing code to configure the IC registers, start ADC conversions, read cell and auxiliary pin values, and store them temporarily. Key functions are explained like initializing the ICs, configuring ADC states, reading cell voltages and auxiliary pins, clearing registers, and SPI communication. The goal is to understand how to code the battery monitoring system using the provided IC functions.

Uploaded by

boby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BATTERY & BMS

CODING ON MBED
LET'S TAKE A LOOK AT THE
SYSTEM

SOME COMPLICATED
CONNECTIONS CONNECTIONS COMPONENTS (NOT REQUIRED
FOR UNDERSTANDING THIS)

A CELL(A BUNCH OF
THESE ARE USED)

EMBED-
MICROCONTROLLER
(THIS IS WHERE OUR
CODE GOES INTO)
UNDERSTANDING THE IC-LTC6804-2

WHAT CAN THE IC DO?


Each IC can measure up to a maximum of 12 cells.

It can do passive balancing for each of the cell.

It can be used to measure temperature.

NOW WE ARE USING ALL THESE FUNCTIONS FOR


OUR PURPOSE. THE ABOVE OVERVIEW WILL
HELP US UNDERSTAND THE CONSTRUCTION OF
THE CODE.
CODE

CONSTRUCTION OF THE CODE


1. Starting and setting up the SPI communication.

2. Assigning the required values to the configuration registers.


(For each functionality of the IC there exist various modes of
operation. For configuring these modes we need to assign
some values to these configuration registers.)

3. Now we have to start the ADC conversion of the raw voltage


values and temperature values.

4. Finally we have to store the values received (temporarily) and


then provide them to the microcontroller.
THE CONFIGURATION REGISTERS

The table below shows six configuration registers(CFGR0-5) with the corresponding bit wise implication.

Now we will choose the value of each bit for each register step by step.

CFGR0 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

Use GPIO5 GPIO4 GPIO3 GPIO2 GPIO1 REFON SWTRD ADCOPT

Value used 0 0 0 0 0 1 * 0

GPIOx is 1 if xth pin used and 0 if it's not used.


REFON is 1 if 'we have to power up the reference until the watchdog timeout' and 0 if 'we have to shut
down after every conversion'.
Understanding REFON in a better way

A CELL ADC
CONVERTER OUTPUT

THIS IS GOING TO
THIS WILL HAVE CONVERT THESE
SOME VOLTAGE ANALOG VALUES TO
RELATED TO IT.(AN THE CORRESPONDING
ANALOG VALUE) DIGITAL VALUES.

Now the thing to understand here is that the ADC converter will not be converting all the time and
it needs some power (energy) to do the job. If we choose REFUP to be 1 then it will always be
powered up until watchdog timer expires and if it's chosen to be 0 then it shuts down after every
conversion.
THE CONFIGURATION REGISTERS

The SWTRD is read only and is used for telling the SWETEN pin status. In our case it doesn't matter if it's
value is either 0 or 1.

ADCOPT is used for selecting the mode of operation of ADC. ADC can operate on 7kHz, 2kHz, 3kHz,
27kHz, 14kHz and [Link] 0 is used to select from 27, 7or 26 kHz and 1 is used to select from 14, 3
or 2 kHz which in turn can be further selected from using the MD[1:0] Bits.

VUV and VOV refers to under voltage and over voltage comparison voltages respective. We don't use this
feature. Hence all bits are assigned 0.

CFGR1 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

Use VUV[7] VUV[6] VUV[5] VUV[4] VUV[3] VUV[2] VUV[1] VUV[0]

Value used 0 0 0 0 0 0 0 0

CFGR2 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

Use VOV[3] VOV[2] VOV[1] VOV[0] VUV[11] VUV[10] VUV[9] VUV[8]

Value used 0 0 0 0 0 0 0 0
THE CONFIGURATION REGISTERS

CFGR3 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

Use VOV[11] VOV[10] VOV[9] VOV[8] VOV[7] VOV[6] VOV[5] VOV[4]

Value used 0 0 0 0 0 0 0 0

CFGR4 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

Use DCC8 DCC7 DCC6 DCC5 DCC4 DCC3 DCC2 DCC1

Value used 0 0 0 0 0 0 0 0

CFGR5 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

Use DCTO[3] DCTO[2] DCTO[1] DCTO[0] DCC12 DCC11 DCC10 DCC9

Value used 0 0 0 1 0 0 0 0
THE CONFIGURATION REGISTERS

DCCi refers to whether the ith cell will discharge or not. 1 corresponds to it being discharged and 0
corresponding to it not being discharged. Therefore initially we let all the DCC bits to be 0.

DCTO refers to the timeout discharge value, which is matched according to the following table:

This is the value


which we are
considering to take.
UNDERSTANDING THE PROVIDED FUNCTIONS

THE CODE

Now let's try to understand the various prebuilt functions


provided by Linear Technology in their .cpp file.
The functions are as:

THIS FUNCTION IS USED FOR CONFIGURING(OR INITIALISING) ALL THE ICS ACCORDING TO THE REQUIREMENTS. IT
CAN BE CLEARLY SEEN THAT IT'S CALLING OTHER VARIOUS FUNCTIONS INSIDE OF IT, THEREFORE THEIR EXACT
MEANING WILL ALSO BE CLEARED LATER. ONE THING TO NOTE HERE IS THAT ALL THE VARIABLES USED INSIDE
THE FUNCTIONS MUST EITHER BE GLOBAL OR PREDEFINED.
FUNCTIONS

THIS FUNCTION IS USED FOR CONFIGURING THE STATE OF THE ADC CONVERTERS. WHAT'S HAPPENING INSIDE IS
THAT WITH THE VARIABLES PASSED TO THE FUNCTION, IT IS SETTING THE GLOBAL VARIABLES ADAX AND ADCV TO
THE REQUIRED VALUES(THESE ARE USED WHILE SENDING SPI MESSAGES). ANOTHER THING TO UNDERSTAND IS
THE MEANING ASSOCIATED WITH THE PASSED VARIABLES.

ADCV configures Cpin inputs.

ADAX configures GPIO pins.


FUNCTIONS

THIS FUNCTION STARTS THE CONVERSION OF CPIN INPUT VOLTAGES.


NOTE- TEMP_PEC IS A TEMPORARY VARIABLE MANAGING PEC ERROR(IT IS SIMILAR TO THE CHECKSUM).
FUNCTIONS

THIS FUNCTION STARTS THE CONVERSION OF GPIO PINS.


NOTE- TEMP_PEC IS A TEMPORARY VARIABLE MANAGING PEC ERROR(IT IS SIMILAR TO THE CHECKSUM).
FUNCTIONS

THIS FUNCTION WILL SEND THE COMMAND TO READ THE CELL VOLTAGES, PARSE THE DATA AND THEN STORE
THEM IN 'CELL_CODES' ARRAY.
REG: THIS VARIABLE TELL ABOUT THE GROUP OF CELL REGISTERS TO READ, WITH 0-4 CORRESPONDING TO
ALL, A-D RESPECTIVELY.
TOTAL_IC: THIS CORRESPONDS TO THE TOTAL NUMBER OF LTC6804 CONNECTED TO THE MBED.
THIS FUNCTION RETURNS 0 IF NO ERROR IS DETECTED AND -1 IF PEC ERROR IS DETECTED.
FUNCTIONS

THIS FUNCTION IS USUALLY USED INSIDE THE PREVIOUS FUNCTION FOR STORING THE RAW DATA FROM A
SINGLE CELL VOLTAGE [Link]- THIS DATA IS NOT PARSED.

THIS FUNCTION IS SIMILAR TO LTC6804_RDCV FUNCTION, THE DIFFERENCE BEING IT OPERATED ON


AUXILIARY PINS.
REG: THIS VARIABLE TELLS ABOUT THE GROUP OF REGISTERS TO READ, WITH 0-2 CORRESPONDING TO
ALL, A AND B RESPECTIVELY.
THE 6 ELEMENTS IN 'AUX_CODES' ARRAY CORRESPONDS TO GPIO1-5 AND VREF2 PINS' DATA.
FUNCTIONS

THIS FUNCTION IS JUST SIMILAR TO 'LTC6804_RDCV_REG' FUNCTION. THE DIFFERENCE BEING IT


HANDLES AUXILIARY PINS.

THIS COMMAND CLEARS ALL THE CELL VOLTAGE REGISTERS AND INITIALISES THEM TO 1.

THIS COMMAND CLEARS ALL THE AUXILIARY REGISTERS AND INITIALISES THEM TO 1.
FUNCTIONS
FUNCTIONS

WAKE ISOSPI FROM IDLE STATE.

WAKE LTC6804 FROM THE SLEEP STATE


FUNCTIONS

THIS FUNCTION WRITES AN ARRAY OF BYTES OUT OF THE SPI PORT.

THIS FUNCTION READS AND WRITES A SET NUMBER OF BYTES USING THE SPI PORT.

Common questions

Powered by AI

Configuration registers like CFGR0 and CFGR1 in the IC-LTC6804-2 are used to set up and control various functionalities of the chip. CFGR0 is crucial for setting GPIO usage, reference power configurations (REFON), and ADC operation modes (ADCOPT). For example, REFON determines whether the reference remains powered up until the watchdog timeout or shuts down after every conversion, influencing power consumption . CFGR1 is not utilized for its default under-voltage settings in this context, as all bits are set to 0, disabling under-voltage detection . These configuration registers provide flexibility and control over the operation of the IC depending on the application requirements.

The ADCOPT value in the CFGR0 register of IC-LTC6804-2 determines the ADC operation frequency by allowing the selection between high-frequency and low-frequency modes. An ADCOPT of 0 selects between 27, 7, or 26 kHz, while a value of 1 selects from 14, 3, or 2 kHz, with further selection made via MD[1:0] bits . This adjustment is significant because it affects the balance between conversion speed and power consumption, which can be critical depending on the application's power budget and performance requirements. Choosing the correct ADC frequency ensures that the IC operates efficiently within its intended application.

The global variables ADAX and ADCV are integral to automated configuration functions within the IC-LTC6804-2 as they define the configuration states for GPIO and CPIN inputs respectively. ADAX determines the setup for external connections through GPIOs, influencing peripheral interactions and system control capabilities. Meanwhile, ADCV configures how CPIN inputs are interpreted for voltage readings, crucial for accurate battery monitoring . These variables enable dynamic system configuration, allowing automated adjustment to varying operational conditions without manual intervention, thereby enhancing system robustness and operational efficiency in embedded applications.

Setting up and configuring SPI communication is crucial for the successful operation of the IC-LTC6804-2 in embedded systems since SPI serves as the primary interface for data exchange between the microcontroller and the IC. The configuration involves initializing communication parameters, such as clock polarity, phase, and data rate, ensuring that these settings match the IC's requirements for correctly timed signal transmission . Proper SPI setup facilitates reliable transfer of configuration commands and retrieval of real-time battery data like cell voltages and temperatures. Any misconfiguration can result in communication errors, leading to potential data corruption and system malfunction, highlighting the importance of thorough SPI setup.

Setting the REFON bit in the CFGR0 register impacts both energy consumption and functionality by controlling the power state of the reference circuit. A REFON value of 1 keeps the reference powered on until the watchdog timer expires, ensuring continuous operation but consuming more energy. Conversely, setting REFON to 0 allows the reference to power down following every conversion, which conserves energy by reducing the standby power draw but requires the reference to power up for each measurement, potentially affecting measurement speed . This trade-off is critical in battery management applications where energy efficiency is paramount for extending operational time.

The Packet Error Code (PEC) is used for error checking in SPI communication with the IC-LTC6804-2. It acts similar to a checksum, ensuring the integrity of the data transmitted over the SPI interface. If an error is detected during the communication, the function returns an error code, indicating that the transmitted data was corrupted . This mechanism is crucial for reliable data transfer, especially in applications where data integrity is critical, such as monitoring and managing the state of charge in battery systems.

The function responsible for reading cell voltages in the IC-LTC6804-2 is designed to send commands to the IC that allow it to acquire voltage data from connected battery cells. This function parses the raw data, storing it in the 'CELL_CODES' array for further analysis or action . For data integrity, this function uses the CRC (Cyclic Redundancy Check) mechanism, identifying any errors in transmission with a return value of -1 if a PEC error is detected . By ensuring accurate and error-free data retrieval, this function is essential for maintaining the reliability of battery status monitoring, preventing erroneous decisions based on faulty data readings.

The functionality to start the conversion of CPIN input voltages in the IC-LTC6804-2 directly influences the data acquisition process by initiating the analog-to-digital conversion of cell voltages from connected battery cells. This ensures that the analog signals representing voltage levels are converted into digital data for processing by the microcontroller . By enabling this conversion, the IC-LTC6804-2 can provide real-time monitoring of voltage levels, important for battery management tasks such as balancing and safety monitoring. The function ensures accurate data capture, which is essential for timely and precise system adjustments.

GPIO pin configuration in the IC-LTC6804-2 is significant because it allows the IC to interface with a multitude of external devices and sensors, thereby enhancing the flexibility and adaptability of system design. By configuring GPIO pins through the CFGR0 register, users can select which pins are active, each serving functions such as status indication, control signal transmission, and external event detection . This configurability allows the IC to be tailored to specific application needs, supporting diverse operational environments and custom system integrations without the need for additional hardware modifications.

The DIAG (diagnostic) modes in the IC-LTC6804-2 play a critical role in enhancing system safety and reliability by providing built-in self-test mechanisms to check the functionality of IC operations. They allow users to diagnose faults in voltage measurement by using diagnostic commands that verify whether the internal components of the IC are functioning correctly. This diagnostic capability helps in proactively identifying issues that could otherwise lead to failures in monitoring battery parameters, thus ensuring the reliability and safety of the system . This feature is especially important in battery management systems where accurate monitoring of cell voltages is critical for preventing failures and maintaining optimum performance.

You might also like