Midnight Sun Firmware
Loading...
Searching...
No Matches
LTC6811

LTC6811 library. More...

Classes

struct  LtcAfeSettings
 Afe Settings Data. More...
 
struct  LtcAfeStorage
 Runtime Data Storage. More...
 
struct  _PACKED
 Configuration for the AFE configuration register group (CFGR). More...
 
union  LtcAfeRegisterData
 

Macros

#define _PACKED
 
#define LTC_AFE_MAX_DEVICES   3
 Maximum AFE devices in daisy chain config. More...
 
#define LTC_AFE_MAX_CELLS_PER_DEVICE   12
 Maximum x of each device. More...
 
#define LTC_AFE_MAX_THERMISTORS_PER_DEVICE   8
 
#define LTC_AFE_MAX_CELLS   (LTC_AFE_MAX_DEVICES * LTC_AFE_MAX_CELLS_PER_DEVICE)
 Maximum across all devices.
 
#define LTC_AFE_MAX_THERMISTORS   (LTC_AFE_MAX_DEVICES * LTC_AFE_MAX_THERMISTORS_PER_DEVICE)
 
#define _PACKED
 Stores all member variables in a struct without padding.
 
#define LTC6811_CELLS_IN_REG   3
 Used internally by the LTC AFE driver (number of regs per reg group)
 
#define LTC6811_GPIOS_IN_REG   3
 
#define AUX_ADG731_NUM_PINS   32
 Used for the external mux (ADG731) connected to the AFE.
 
#define LTC6811_CMD_SIZE   4
 Size of command code (2 bytes) + PEC (2 bytes)
 
#define LTC6811_NUM_COMM_REG_BYTES   3
 3 bytes are required to send 24 clock cycles with our SPI driver for the STCOMM command
 
#define LTC8611_NUM_PWM_REGS   6
 Number of registers in PWM Register Group. See Table 51 on page 64.
 
#define LTC_AFE_MAX_CELLS_PER_DEVICE   12
 Number of voltage cells connected to each device.
 
#define SIZEOF_LTC_AFE_WRITE_CONFIG_PACKET(devices)   (LTC6811_CMD_SIZE + (devices) * sizeof(LtcAfeWriteDeviceConfigPacket))
 
#define LTC6811_WRCFG_RESERVED   (1 << 0)
 Command codes for LTC6811 AFE. More...
 
#define LTC6811_RDCFG_RESERVED   (1 << 1)
 
#define LTC6811_RDCVA_RESERVED   (1 << 2)
 
#define LTC6811_RDCVB_RESERVED   (1 << 2) | (1 << 1)
 
#define LTC6811_RDCVC_RESERVED   (1 << 3)
 
#define LTC6811_RDCVD_RESERVED   (1 << 3) | (1 << 1)
 
#define LTC6811_RDAUXA_RESERVED   ((1 << 3) | (1 << 2))
 
#define LTC6811_RDAUXB_RESERVED   ((1 << 3) | (1 << 2)) | (1 << 1)
 
#define LTC6811_RDSTATA_RESERVED   (1 << 4)
 
#define LTC6811_RDSTATB_RESERVED   (1 << 4) | (1 << 1)
 
#define LTC6811_ADCV_RESERVED   ((1 << 9) | (1 << 6) | (1 << 5))
 
#define LTC6811_ADOW_RESERVED   ((1 << 3) | (1 << 5) | (1 << 9))
 
#define LTC6811_CVST_RESERVED   ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 9))
 
#define LTC6811_ADAX_RESERVED   (1 << 10) | (1 << 6) | (1 << 5)
 
#define LTC6811_CLRCELL_RESERVED   (1 << 0) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define LTC6811_CLRAUX_RESERVED   (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define LTC6811_CLRSTAT_RESERVED   (1 << 0) | (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define LTC6811_PLADC_RESERVED   (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define LTC6811_DIAGN_RESERVED   (1 << 0) | (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define LTC6811_WRCOMM_RESERVED   (1 << 0) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define LTC6811_RDCOMM_RESERVED   (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define LTC6811_STCOMM_RESERVED   (1 << 0) | (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define LTC6811_WRPWM_RESERVED   (1 << 5)
 
#define LTC6811_RDPWM_RESERVED   (1 << 5) | (1 << 2)
 
#define LTC6811_GPIO1_PD_ON   (0 << 3)
 GPIO pull-down configuration for the Config Register Group. More...
 
#define LTC6811_GPIO1_PD_OFF   (1 << 3)
 
#define LTC6811_GPIO2_PD_ON   (0 << 4)
 
#define LTC6811_GPIO2_PD_OFF   (1 << 4)
 
#define LTC6811_GPIO3_PD_ON   (0 << 5)
 
#define LTC6811_GPIO3_PD_OFF   (1 << 5)
 
#define LTC6811_GPIO4_PD_ON   (0 << 6)
 
#define LTC6811_GPIO4_PD_OFF   (1 << 6)
 
#define LTC6811_GPIO5_PD_ON   (0 << 7)
 
#define LTC6811_GPIO5_PD_OFF   (1 << 7)
 
#define LTC6811_CNVT_CELL_ALL   0x00
 ADCV command macros for cell conversion. More...
 
#define LTC6811_CNVT_CELL_1_7   0x01
 
#define LTC6811_CNVT_CELL_2_8   0x02
 
#define LTC6811_CNVT_CELL_3_9   0x03
 
#define LTC6811_CNVT_CELL_4_10   0x04
 
#define LTC6811_CNVT_CELL_5_11   0x05
 
#define LTC6811_CNVT_CELL_6_12   0x06
 
#define LTC6811_ADCV_DISCHARGE_NOT_PERMITTED   (0 << 4)
 ADCV discharge permission macros. More...
 
#define LTC6811_ADCV_DISCHARGE_PERMITTED   (1 << 4)
 
#define LTC6811_ADAX_GPIO1   0x01
 ADAX command macros. More...
 
#define LTC6811_ADAX_GPIO4   0x04
 
#define LTC6811_ADAX_MODE_FAST   (0 << 8) | (1 << 7)
 
#define LTC6811_ICOM_CSBM_LOW   (1 << 3)
 Write Codes for ICOMn (n = 1, 2, 3) More...
 
#define LTC6811_ICOM_CSBM_FALL_EDGE   (1 << 3) | (1 << 0)
 
#define LTC6811_ICOM_CSBM_HIGH   (1 << 3) | (1 << 1)
 
#define LTC6811_ICOM_NO_TRANSMIT   (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0)
 
#define LTC6811_FCOM_CSBM_LOW   (0 << 0)
 Write Codes for FCOMn (n = 1, 2, 3) More...
 
#define LTC6811_FCOM_CSBM_HIGH   (1 << 3) | (1 << 0)
 
#define LTC6811_PWMC_DC_100   (0xF)
 PWM duty cycle configuration (100%). More...
 

Typedefs

typedef struct LtcAfeSettings LtcAfeSettings
 Afe Settings Data. More...
 
typedef struct LtcAfeStorage LtcAfeStorage
 Runtime Data Storage. More...
 

Enumerations

enum  LtcAfeAdcMode {
  LTC_AFE_ADC_MODE_422KHZ = 0 , LTC_AFE_ADC_MODE_27KHZ , LTC_AFE_ADC_MODE_7KHZ , LTC_AFE_ADC_MODE_26HZ ,
  LTC_AFE_ADC_MODE_1KHZ , LTC_AFE_ADC_MODE_14KHZ , LTC_AFE_ADC_MODE_3KHZ , LTC_AFE_ADC_MODE_2KHZ ,
  NUM_LTC_AFE_ADC_MODES
}
 Select the ADC mode. More...
 
enum  LtcAfeRegister {
  LTC_AFE_REGISTER_CONFIG = 0 , LTC_AFE_REGISTER_CELL_VOLTAGE_A , LTC_AFE_REGISTER_CELL_VOLTAGE_B , LTC_AFE_REGISTER_CELL_VOLTAGE_C ,
  LTC_AFE_REGISTER_CELL_VOLTAGE_D , LTC_AFE_REGISTER_AUX_A , LTC_AFE_REGISTER_AUX_B , LTC_AFE_REGISTER_STATUS_A ,
  LTC_AFE_REGISTER_STATUS_B , LTC_AFE_REGISTER_READ_COMM , LTC_AFE_REGISTER_START_COMM , NUM_LTC_AFE_REGISTERS
}
 List of LTC AFE registers. More...
 
enum  LtcAfeVoltageRegister {
  LTC_AFE_VOLTAGE_REGISTER_A = LTC_AFE_REGISTER_CELL_VOLTAGE_A , LTC_AFE_VOLTAGE_REGISTER_B = LTC_AFE_REGISTER_CELL_VOLTAGE_B , LTC_AFE_VOLTAGE_REGISTER_C = LTC_AFE_REGISTER_CELL_VOLTAGE_C , LTC_AFE_VOLTAGE_REGISTER_D = LTC_AFE_REGISTER_CELL_VOLTAGE_D ,
  NUM_LTC_AFE_VOLTAGE_REGISTERS
}
 Voltage registers for easy mapping to LtcAfeRegister
 
enum  LtcAfeDischargeTimeout {
  LTC_AFE_DISCHARGE_TIMEOUT_DISABLED = 0 , LTC_AFE_DISCHARGE_TIMEOUT_30_S , LTC_AFE_DISCHARGE_TIMEOUT_1_MIN , LTC_AFE_DISCHARGE_TIMEOUT_2_MIN ,
  LTC_AFE_DISCHARGE_TIMEOUT_3_MIN , LTC_AFE_DISCHARGE_TIMEOUT_4_MIN , LTC_AFE_DISCHARGE_TIMEOUT_5_MIN , LTC_AFE_DISCHARGE_TIMEOUT_10_MIN ,
  LTC_AFE_DISCHARGE_TIMEOUT_15_MIN , LTC_AFE_DISCHARGE_TIMEOUT_20_MIN , LTC_AFE_DISCHARGE_TIMEOUT_30_MIN , LTC_AFE_DISCHARGE_TIMEOUT_40_MIN ,
  LTC_AFE_DISCHARGE_TIMEOUT_60_MIN , LTC_AFE_DISCHARGE_TIMEOUT_75_MIN , LTC_AFE_DISCHARGE_TIMEOUT_90_MIN , LTC_AFE_DISCHARGE_TIMEOUT_120_MIN
}
 Discharge timeout options for the AFE. More...
 

Functions

StatusCode ltc_afe_init (LtcAfeStorage *afe, const LtcAfeSettings *config)
 Initializes the LTC AFE system with provided configuration settings. More...
 
StatusCode ltc_afe_write_config (LtcAfeStorage *afe)
 Writes configuration bits onto CFGR (Configuration Register Group) More...
 
StatusCode ltc_afe_trigger_cell_conv (LtcAfeStorage *afe)
 Triggers ADC conversion for all enabled cell voltage inputs. More...
 
StatusCode ltc_afe_trigger_aux_conv (LtcAfeStorage *afe, uint8_t device_cell)
 Triggers ADC conversion for an auxiliary (thermistor) input. More...
 
StatusCode ltc_afe_read_cells (LtcAfeStorage *afe)
 Reads and stores cell voltages from the voltage cell registers of each afe. More...
 
StatusCode ltc_afe_read_aux (LtcAfeStorage *afe, uint8_t device_cell)
 Reads and stores auxillary input from GPIO4 of each afe. More...
 
StatusCode ltc_afe_toggle_cell_discharge (LtcAfeStorage *afe, uint16_t cell, bool discharge)
 Mark cell for discharging in each device. More...
 
StatusCode ltc_afe_set_discharge_pwm_cycle (LtcAfeStorage *afe, uint8_t duty_cycle)
 Sets the same discharge PWM duty cycle for all cells across all AFE devices. More...
 
void crc15_init_table (void)
 Initiliaze the CRC15 table for PEC. More...
 
uint16_t crc15_calculate (uint8_t *data, size_t len)
 Calculates CRC15 PEC value for given data. More...
 

Detailed Description

LTC6811 library.

Note
Requires GPIO, Interrupts, Soft Timers, and the Event Queue to be initialized before use.
All voltage units are in 100 µV.
This module supports AFEs with 12 or more cells using the cell/aux bitset.
Due to long conversion delays, the driver uses a finite state machine (FSM) to return control to the application during conversions.
This module is mostly exposed for the FSM. Do not use functions in this module directly.

Macro Definition Documentation

◆ LTC6811_ADAX_GPIO1

#define LTC6811_ADAX_GPIO1   0x01

ADAX command macros.

Select GPIO 1 for ADC Conversion

◆ LTC6811_ADAX_GPIO4

#define LTC6811_ADAX_GPIO4   0x04

Select GPIO 4 for ADC Conversion

◆ LTC6811_ADAX_MODE_FAST

#define LTC6811_ADAX_MODE_FAST   (0 << 8) | (1 << 7)

Select fast ADC mode

◆ LTC6811_ADAX_RESERVED

#define LTC6811_ADAX_RESERVED   (1 << 10) | (1 << 6) | (1 << 5)

Start GPIOs ADC Conversion and Poll Status

◆ LTC6811_ADCV_DISCHARGE_NOT_PERMITTED

#define LTC6811_ADCV_DISCHARGE_NOT_PERMITTED   (0 << 4)

ADCV discharge permission macros.

Determines if cell discharge is permitted during ADCV commands.

◆ LTC6811_ADCV_RESERVED

#define LTC6811_ADCV_RESERVED   ((1 << 9) | (1 << 6) | (1 << 5))

Start Cell Voltage ADC Conversion and Poll Status

◆ LTC6811_ADOW_RESERVED

#define LTC6811_ADOW_RESERVED   ((1 << 3) | (1 << 5) | (1 << 9))

Start Open Wire ADC Conversion and Poll Status

◆ LTC6811_CLRAUX_RESERVED

#define LTC6811_CLRAUX_RESERVED   (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)

Clear Auxillary Register Groups

◆ LTC6811_CLRCELL_RESERVED

#define LTC6811_CLRCELL_RESERVED   (1 << 0) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)

Clear Cell Voltage Register Groups

◆ LTC6811_CLRSTAT_RESERVED

#define LTC6811_CLRSTAT_RESERVED   (1 << 0) | (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)

Clear Status Register Groups

◆ LTC6811_CNVT_CELL_1_7

#define LTC6811_CNVT_CELL_1_7   0x01

Convert cells 1 and 7.

◆ LTC6811_CNVT_CELL_2_8

#define LTC6811_CNVT_CELL_2_8   0x02

Convert cells 2 and 8.

◆ LTC6811_CNVT_CELL_3_9

#define LTC6811_CNVT_CELL_3_9   0x03

Convert cells 3 and 9.

◆ LTC6811_CNVT_CELL_4_10

#define LTC6811_CNVT_CELL_4_10   0x04

Convert cells 4 and 10.

◆ LTC6811_CNVT_CELL_5_11

#define LTC6811_CNVT_CELL_5_11   0x05

Convert cells 5 and 11.

◆ LTC6811_CNVT_CELL_6_12

#define LTC6811_CNVT_CELL_6_12   0x06

Convert cells 6 and 12.

◆ LTC6811_CNVT_CELL_ALL

#define LTC6811_CNVT_CELL_ALL   0x00

ADCV command macros for cell conversion.

Determines which cells to convert during ADCV commands. Convert all cells.

◆ LTC6811_CVST_RESERVED

#define LTC6811_CVST_RESERVED   ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 9))

Start Self Test Cell Voltage Conversion and Poll Status

◆ LTC6811_DIAGN_RESERVED

#define LTC6811_DIAGN_RESERVED   (1 << 0) | (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)

Diagnose MUX and Poll Status

◆ LTC6811_FCOM_CSBM_HIGH

#define LTC6811_FCOM_CSBM_HIGH   (1 << 3) | (1 << 0)

Transitions CSBM high at end of transmission

◆ LTC6811_FCOM_CSBM_LOW

#define LTC6811_FCOM_CSBM_LOW   (0 << 0)

Write Codes for FCOMn (n = 1, 2, 3)

Holds CSBM low at end of transmission

◆ LTC6811_GPIO1_PD_ON

#define LTC6811_GPIO1_PD_ON   (0 << 3)

GPIO pull-down configuration for the Config Register Group.

Note
See Table 40 (p.62) and LtcAfeConfigRegisterData struct for details.

◆ LTC6811_ICOM_CSBM_FALL_EDGE

#define LTC6811_ICOM_CSBM_FALL_EDGE   (1 << 3) | (1 << 0)

CSBM high then low signal

◆ LTC6811_ICOM_CSBM_HIGH

#define LTC6811_ICOM_CSBM_HIGH   (1 << 3) | (1 << 1)

CSBM high signal

◆ LTC6811_ICOM_CSBM_LOW

#define LTC6811_ICOM_CSBM_LOW   (1 << 3)

Write Codes for ICOMn (n = 1, 2, 3)

CSBM low signal

◆ LTC6811_ICOM_NO_TRANSMIT

#define LTC6811_ICOM_NO_TRANSMIT   (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0)

No Data is tranmitted

◆ LTC6811_PLADC_RESERVED

#define LTC6811_PLADC_RESERVED   (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)

Poll ADC Conversion Status

◆ LTC6811_PWMC_DC_100

#define LTC6811_PWMC_DC_100   (0xF)

PWM duty cycle configuration (100%).

Note
See Table 17 (p.38) for details.

◆ LTC6811_RDAUXA_RESERVED

#define LTC6811_RDAUXA_RESERVED   ((1 << 3) | (1 << 2))

Read Auxillary Reg Group A

◆ LTC6811_RDAUXB_RESERVED

#define LTC6811_RDAUXB_RESERVED   ((1 << 3) | (1 << 2)) | (1 << 1)

Read Auxillary Reg Group B

◆ LTC6811_RDCFG_RESERVED

#define LTC6811_RDCFG_RESERVED   (1 << 1)

Read Config Reg Group A

◆ LTC6811_RDCOMM_RESERVED

#define LTC6811_RDCOMM_RESERVED   (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)

Read COMM Register Group

◆ LTC6811_RDCVA_RESERVED

#define LTC6811_RDCVA_RESERVED   (1 << 2)

Read Cell Voltage Reg Group A

◆ LTC6811_RDCVB_RESERVED

#define LTC6811_RDCVB_RESERVED   (1 << 2) | (1 << 1)

Read Cell Voltage Reg Group B

◆ LTC6811_RDCVC_RESERVED

#define LTC6811_RDCVC_RESERVED   (1 << 3)

Read Cell Voltage Reg Group C

◆ LTC6811_RDCVD_RESERVED

#define LTC6811_RDCVD_RESERVED   (1 << 3) | (1 << 1)

Read Cell Voltage Reg Group D

◆ LTC6811_RDPWM_RESERVED

#define LTC6811_RDPWM_RESERVED   (1 << 5) | (1 << 2)

Read PWM Register Group

◆ LTC6811_RDSTATA_RESERVED

#define LTC6811_RDSTATA_RESERVED   (1 << 4)

Read Status Register Group A

◆ LTC6811_RDSTATB_RESERVED

#define LTC6811_RDSTATB_RESERVED   (1 << 4) | (1 << 1)

Read Status Register Group B

◆ LTC6811_WRCFG_RESERVED

#define LTC6811_WRCFG_RESERVED   (1 << 0)

Command codes for LTC6811 AFE.

See Table 38 (p.59) Write Config Reg Group A

◆ LTC6811_WRCOMM_RESERVED

#define LTC6811_WRCOMM_RESERVED   (1 << 0) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)

Write COMM Register Group

◆ LTC6811_WRPWM_RESERVED

#define LTC6811_WRPWM_RESERVED   (1 << 5)

Write PWM Register Group

◆ LTC_AFE_MAX_CELLS_PER_DEVICE

#define LTC_AFE_MAX_CELLS_PER_DEVICE   12

Maximum x of each device.

Note
This is a device limitation

◆ LTC_AFE_MAX_DEVICES

#define LTC_AFE_MAX_DEVICES   3

Maximum AFE devices in daisy chain config.

Note
This is an arbitrary limitation, can be increased/decreased if needed

Typedef Documentation

◆ LtcAfeSettings

Afe Settings Data.

Set by the user when ltc_afe_init is called Stores SPI information, which cell and aux inputs are enabled, and number of things

Note
For more info on SpiSettings refer to spi.h

◆ LtcAfeStorage

typedef struct LtcAfeStorage LtcAfeStorage

Runtime Data Storage.

Stores settings, configs, and voltages for all AFE devices

Note
Raw indices mean
  • Index 0 corresponds to the first cell/aux value of the first AFE device.
  • Index n * max_x_per_device corresponds to the first value of the (n+1)th AFE device.
  • Each AFE's data (voltages, lookups, etc.) is stored contiguously before the next AFE's data.

Enumeration Type Documentation

◆ LtcAfeAdcMode

Select the ADC mode.

Trade-off between speed or minimizing noise

Note
See p 50 for conversion times and p 23 (table 3) for noise
Enumerator
LTC_AFE_ADC_MODE_27KHZ 

Normal

LTC_AFE_ADC_MODE_7KHZ 

Fast

LTC_AFE_ADC_MODE_26HZ 

Filtered

◆ LtcAfeDischargeTimeout

Discharge timeout options for the AFE.

See Table 52 on Page 65 for more details

Enumerator
LTC_AFE_DISCHARGE_TIMEOUT_DISABLED 

Discharge timeout disabled

LTC_AFE_DISCHARGE_TIMEOUT_30_S 

30-second timeout

LTC_AFE_DISCHARGE_TIMEOUT_1_MIN 

1-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_2_MIN 

2-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_3_MIN 

3-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_4_MIN 

4-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_5_MIN 

5-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_10_MIN 

10-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_15_MIN 

15-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_20_MIN 

20-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_30_MIN 

30-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_40_MIN 

40-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_60_MIN 

60-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_75_MIN 

75-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_90_MIN 

90-minute timeout

LTC_AFE_DISCHARGE_TIMEOUT_120_MIN 

120-minute timeout

◆ LtcAfeRegister

List of LTC AFE registers.

These registers are mapped to the s_read_reg[] array in ltc_afe.c

Enumerator
LTC_AFE_REGISTER_CONFIG 

Configuration register

LTC_AFE_REGISTER_CELL_VOLTAGE_A 

Cell voltage register A

LTC_AFE_REGISTER_CELL_VOLTAGE_B 

Cell voltage register B

LTC_AFE_REGISTER_CELL_VOLTAGE_C 

Cell voltage register C

LTC_AFE_REGISTER_CELL_VOLTAGE_D 

Cell voltage register D

LTC_AFE_REGISTER_AUX_A 

Auxiliary register A

LTC_AFE_REGISTER_AUX_B 

Auxiliary register B

LTC_AFE_REGISTER_STATUS_A 

Status register A

LTC_AFE_REGISTER_STATUS_B 

Status register B

LTC_AFE_REGISTER_READ_COMM 

Read communication register

LTC_AFE_REGISTER_START_COMM 

Start communication register

NUM_LTC_AFE_REGISTERS 

Total number of LTC AFE registers

Function Documentation

◆ crc15_calculate()

uint16_t crc15_calculate ( uint8_t *  data,
size_t  len 
)

Calculates CRC15 PEC value for given data.

Parameters
datathe data to calculate the PEC for
lenlength of the data
Returns
uint16_t Return PEC

◆ crc15_init_table()

void crc15_init_table ( void  )

Initiliaze the CRC15 table for PEC.

Used for fast CRC15 lookups

◆ ltc_afe_init()

StatusCode ltc_afe_init ( LtcAfeStorage afe,
const LtcAfeSettings config 
)

Initializes the LTC AFE system with provided configuration settings.

Validates user-defined configuration parameters, sets up SPI communication, calculates result buffer offsets, initializes the CRC15 lookup table, and writes configuration settings to all AFE devices

Parameters
afePointer to LtcAfeStorage struct, stores runtime data and settings of AFE
configPointer to constant LtcAfeSettings struct, contains user-specified configuration parameters
Returns
STATUS_CODE_OK if initialization is successful STATUS_CODE_INVALID_ARGS if device, cell, or thermistor counts exceed defined maximums STATUS_CODE_INTERNAL_ERROR if SPI or configuration writes fail during setup

◆ ltc_afe_read_aux()

StatusCode ltc_afe_read_aux ( LtcAfeStorage afe,
uint8_t  device_cell 
)

Reads and stores auxillary input from GPIO4 of each afe.

RDAUXB command is sent through SPI, and converted values are read from cell register group B Data in the register will be the form: {GPIO4, AUXB2, AUXB3, PEC} Only GPIO4 value is stored, as well as the PEC. PEC of data is compared to PEC read to check for validity Values are stored in the afe->aux_voltages array, if device_cell for device is enabled

Parameters
afePointer to LtcAfeStorage struct, stores runtime data and settings of AFE
device_cellThe GPIO port we want to read from
Returns
STATUS_CODE_OK if auxillary input was read correctly STATUS_CODE_INTERNAL_ERROR if data PEC and PEC read are not the same STATUS_CODE_INVALID_ARGS if arguments are invalid in prv_read_register

◆ ltc_afe_read_cells()

StatusCode ltc_afe_read_cells ( LtcAfeStorage afe)

Reads and stores cell voltages from the voltage cell registers of each afe.

RDCVx (x = A, B, C, D) command is sent to read converted voltage from respective register group Received PEC and PEC of data is compared to see if data is valid Voltages are stored in the afe->cell_voltages array, if cell status is enabled

Parameters
afePointer to LtcAfeStorage struct, stores runtime data and settings of AFE
Returns
STATUS_CODE_OK if cells were read correctly STATUS_CODE_INTERNAL_ERROR if read PEC and calcualted PEC do not match up STATUS_CODE_INVALID_ARGS if arguments are invalid in prv_read_register

◆ ltc_afe_set_discharge_pwm_cycle()

StatusCode ltc_afe_set_discharge_pwm_cycle ( LtcAfeStorage afe,
uint8_t  duty_cycle 
)

Sets the same discharge PWM duty cycle for all cells across all AFE devices.

Configures the PWM duty cycle registers on each AFE device so that all 12 cell discharge channels operate at the same specified duty cycle. Each register controls 2 channels, so 6 registers are written per device. Prepares a write command and transmits it to all AFE devices.

Parameters
afePointer to LtcAfeStorage struct containing runtime data and settings
duty_cycle4-bit duty cycle value (0x0 to 0xF) to set for all PWM channels
Returns
STATUS_CODE_OK if the PWM configuration was successfully transmitted STATUS_CODE_INVALID_ARGS if parameters passed to spi_exchange are invalid STATUS_CODE_INTERNAL_ERROR if SPI transmission fails

Initialize a buffer to store the PWM configuration command, while also accounting for the number of registers to write to (6) for each AFE, which is not known at compile time.

Since each AFE has 12 PWM channels and each PWM register stores two 4-bit PWM values in a byte, there are 6 registers to iterate through and 2 PWM channels are configured at a time.

◆ ltc_afe_toggle_cell_discharge()

StatusCode ltc_afe_toggle_cell_discharge ( LtcAfeStorage afe,
uint16_t  cell,
bool  discharge 
)

Mark cell for discharging in each device.

Device number is reverse indexed, since ltc_afe_write_config writes configs in reverse order Appropriate bit in discharge_bitset in LtcAfeConfigRegisterData is marked (see ltc_afe_regs.h) Only takes effect when config is rewritten with ltc_afe_write_config

Parameters
afePointer to LtcAfeStorage struct, stores runtime data and settings of AFE
cellIndex of cell at device x (cell = cell # in device + (# of cells * device_number))
dischargeIs cell being discharged or not?
Returns
STATUS_CODE_OK if cell discharge was correctly toggled correctly STATUS_CODE_INVALID_ARGS if cell index is invalid

◆ ltc_afe_trigger_aux_conv()

StatusCode ltc_afe_trigger_aux_conv ( LtcAfeStorage afe,
uint8_t  device_cell 
)

Triggers ADC conversion for an auxiliary (thermistor) input.

Selects the specified thermistor by configuring GPIO bits, then builds and transmits the ADAX command to begin auxiliary ADC conversion using GPIO4. Supports thermistors mapped to 5 available GPIO inputs across devices.

Parameters
afePointer to LtcAfeStorage struct containing runtime data and settings
thermistorIndex of the thermistor to measure (0-7 across devices)
Returns
STATUS_CODE_OK if the ADAX command was successfully transmitted STATUS_CODE_INVALID_ARGS if arguments passed to spi_exchange are invalid STATUS_CODE_INTERNAL_ERROR if SPI transmission fails

◆ ltc_afe_trigger_cell_conv()

StatusCode ltc_afe_trigger_cell_conv ( LtcAfeStorage afe)

Triggers ADC conversion for all enabled cell voltage inputs.

Builds and transmits the ADCV command using the configured ADC mode to start cell voltage conversion across all AFE devices. Puts device into active mode before initiating conversion.

Parameters
afePointer to LtcAfeStorage struct containing runtime data and settings
Returns
STATUS_CODE_OK if the ADCV command was successfully transmitted STATUS_CODE_INVALID_ARGS if arguments passed to spi_exchange are invalid STATUS_CODE_INTERNAL_ERROR if SPI transmission fails

◆ ltc_afe_write_config()

StatusCode ltc_afe_write_config ( LtcAfeStorage afe)

Writes configuration bits onto CFGR (Configuration Register Group)

Writes configuration bits to each of the AFE devices' configuration register bits

Parameters
afePointer to LtcAfeStorage struct, stores runtime data and settings of AFE
Returns
STATUS_CODE_OK if configs were written onto register STATUS_CODE_INVALID_ARGS if one of the parameters in spi_exchange is incorrect in prv_write_config STATUS_CODE_INTERNAL_ERROR if HAL transmission/receiving fails STATUS_CODE_TIMEOUT if transmission/receiving takes too long
Note
Only for initial config