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

ADBMS1818 library. More...

Classes

struct  AdbmsAfeSettings
 Afe Settings Data. More...
 
struct  AdbmsAfeStorage
 Runtime Data Storage. More...
 
struct  _PACKED
 Configuration for the AFE configuration register group A (CFGRA). More...
 
union  AdbmsAfeRegisterData
 

Macros

#define _PACKED
 
#define ADBMS_AFE_MAX_DEVICES   3
 Maximum AFE devices in daisy chain config. More...
 
#define ADBMS_AFE_MAX_CELLS_PER_DEVICE   18
 Maximum x of each device. More...
 
#define ADBMS_AFE_MAX_CELL_THERMISTORS_PER_DEVICE   16
 
#define ADBMS_AFE_MAX_BOARD_THERMISTORS_PER_DEVICE   1
 
#define ADBMS_AFE_MAX_CELLS   (ADBMS_AFE_MAX_DEVICES * ADBMS_AFE_MAX_CELLS_PER_DEVICE)
 Maximum across all devices.
 
#define ADBMS_AFE_MAX_CELL_THERMISTORS   (ADBMS_AFE_MAX_DEVICES * ADBMS_AFE_MAX_CELL_THERMISTORS_PER_DEVICE)
 
#define ADBMS_AFE_MAX_BOARD_THERMISTORS   (ADBMS_AFE_MAX_DEVICES * ADBMS_AFE_MAX_CELL_THERMISTORS_PER_DEVICE)
 
#define _PACKED
 Stores all member variables in a struct without padding.
 
#define ADBMS1818_CELLS_IN_REG   3
 Used internally by the ADBMS AFE driver (number of regs per reg group)
 
#define ADBMS1818_GPIOS_IN_REG   3
 
#define AUX_ADG731_NUM_PINS   32
 Used for the external mux (ADG731) connected to the AFE.
 
#define ADBMS1818_CMD_SIZE   4
 Size of command code (2 bytes) + PEC (2 bytes)
 
#define ADBMS1818_NUM_COMM_REG_BYTES   3
 3 bytes are required to send 24 clock cycles with our SPI driver for the STCOMM command
 
#define ADBMS1818_NUM_PWMR_REGS   6
 Number of registers in PWM Register Group. See Table 70 on page 68.
 
#define ADBMS1818_NUM_PSR_REGS   6
 Macros for PWM/S control register group B. More...
 
#define ADBMS1818_NUM_PWM_REGS_IN_PSR   3
 
#define ADBMS1818_NUM_SCTL_REGS_IN_PSR   3
 
#define ADBMS1818_NUM_PWMS_REGS   6
 Number of registers in PWM/S Register Group. See Table 71 on page 68.
 
#define ADBMS_AFE_MAX_CELLS_PER_DEVICE   18
 Number of voltage cells connected to each device.
 
#define ADBMS1818_WRCFGA_RESERVED   (1 << 0)
 Command codes for ADBMS1818 AFE. More...
 
#define ADBMS1818_WRCFGB_RESERVED   (1 << 5) | (1 << 2)
 
#define ADBMS1818_RDCFGA_RESERVED   (1 << 1)
 
#define ADBMS1818_RDCFGB_RESERVED   (1 << 5) | (1 << 2) | (1 << 1)
 
#define ADBMS1818_RDCVA_RESERVED   (1 << 2)
 
#define ADBMS1818_RDCVB_RESERVED   (1 << 2) | (1 << 1)
 
#define ADBMS1818_RDCVC_RESERVED   (1 << 3)
 
#define ADBMS1818_RDCVD_RESERVED   (1 << 3) | (1 << 1)
 
#define ADBMS1818_RDCVE_RESERVED   (1 << 3) | (1 << 0)
 
#define ADBMS1818_RDCVF_RESERVED   (1 << 3) | (1 << 1) | (1 << 0)
 
#define ADBMS1818_RDAUXA_RESERVED   ((1 << 3) | (1 << 2))
 
#define ADBMS1818_RDAUXB_RESERVED   ((1 << 3) | (1 << 2)) | (1 << 1)
 
#define ADBMS1818_RDAUXC_RESERVED   ((1 << 3) | (1 << 2)) | (1 << 0)
 
#define ADBMS1818_RDAUXD_RESERVED   ((1 << 3) | (1 << 2)) | (1 << 1) | (1 << 0)
 
#define ADBMS1818_RDSTATA_RESERVED   (1 << 4)
 
#define ADBMS1818_RDSTATB_RESERVED   (1 << 4) | (1 << 1)
 
#define ADBMS1818_WRSCTRL_RESERVED   (1 << 4) | (1 << 2)
 
#define ADBMS1818_WRPWM_RESERVED   (1 << 5)
 
#define ADBMS1818_WRPSB_RESERVED   (1 << 4) | (1 << 3) | (1 << 2)
 
#define ADBMS1818_RDSCTRL_RESERVED   (1 << 4) | (1 << 2) | (1 << 1)
 
#define ADBMS1818_RDPWM_RESERVED   (1 << 5) | (1 << 2)
 
#define ADBMS1818_RDPSB_RESERVED   (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1)
 
#define ADBMS1818_STSCTRL_RESERVED   (1 << 4) | (1 << 3) | (1 << 0)
 
#define ADBMS1818_CLRSCTRL_RESERVED   (1 << 4) | (1 << 3)
 
#define ADBMS1818_ADCV_RESERVED   ((1 << 9) | (1 << 6) | (1 << 5))
 
#define ADBMS1818_ADOW_RESERVED   ((1 << 3) | (1 << 5) | (1 << 9))
 
#define ADBMS1818_CVST_RESERVED   ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 9))
 
#define ADBMS1818_ADAX_RESERVED   (1 << 10) | (1 << 6) | (1 << 5)
 
#define ADBMS1818_CLRCELL_RESERVED   (1 << 0) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define ADBMS1818_CLRAUX_RESERVED   (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define ADBMS1818_CLRSTAT_RESERVED   (1 << 0) | (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define ADBMS1818_PLADC_RESERVED   (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define ADBMS1818_DIAGN_RESERVED   (1 << 0) | (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define ADBMS1818_WRCOMM_RESERVED   (1 << 0) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define ADBMS1818_RDCOMM_RESERVED   (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define ADBMS1818_STCOMM_RESERVED   (1 << 0) | (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)
 
#define ADBMS1818_GPIO1_PD_ON   (0 << 3)
 GPIO pull-down configuration for the Config Register Group. More...
 
#define ADBMS1818_GPIO1_PD_OFF   (1 << 3)
 
#define ADBMS1818_GPIO2_PD_ON   (0 << 4)
 
#define ADBMS1818_GPIO2_PD_OFF   (1 << 4)
 
#define ADBMS1818_GPIO3_PD_ON   (0 << 5)
 
#define ADBMS1818_GPIO3_PD_OFF   (1 << 5)
 
#define ADBMS1818_GPIO4_PD_ON   (0 << 6)
 
#define ADBMS1818_GPIO4_PD_OFF   (1 << 6)
 
#define ADBMS1818_GPIO5_PD_ON   (0 << 7)
 
#define ADBMS1818_GPIO5_PD_OFF   (1 << 7)
 
#define ADBMS1818_GPIO6_PD_ON   (0 << 0)
 
#define ADBMS1818_GPIO6_PD_OFF   (1 << 0)
 
#define ADBMS1818_GPIO7_PD_ON   (0 << 1)
 
#define ADBMS1818_GPIO7_PD_OFF   (1 << 1)
 
#define ADBMS1818_GPIO8_PD_ON   (0 << 2)
 
#define ADBMS1818_GPIO8_PD_OFF   (1 << 2)
 
#define ADBMS1818_GPIO9_PD_ON   (0 << 3)
 
#define ADBMS1818_GPIO9_PD_OFF   (1 << 3)
 
#define ADBMS1818_CNVT_CELL_ALL   0x00
 ADCV command macros for cell conversion. More...
 
#define ADBMS1818_CNVT_CELL_1_7_13   0x01
 
#define ADBMS1818_CNVT_CELL_2_8_14   0x02
 
#define ADBMS1818_CNVT_CELL_3_9_15   0x03
 
#define ADBMS1818_CNVT_CELL_4_10_16   0x04
 
#define ADBMS1818_CNVT_CELL_5_11_17   0x05
 
#define ADBMS1818_CNVT_CELL_6_12_18   0x06
 
#define ADBMS1818_ADCV_DISCHARGE_NOT_PERMITTED   (0 << 4)
 ADCV discharge permission macros. More...
 
#define ADBMS1818_ADCV_DISCHARGE_PERMITTED   (1 << 4)
 
#define ADBMS1818_ADAX_GPIO_ALL   0x00
 ADAX command macros. More...
 
#define ADBMS1818_ADAX_GPIO1_6   0x01
 
#define ADBMS1818_ADAX_GPIO2_7   0x02
 
#define ADBMS1818_ADAX_GPIO3_8   0x03
 
#define ADBMS1818_ADAX_GPIO4_9   0x04
 
#define ADBMS1818_ADAX_GPIO5   0x05
 
#define ADBMS1818_ADAX_REF2   0x06
 
#define ADBMS1818_ADAX_MODE_FAST   (0 << 8) | (1 << 7)
 
#define ADBMS1818_ICOM_CSBM_LOW   (1 << 3)
 Write Codes for ICOMn (n = 1, 2, 3) More...
 
#define ADBMS1818_ICOM_CSBM_FALL_EDGE   (1 << 3) | (1 << 0)
 
#define ADBMS1818_ICOM_CSBM_HIGH   (1 << 3) | (1 << 1)
 
#define ADBMS1818_ICOM_NO_TRANSMIT   (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0)
 
#define ADBMS1818_FCOM_CSBM_LOW   (0 << 0)
 Write Codes for FCOMn (n = 1, 2, 3) More...
 
#define ADBMS1818_FCOM_CSBM_HIGH   (1 << 3) | (1 << 0)
 
#define ADBMS1818_PWMC_DC_100   (0xF)
 PWM duty cycle configuration (100%). More...
 

Typedefs

typedef struct AdbmsAfeSettings AdbmsAfeSettings
 Afe Settings Data. More...
 
typedef struct AdbmsAfeStorage AdbmsAfeStorage
 Runtime Data Storage. More...
 

Enumerations

enum  AdbmsAfeAdcMode {
  ADBMS_AFE_ADC_MODE_422HZ = 0 , ADBMS_AFE_ADC_MODE_27KHZ , ADBMS_AFE_ADC_MODE_7KHZ , ADBMS_AFE_ADC_MODE_26HZ ,
  ADBMS_AFE_ADC_MODE_1KHZ , ADBMS_AFE_ADC_MODE_14KHZ , ADBMS_AFE_ADC_MODE_3KHZ , ADBMS_AFE_ADC_MODE_2KHZ ,
  NUM_ADBMS_AFE_ADC_MODES
}
 Select the ADC mode. More...
 
enum  AdbmsAfeRegister {
  ADBMS_AFE_REGISTER_CONFIG_A = 0 , ADBMS_AFE_REGISTER_CONFIG_B , ADBMS_AFE_REGISTER_CELL_VOLTAGE_A , ADBMS_AFE_REGISTER_CELL_VOLTAGE_B ,
  ADBMS_AFE_REGISTER_CELL_VOLTAGE_C , ADBMS_AFE_REGISTER_CELL_VOLTAGE_D , ADBMS_AFE_REGISTER_CELL_VOLTAGE_E , ADBMS_AFE_REGISTER_CELL_VOLTAGE_F ,
  ADBMS_AFE_REGISTER_AUX_A , ADBMS_AFE_REGISTER_AUX_B , ADBMS_AFE_REGISTER_AUX_C , ADBMS_AFE_REGISTER_AUX_D ,
  ADBMS_AFE_REGISTER_STATUS_A , ADBMS_AFE_REGISTER_STATUS_B , ADBMS_AFE_REGISTER_READ_COMM , ADBMS_AFE_REGISTER_START_COMM ,
  NUM_ADBMS_AFE_REGISTERS
}
 List of ADBMS AFE registers. More...
 
enum  AdbmsAfeVoltageRegister {
  ADBMS_AFE_VOLTAGE_REGISTER_A = ADBMS_AFE_REGISTER_CELL_VOLTAGE_A , ADBMS_AFE_VOLTAGE_REGISTER_B = ADBMS_AFE_REGISTER_CELL_VOLTAGE_B , ADBMS_AFE_VOLTAGE_REGISTER_C = ADBMS_AFE_REGISTER_CELL_VOLTAGE_C , ADBMS_AFE_VOLTAGE_REGISTER_D = ADBMS_AFE_REGISTER_CELL_VOLTAGE_D ,
  ADBMS_AFE_VOLTAGE_REGISTER_E = ADBMS_AFE_REGISTER_CELL_VOLTAGE_E , ADBMS_AFE_VOLTAGE_REGISTER_F = ADBMS_AFE_REGISTER_CELL_VOLTAGE_F , NUM_ADBMS_AFE_VOLTAGE_REGISTERS
}
 Voltage registers for easy mapping to AdbmsAfeRegister
 
enum  AdbmsAfeDischargeTimeout {
  ADBMS_AFE_DISCHARGE_TIMEOUT_DISABLED = 0 , ADBMS_AFE_DISCHARGE_TIMEOUT_30_S , ADBMS_AFE_DISCHARGE_TIMEOUT_1_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_2_MIN ,
  ADBMS_AFE_DISCHARGE_TIMEOUT_3_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_4_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_5_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_10_MIN ,
  ADBMS_AFE_DISCHARGE_TIMEOUT_15_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_20_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_30_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_40_MIN ,
  ADBMS_AFE_DISCHARGE_TIMEOUT_60_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_75_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_90_MIN , ADBMS_AFE_DISCHARGE_TIMEOUT_120_MIN
}
 Discharge timeout options for the AFE. More...
 

Functions

StatusCode adbms_afe_init (AdbmsAfeStorage *afe, const AdbmsAfeSettings *config)
 Initializes the ADBMS AFE system with provided configuration settings. More...
 
StatusCode adbms_afe_write_config (AdbmsAfeStorage *afe)
 Writes configuration bits onto CFGR (Configuration Register Group) More...
 
StatusCode adbms_afe_trigger_cell_conv (AdbmsAfeStorage *afe)
 Triggers ADC conversion for all enabled cell voltage inputs. More...
 
StatusCode adbms_afe_trigger_thermistor_conv (AdbmsAfeStorage *afe, uint8_t device_num, uint8_t thermistor_index)
 Triggers ADC conversion for the specified thermistor voltage inputs. More...
 
StatusCode adbms_afe_trigger_board_temp_conv (AdbmsAfeStorage *afe, uint8_t device_num)
 Triggers ADC conversion for the specified board temperature thermistor input. More...
 
StatusCode adbms_afe_read_cells (AdbmsAfeStorage *afe)
 Reads and stores cell voltages from the voltage cell registers of each afe. More...
 
StatusCode adbms_afe_read_thermistor (AdbmsAfeStorage *afe, uint8_t device_num, uint8_t thermistor_index)
 Reads and stores thermistor voltages from the aux voltage registers of each afe. More...
 
StatusCode adbms_afe_read_board_temp (AdbmsAfeStorage *afe, uint8_t device_num)
 Reads and stores board temperature thermistor voltage from the aux voltage registers of each afe. More...
 
StatusCode adbms_afe_toggle_cell_discharge (AdbmsAfeStorage *afe, uint16_t cell, bool discharge)
 Mark cell for discharging in each device. More...
 
StatusCode adbms_afe_set_discharge_pwm_cycle (AdbmsAfeStorage *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

ADBMS1818 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/thermistor 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

◆ ADBMS1818_ADAX_GPIO1_6

#define ADBMS1818_ADAX_GPIO1_6   0x01

Convert GPIO1 and GPIO6.

◆ ADBMS1818_ADAX_GPIO2_7

#define ADBMS1818_ADAX_GPIO2_7   0x02

Convert GPIO2 and GPIO7.

◆ ADBMS1818_ADAX_GPIO3_8

#define ADBMS1818_ADAX_GPIO3_8   0x03

Convert GPIO3 and GPIO8.

◆ ADBMS1818_ADAX_GPIO4_9

#define ADBMS1818_ADAX_GPIO4_9   0x04

Convert GPIO4 and GPIO9.

◆ ADBMS1818_ADAX_GPIO5

#define ADBMS1818_ADAX_GPIO5   0x05

Convert GPIO5 only.

◆ ADBMS1818_ADAX_GPIO_ALL

#define ADBMS1818_ADAX_GPIO_ALL   0x00

ADAX command macros.

Convert GPIO1–GPIO5, 2nd reference, and GPIO6–GPIO9.

◆ ADBMS1818_ADAX_MODE_FAST

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

Select fast ADC mode

◆ ADBMS1818_ADAX_REF2

#define ADBMS1818_ADAX_REF2   0x06

Convert 2nd reference only (VREF2).

◆ ADBMS1818_ADAX_RESERVED

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

Start GPIOs ADC Conversion and Poll Status

◆ ADBMS1818_ADCV_DISCHARGE_NOT_PERMITTED

#define ADBMS1818_ADCV_DISCHARGE_NOT_PERMITTED   (0 << 4)

ADCV discharge permission macros.

Determines if cell discharge is permitted during ADCV commands.

◆ ADBMS1818_ADCV_RESERVED

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

Start Cell Voltage ADC Conversion and Poll Status

◆ ADBMS1818_ADOW_RESERVED

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

Start Open Wire ADC Conversion and Poll Status

◆ ADBMS1818_CLRAUX_RESERVED

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

Clear Auxillary Register Groups

◆ ADBMS1818_CLRCELL_RESERVED

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

Clear Cell Voltage Register Groups

◆ ADBMS1818_CLRSCTRL_RESERVED

#define ADBMS1818_CLRSCTRL_RESERVED   (1 << 4) | (1 << 3)

Clear S COntrol Register Group

◆ ADBMS1818_CLRSTAT_RESERVED

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

Clear Status Register Groups

◆ ADBMS1818_CNVT_CELL_1_7_13

#define ADBMS1818_CNVT_CELL_1_7_13   0x01

Convert cells 1, 7, and 13.

◆ ADBMS1818_CNVT_CELL_2_8_14

#define ADBMS1818_CNVT_CELL_2_8_14   0x02

Convert cells 2, 8, and 14.

◆ ADBMS1818_CNVT_CELL_3_9_15

#define ADBMS1818_CNVT_CELL_3_9_15   0x03

Convert cells 3, 9, and 15.

◆ ADBMS1818_CNVT_CELL_4_10_16

#define ADBMS1818_CNVT_CELL_4_10_16   0x04

Convert cells 4, 10, and 16.

◆ ADBMS1818_CNVT_CELL_5_11_17

#define ADBMS1818_CNVT_CELL_5_11_17   0x05

Convert cells 5, 11, and 17.

◆ ADBMS1818_CNVT_CELL_6_12_18

#define ADBMS1818_CNVT_CELL_6_12_18   0x06

Convert cells 6, 12, and 18.

◆ ADBMS1818_CNVT_CELL_ALL

#define ADBMS1818_CNVT_CELL_ALL   0x00

ADCV command macros for cell conversion.

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

◆ ADBMS1818_CVST_RESERVED

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

Start Self Test Cell Voltage Conversion and Poll Status

◆ ADBMS1818_DIAGN_RESERVED

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

Diagnose MUX and Poll Status

◆ ADBMS1818_FCOM_CSBM_HIGH

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

Transitions CSBM high at end of transmission

◆ ADBMS1818_FCOM_CSBM_LOW

#define ADBMS1818_FCOM_CSBM_LOW   (0 << 0)

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

Holds CSBM low at end of transmission

◆ ADBMS1818_GPIO1_PD_ON

#define ADBMS1818_GPIO1_PD_ON   (0 << 3)

GPIO pull-down configuration for the Config Register Group.

Note
See Table 72 (p.68) and AdbmsAfeConfigReg isterXData struct for details.

◆ ADBMS1818_ICOM_CSBM_FALL_EDGE

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

CSBM high then low signal

◆ ADBMS1818_ICOM_CSBM_HIGH

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

CSBM high signal

◆ ADBMS1818_ICOM_CSBM_LOW

#define ADBMS1818_ICOM_CSBM_LOW   (1 << 3)

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

CSBM low signal

◆ ADBMS1818_ICOM_NO_TRANSMIT

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

No Data is tranmitted

◆ ADBMS1818_NUM_PSR_REGS

#define ADBMS1818_NUM_PSR_REGS   6

Macros for PWM/S control register group B.

Number of registers in PWM/S Control register group B

◆ ADBMS1818_NUM_PWM_REGS_IN_PSR

#define ADBMS1818_NUM_PWM_REGS_IN_PSR   3

Number of PWM registers in the PWM/S control register group B

◆ ADBMS1818_NUM_SCTL_REGS_IN_PSR

#define ADBMS1818_NUM_SCTL_REGS_IN_PSR   3

Number of SCTL registers in the PWM/S control register group B

◆ ADBMS1818_PLADC_RESERVED

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

Poll ADC Conversion Status

◆ ADBMS1818_PWMC_DC_100

#define ADBMS1818_PWMC_DC_100   (0xF)

PWM duty cycle configuration (100%).

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

◆ ADBMS1818_RDAUXA_RESERVED

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

Read Auxillary Reg Group A

◆ ADBMS1818_RDAUXB_RESERVED

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

Read Auxillary Reg Group B

◆ ADBMS1818_RDAUXC_RESERVED

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

Read Auxillary Reg Group C

◆ ADBMS1818_RDAUXD_RESERVED

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

Read Auxillary Reg Group D

◆ ADBMS1818_RDCFGA_RESERVED

#define ADBMS1818_RDCFGA_RESERVED   (1 << 1)

Read Config Reg Group A

◆ ADBMS1818_RDCFGB_RESERVED

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

Read Config Reg Group B

◆ ADBMS1818_RDCOMM_RESERVED

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

Read COMM Register Group

◆ ADBMS1818_RDCVA_RESERVED

#define ADBMS1818_RDCVA_RESERVED   (1 << 2)

Read Cell Voltage Reg Group A

◆ ADBMS1818_RDCVB_RESERVED

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

Read Cell Voltage Reg Group B

◆ ADBMS1818_RDCVC_RESERVED

#define ADBMS1818_RDCVC_RESERVED   (1 << 3)

Read Cell Voltage Reg Group C

◆ ADBMS1818_RDCVD_RESERVED

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

Read Cell Voltage Reg Group D

◆ ADBMS1818_RDCVE_RESERVED

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

Read Cell Voltage Reg Group E

◆ ADBMS1818_RDCVF_RESERVED

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

Read Cell Voltage Reg Group F

◆ ADBMS1818_RDPSB_RESERVED

#define ADBMS1818_RDPSB_RESERVED   (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1)

Read PWM Register Group

◆ ADBMS1818_RDPWM_RESERVED

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

Read PWM Register Group

◆ ADBMS1818_RDSCTRL_RESERVED

#define ADBMS1818_RDSCTRL_RESERVED   (1 << 4) | (1 << 2) | (1 << 1)

Read S Control Register Group

◆ ADBMS1818_RDSTATA_RESERVED

#define ADBMS1818_RDSTATA_RESERVED   (1 << 4)

Read Status Register Group A

◆ ADBMS1818_RDSTATB_RESERVED

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

Read Status Register Group B

◆ ADBMS1818_STSCTRL_RESERVED

#define ADBMS1818_STSCTRL_RESERVED   (1 << 4) | (1 << 3) | (1 << 0)

Start S Control Pulsing and Poll Status

◆ ADBMS1818_WRCFGA_RESERVED

#define ADBMS1818_WRCFGA_RESERVED   (1 << 0)

Command codes for ADBMS1818 AFE.

See Table 52 (p.61) Write Config Reg Group A

◆ ADBMS1818_WRCFGB_RESERVED

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

Write Config Reg Group B

◆ ADBMS1818_WRCOMM_RESERVED

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

Write COMM Register Group

◆ ADBMS1818_WRPSB_RESERVED

#define ADBMS1818_WRPSB_RESERVED   (1 << 4) | (1 << 3) | (1 << 2)

Write PWM/S Control Register Group B

◆ ADBMS1818_WRPWM_RESERVED

#define ADBMS1818_WRPWM_RESERVED   (1 << 5)

Write PWM Register Group

◆ ADBMS1818_WRSCTRL_RESERVED

#define ADBMS1818_WRSCTRL_RESERVED   (1 << 4) | (1 << 2)

Write S Control Register Group

◆ ADBMS_AFE_MAX_CELLS_PER_DEVICE

#define ADBMS_AFE_MAX_CELLS_PER_DEVICE   18

Maximum x of each device.

Note
This is a device limitation

◆ ADBMS_AFE_MAX_DEVICES

#define ADBMS_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

◆ AdbmsAfeSettings

Afe Settings Data.

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

Note
For more info on SpiSettings refer to spi.h

◆ AdbmsAfeStorage

Runtime Data Storage.

Stores settings, configs, and voltages for all AFE devices

Note
Raw indices mean
  • Index 0 corresponds to the first cell/thermistor 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

◆ AdbmsAfeAdcMode

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
ADBMS_AFE_ADC_MODE_27KHZ 

Normal

ADBMS_AFE_ADC_MODE_7KHZ 

Fast

ADBMS_AFE_ADC_MODE_26HZ 

Filtered

◆ AdbmsAfeDischargeTimeout

Discharge timeout options for the AFE.

See Table 72 on Page 68 for more details

Enumerator
ADBMS_AFE_DISCHARGE_TIMEOUT_DISABLED 

Discharge timeout disabled

ADBMS_AFE_DISCHARGE_TIMEOUT_30_S 

30-second timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_1_MIN 

1-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_2_MIN 

2-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_3_MIN 

3-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_4_MIN 

4-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_5_MIN 

5-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_10_MIN 

10-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_15_MIN 

15-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_20_MIN 

20-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_30_MIN 

30-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_40_MIN 

40-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_60_MIN 

60-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_75_MIN 

75-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_90_MIN 

90-minute timeout

ADBMS_AFE_DISCHARGE_TIMEOUT_120_MIN 

120-minute timeout

◆ AdbmsAfeRegister

List of ADBMS AFE registers.

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

Enumerator
ADBMS_AFE_REGISTER_CONFIG_A 

Configuration register A

ADBMS_AFE_REGISTER_CONFIG_B 

Configuration register B

ADBMS_AFE_REGISTER_CELL_VOLTAGE_A 

Cell voltage register A

ADBMS_AFE_REGISTER_CELL_VOLTAGE_B 

Cell voltage register B

ADBMS_AFE_REGISTER_CELL_VOLTAGE_C 

Cell voltage register C

ADBMS_AFE_REGISTER_CELL_VOLTAGE_D 

Cell voltage register D

ADBMS_AFE_REGISTER_CELL_VOLTAGE_E 

Cell voltage register E

ADBMS_AFE_REGISTER_CELL_VOLTAGE_F 

Cell voltage register F

ADBMS_AFE_REGISTER_AUX_A 

Auxiliary register A

ADBMS_AFE_REGISTER_AUX_B 

Auxiliary register B

ADBMS_AFE_REGISTER_AUX_C 

Auxiliary register C

ADBMS_AFE_REGISTER_AUX_D 

Auxiliary register D

ADBMS_AFE_REGISTER_STATUS_A 

Status register A

ADBMS_AFE_REGISTER_STATUS_B 

Status register B

ADBMS_AFE_REGISTER_READ_COMM 

Read communication register

ADBMS_AFE_REGISTER_START_COMM 

Start communication register

NUM_ADBMS_AFE_REGISTERS 

Total number of ADBMS AFE registers

Function Documentation

◆ adbms_afe_init()

StatusCode adbms_afe_init ( AdbmsAfeStorage afe,
const AdbmsAfeSettings config 
)

Initializes the ADBMS 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 AdbmsAfeStorage struct, stores runtime data and settings of AFE
configPointer to constant AdbmsAfeSettings 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

◆ adbms_afe_read_board_temp()

StatusCode adbms_afe_read_board_temp ( AdbmsAfeStorage afe,
uint8_t  device_num 
)

Reads and stores board temperature thermistor voltage from the aux voltage registers of each afe.

Received PEC and PEC of data is compared to see if data is valid Voltages are stored in the afe->board_thermistor_voltages array

Parameters
afePointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE
device_numTarget device number
Returns
STATUS_CODE_OK if thermistors 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 s_read_register

◆ adbms_afe_read_cells()

StatusCode adbms_afe_read_cells ( AdbmsAfeStorage 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 AdbmsAfeStorage 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 s_read_register

◆ adbms_afe_read_thermistor()

StatusCode adbms_afe_read_thermistor ( AdbmsAfeStorage afe,
uint8_t  device_num,
uint8_t  thermistor_index 
)

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

Received PEC and PEC of data is compared to see if data is valid Voltages are stored in the afe->thermistor_voltages array

Parameters
afePointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE
device_numTarget device number
thermistor_indexThermistor index between 0-16
Returns
STATUS_CODE_OK if thermistors 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 s_read_register

◆ adbms_afe_set_discharge_pwm_cycle()

StatusCode adbms_afe_set_discharge_pwm_cycle ( AdbmsAfeStorage 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 18 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 AdbmsAfeStorage 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 for the PWMR group 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.

◆ adbms_afe_toggle_cell_discharge()

StatusCode adbms_afe_toggle_cell_discharge ( AdbmsAfeStorage afe,
uint16_t  cell,
bool  discharge 
)

Mark cell for discharging in each device.

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

Parameters
afePointer to AdbmsAfeStorage 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

◆ adbms_afe_trigger_board_temp_conv()

StatusCode adbms_afe_trigger_board_temp_conv ( AdbmsAfeStorage afe,
uint8_t  device_num 
)

Triggers ADC conversion for the specified board temperature thermistor input.

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

Parameters
afePointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE
device_numTarget device number
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

◆ adbms_afe_trigger_cell_conv()

StatusCode adbms_afe_trigger_cell_conv ( AdbmsAfeStorage 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 AdbmsAfeStorage 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

◆ adbms_afe_trigger_thermistor_conv()

StatusCode adbms_afe_trigger_thermistor_conv ( AdbmsAfeStorage afe,
uint8_t  device_num,
uint8_t  thermistor_index 
)

Triggers ADC conversion for the specified thermistor voltage inputs.

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

Parameters
afePointer to AdbmsAfeStorage struct, stores runtime data and settings of AFE
device_numTarget device number
thermistor_indexThermistor index between 0-16
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

◆ adbms_afe_write_config()

StatusCode adbms_afe_write_config ( AdbmsAfeStorage afe)

Writes configuration bits onto CFGR (Configuration Register Group)

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

Parameters
afePointer to AdbmsAfeStorage 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

◆ 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