firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
LTC6811.c File Reference

LTC6811 Drivers. More...

#include "LTC6811.h"
Include dependency graph for LTC6811.c:

Macros

#define BOARD_IS_FUCKED   0
#define PEC_TABLE_SIZE   256
#define UNDER_TEMP_LIMIT   10
#define OVER_TEMP_LIMIT   55

Functions

void initPECTable (void)
 Initializes Packet Error Code LUT by generating PEC look up table -> call on startup.
uint16_t calculatePEC (uint8_t len, uint8_t *data)
 This method is used when sending a command to calculate the necessary PEC bytes to follow command bytes. Should be used when receiving data to compare receieved PEC with expected PEC value.
void writeConfigAddress (BMSConfigStructTypedef *cfg, uint8_t address)
 this method is used for cellDischarge in order to write configuration datra to the LTC with specified address
void writeConfigAll (BMSConfigStructTypedef *cfg)
 This function is called every loop to accommodate dischargeCells method Specifically writes configuration data (UV, OV, ADCMode, etc) to BMSConfig struct.
bool readCellVoltage (uint8_t address, uint16_t cellVoltage[12])
 This function sends an ADCV command that begins conversion for every cell to specified LTC. This results in the function readings all cell voltage registers using the readRegister function.
bool readAllCellVoltages (CellData bmsData[144])
 This function reads all cell voltages by essentially parsing each board and reading the individual cell voltages. These are then stored in the bmsData array, along with the cell number that is associated with the reading.
bool readCellTemp (uint8_t address, uint16_t cellTemp[4], bool dcFault[4], bool tempFault[4])
 This function initiates ADC conversion for GPIO inputs connected to temperature sensors. Reads auxiliary register groups using readRegister function. Then, converts measured voltage into temperature based on temperature sensor response. Also checks for disconnected temperature sensor and OT faults. NOTE: We only read 4 temps per board, and they are the 4 highest temps on each board.
bool readAllCellTemps (CellData bmsData[144])
 This function reads cell temps from all of our board by calling readCellTemp for each board. NOTE : This is not proven to work properly yet.
bool readConfig (uint8_t address, uint8_t cfg[8])
 This method uses general readRegister function to check current state of LTC configuration reg. Mostly used for testing purposes.
bool checkAllCellConnections (BMSConfigStructTypedef cfg, CellData bmsData[144])
 This function checks the cell connections of each cell in the BMS data array. Currently not used, as we have not been able to get it working, but the whole idea is that this function compares previously measured values to open wire check values, and if there is a significant drop in voltage, cell is allegedly disconnected.
bool dischargeCellGroups (BMSConfigStructTypedef *cfg, bool cellDischarge[12][12])
 This function writes the configuration struct of cells that are currently being discharged. This is to track which cells are // being discharged while running our balancing algorithm.
void wakeup_idle ()
 This function is used to wakeup the LTC chip that we want to use to get readings from.
bool poll_single_secondary_voltage_reading (uint8_t board_num, BMSConfigStructTypedef *cfg, CellData bmsData[144])
bool poll_single_secondary_temp_reading (uint8_t board_num, BMSConfigStructTypedef *cfg, CellData bmsData[144])
bool readRegister (CommandCodeTypedef command, uint8_t address, uint16_t *data)
 Reads register specified by command from specified board address.
void sendBroadcastCommand (CommandCodeTypedef command)
 Sends specified write only command to every LTC in the chain (ex: ADCV)
void sendAddressCommand (CommandCodeTypedef command, uint8_t address)
 Sends specified write-only command to LTC with the specified address.

Variables

uint16_t pec15Table [PEC_TABLE_SIZE]
uint16_t CRC15_POLY = 0x4599

Detailed Description

LTC6811 Drivers.

Matt Vlasaty: March 29th, 2019 Aditya Nikumbh: Refactored Jan 31, 2024 David Lacayo: April, 2024

Todo
  • checkCellConnection return value needs to disregard unused cell inputs
  • resolve issue with writeConfig not changing every bit in the first register group
  • test functions used to read from every board (readAllCellVoltages should be [12][8])
  • minor changes (using more user-defined constants, changing return values)

Macro Definition Documentation

◆ BOARD_IS_FUCKED

#define BOARD_IS_FUCKED   0

◆ OVER_TEMP_LIMIT

#define OVER_TEMP_LIMIT   55

◆ PEC_TABLE_SIZE

#define PEC_TABLE_SIZE   256

◆ UNDER_TEMP_LIMIT

#define UNDER_TEMP_LIMIT   10

Function Documentation

◆ calculatePEC()

uint16_t calculatePEC ( uint8_t len,
uint8_t * data )

This method is used when sending a command to calculate the necessary PEC bytes to follow command bytes. Should be used when receiving data to compare receieved PEC with expected PEC value.

Parameters
lenis the number of bytes that we will be stepping through in our data
datais the data that we will be using to calculate the expected PEC
Returns
the expected PEC value
Here is the caller graph for this function:

◆ checkAllCellConnections()

bool checkAllCellConnections ( BMSConfigStructTypedef cfg,
CellData bmsData[144] )

This function checks the cell connections of each cell in the BMS data array. Currently not used, as we have not been able to get it working, but the whole idea is that this function compares previously measured values to open wire check values, and if there is a significant drop in voltage, cell is allegedly disconnected.

Parameters
cfgis the BMS configuration struct with constants
bmsDatais an array of 144 cellData structs, containing index, fault, voltage and temperature
Returns
true is the cell is connnected properly, and false if the cell is "disconnected"
Here is the call graph for this function:

◆ dischargeCellGroups()

bool dischargeCellGroups ( BMSConfigStructTypedef * cfg,
bool cellDischarge[12][12] )

This function writes the configuration struct of cells that are currently being discharged. This is to track which cells are // being discharged while running our balancing algorithm.

Parameters
cfgis the configuration struct that stores all the constants in our BMS algorithm
cellDischargeis a 2D array of cells that tracks which cells are being discharged or not : 1 = discharging, 0 = not discharging returns 0 always -> not sure why we need a return value on this
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initPECTable()

void initPECTable ( void )

Initializes Packet Error Code LUT by generating PEC look up table -> call on startup.

Returns
none
Here is the caller graph for this function:

◆ poll_single_secondary_temp_reading()

bool poll_single_secondary_temp_reading ( uint8_t board_num,
BMSConfigStructTypedef * cfg,
CellData bmsData[144] )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ poll_single_secondary_voltage_reading()

bool poll_single_secondary_voltage_reading ( uint8_t board_num,
BMSConfigStructTypedef * cfg,
CellData bmsData[144] )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAllCellTemps()

bool readAllCellTemps ( CellData bmsData[144])

This function reads cell temps from all of our board by calling readCellTemp for each board. NOTE : This is not proven to work properly yet.

Parameters
bmsDatais an array of 144 cellData structs, containing index, fault, voltage and temperature
Returns
true if PEC value received matches expected PEC value. Otherwise, false. -> i.e., returns false if any readCellTemp return values are false.
Here is the call graph for this function:

◆ readAllCellVoltages()

bool readAllCellVoltages ( CellData bmsData[144])

This function reads all cell voltages by essentially parsing each board and reading the individual cell voltages. These are then stored in the bmsData array, along with the cell number that is associated with the reading.

Parameters
bmsDatais an array of 144 cellData structs, containing index, fault, voltage and temperature
Returns
true if no PEC for any register read for any board
Here is the call graph for this function:

◆ readCellTemp()

bool readCellTemp ( uint8_t address,
uint16_t cellTemp[4],
bool dcFault[4],
bool tempFault[4] )

This function initiates ADC conversion for GPIO inputs connected to temperature sensors. Reads auxiliary register groups using readRegister function. Then, converts measured voltage into temperature based on temperature sensor response. Also checks for disconnected temperature sensor and OT faults. NOTE: We only read 4 temps per board, and they are the 4 highest temps on each board.

Parameters
addressis the address of the board being read
cellTempis the array that will hold the cell temps read during readRegister
dcFaultis the array that stores temperature sensor ceonnection for all cells read
tempFaultstores OT fault info for each cell read
Returns
true if PEC value read matches expected PEC value calculated. Otherwise, false.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readCellVoltage()

bool readCellVoltage ( uint8_t address,
uint16_t cellVoltage[12] )

This function sends an ADCV command that begins conversion for every cell to specified LTC. This results in the function readings all cell voltage registers using the readRegister function.

Parameters
addressis the address of the board that will be read
cellVoltageis the array that will store the voltages of all the cells on the board being read
Returns
true if PEC matches expected PEC value, else false
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readConfig()

bool readConfig ( uint8_t address,
uint8_t cfg[8] )

This method uses general readRegister function to check current state of LTC configuration reg. Mostly used for testing purposes.

Parameters
addressis the address passed into the readRegister function
cfgis part of the configuration that will be passed to check the current state of the LTC
Returns
true if the received PEC from readRegister mathes the calculated PEC
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readRegister()

bool readRegister ( CommandCodeTypedef command,
uint8_t address,
uint16_t * data )

Reads register specified by command from specified board address.

Parameters
commandis the command that we will send to the board
addressis the specific board that will get the command
datais where the data read from the specific board will be StartOpenWireConversionPulldown
Returns
true if the data is valid, otherwise false (i.e., received PEC matches expected PEC value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendAddressCommand()

void sendAddressCommand ( CommandCodeTypedef command,
uint8_t address )

Sends specified write-only command to LTC with the specified address.

Parameters
commandis the command that will be sent to the LTC
addressis the specified address of the LTC that will receive the command
Returns
none
Here is the call graph for this function:

◆ sendBroadcastCommand()

void sendBroadcastCommand ( CommandCodeTypedef command)

Sends specified write only command to every LTC in the chain (ex: ADCV)

Parameters
commandcontains every command code used
Returns
none
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wakeup_idle()

void wakeup_idle ( )
inline

This function is used to wakeup the LTC chip that we want to use to get readings from.

Here is the caller graph for this function:

◆ writeConfigAddress()

void writeConfigAddress ( BMSConfigStructTypedef * cfg,
uint8_t address )

this method is used for cellDischarge in order to write configuration datra to the LTC with specified address

Parameters
cfgis the configuration struct for BMS constants
addressis the address used to pass into our config file
Returns
none
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeConfigAll()

void writeConfigAll ( BMSConfigStructTypedef * cfg)

This function is called every loop to accommodate dischargeCells method Specifically writes configuration data (UV, OV, ADCMode, etc) to BMSConfig struct.

Parameters
cfgis the configuration files for the constants in the BMS system
Returns
none
Here is the call graph for this function:

Variable Documentation

◆ CRC15_POLY

uint16_t CRC15_POLY = 0x4599

◆ pec15Table

uint16_t pec15Table[PEC_TABLE_SIZE]