![]() |
Midnight Sun Firmware
|
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... | |
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... | |
LTC6811 library.
#define LTC6811_ADAX_GPIO1 0x01 |
ADAX command macros.
Select GPIO 1 for ADC Conversion
#define LTC6811_ADAX_GPIO4 0x04 |
Select GPIO 4 for ADC Conversion
#define LTC6811_ADAX_MODE_FAST (0 << 8) | (1 << 7) |
Select fast ADC mode
#define LTC6811_ADAX_RESERVED (1 << 10) | (1 << 6) | (1 << 5) |
Start GPIOs ADC Conversion and Poll Status
#define LTC6811_ADCV_DISCHARGE_NOT_PERMITTED (0 << 4) |
ADCV discharge permission macros.
Determines if cell discharge is permitted during ADCV commands.
#define LTC6811_ADCV_RESERVED ((1 << 9) | (1 << 6) | (1 << 5)) |
Start Cell Voltage ADC Conversion and Poll Status
#define LTC6811_ADOW_RESERVED ((1 << 3) | (1 << 5) | (1 << 9)) |
Start Open Wire ADC Conversion and Poll Status
#define LTC6811_CLRAUX_RESERVED (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Clear Auxillary Register Groups
#define LTC6811_CLRCELL_RESERVED (1 << 0) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Clear Cell Voltage Register Groups
#define LTC6811_CLRSTAT_RESERVED (1 << 0) | (1 << 1) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Clear Status Register Groups
#define LTC6811_CNVT_CELL_1_7 0x01 |
Convert cells 1 and 7.
#define LTC6811_CNVT_CELL_2_8 0x02 |
Convert cells 2 and 8.
#define LTC6811_CNVT_CELL_3_9 0x03 |
Convert cells 3 and 9.
#define LTC6811_CNVT_CELL_4_10 0x04 |
Convert cells 4 and 10.
#define LTC6811_CNVT_CELL_5_11 0x05 |
Convert cells 5 and 11.
#define LTC6811_CNVT_CELL_6_12 0x06 |
Convert cells 6 and 12.
#define LTC6811_CNVT_CELL_ALL 0x00 |
ADCV command macros for cell conversion.
Determines which cells to convert during ADCV commands. Convert all cells.
#define LTC6811_CVST_RESERVED ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 9)) |
Start Self Test Cell Voltage Conversion and Poll Status
#define LTC6811_DIAGN_RESERVED (1 << 0) | (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Diagnose MUX and Poll Status
#define LTC6811_FCOM_CSBM_HIGH (1 << 3) | (1 << 0) |
Transitions CSBM high at end of transmission
#define LTC6811_FCOM_CSBM_LOW (0 << 0) |
Write Codes for FCOMn (n = 1, 2, 3)
Holds CSBM low at end of transmission
#define LTC6811_GPIO1_PD_ON (0 << 3) |
GPIO pull-down configuration for the Config Register Group.
LtcAfeConfigRegisterData
struct for details. #define LTC6811_ICOM_CSBM_FALL_EDGE (1 << 3) | (1 << 0) |
CSBM high then low signal
#define LTC6811_ICOM_CSBM_HIGH (1 << 3) | (1 << 1) |
CSBM high signal
#define LTC6811_ICOM_CSBM_LOW (1 << 3) |
Write Codes for ICOMn (n = 1, 2, 3)
CSBM low signal
#define LTC6811_ICOM_NO_TRANSMIT (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0) |
No Data is tranmitted
#define LTC6811_PLADC_RESERVED (1 << 2) | (1 << 4) | (1 << 8) | (1 << 9) | (1 << 10) |
Poll ADC Conversion Status
#define LTC6811_PWMC_DC_100 (0xF) |
PWM duty cycle configuration (100%).
#define LTC6811_RDAUXA_RESERVED ((1 << 3) | (1 << 2)) |
Read Auxillary Reg Group A
#define LTC6811_RDAUXB_RESERVED ((1 << 3) | (1 << 2)) | (1 << 1) |
Read Auxillary Reg Group B
#define LTC6811_RDCFG_RESERVED (1 << 1) |
Read Config Reg Group A
#define LTC6811_RDCOMM_RESERVED (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10) |
Read COMM Register Group
#define LTC6811_RDCVA_RESERVED (1 << 2) |
Read Cell Voltage Reg Group A
#define LTC6811_RDCVB_RESERVED (1 << 2) | (1 << 1) |
Read Cell Voltage Reg Group B
#define LTC6811_RDCVC_RESERVED (1 << 3) |
Read Cell Voltage Reg Group C
#define LTC6811_RDCVD_RESERVED (1 << 3) | (1 << 1) |
Read Cell Voltage Reg Group D
#define LTC6811_RDPWM_RESERVED (1 << 5) | (1 << 2) |
Read PWM Register Group
#define LTC6811_RDSTATA_RESERVED (1 << 4) |
Read Status Register Group A
#define LTC6811_RDSTATB_RESERVED (1 << 4) | (1 << 1) |
Read Status Register Group B
#define LTC6811_WRCFG_RESERVED (1 << 0) |
Command codes for LTC6811 AFE.
See Table 38 (p.59) Write Config Reg Group A
#define LTC6811_WRCOMM_RESERVED (1 << 0) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10) |
Write COMM Register Group
#define LTC6811_WRPWM_RESERVED (1 << 5) |
Write PWM Register Group
#define LTC_AFE_MAX_CELLS_PER_DEVICE 12 |
Maximum x of each device.
#define LTC_AFE_MAX_DEVICES 3 |
Maximum AFE devices in daisy chain config.
typedef struct LtcAfeSettings 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
SpiSettings
refer to spi.h
typedef struct LtcAfeStorage LtcAfeStorage |
Runtime Data Storage.
Stores settings, configs, and voltages for all AFE devices
0
corresponds to the first cell/aux value of the first AFE device.n * max_x_per_device
corresponds to the first value of the (n+1)th AFE device.enum LtcAfeAdcMode |
Discharge timeout options for the AFE.
See Table 52 on Page 65 for more details
enum LtcAfeRegister |
List of LTC AFE registers.
These registers are mapped to the s_read_reg[]
array in ltc_afe.c
uint16_t crc15_calculate | ( | uint8_t * | data, |
size_t | len | ||
) |
Calculates CRC15 PEC value for given data.
data | the data to calculate the PEC for |
len | length of the data |
void crc15_init_table | ( | void | ) |
Initiliaze the CRC15 table for PEC.
Used for fast CRC15 lookups
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
afe | Pointer to LtcAfeStorage struct, stores runtime data and settings of AFE |
config | Pointer to constant LtcAfeSettings struct, contains user-specified configuration parameters |
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
afe | Pointer to LtcAfeStorage struct, stores runtime data and settings of AFE |
device_cell | The GPIO port we want to read from |
prv_read_register
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
afe | Pointer to LtcAfeStorage struct, stores runtime data and settings of AFE |
prv_read_register
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.
afe | Pointer to LtcAfeStorage struct containing runtime data and settings |
duty_cycle | 4-bit duty cycle value (0x0 to 0xF) to set for all PWM channels |
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.
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
afe | Pointer to LtcAfeStorage struct, stores runtime data and settings of AFE |
cell | Index of cell at device x (cell = cell # in device + (# of cells * device_number)) |
discharge | Is cell being discharged or not? |
cell
index is invalid 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.
afe | Pointer to LtcAfeStorage struct containing runtime data and settings |
thermistor | Index of the thermistor to measure (0-7 across devices) |
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.
afe | Pointer to LtcAfeStorage struct containing runtime data and settings |
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
afe | Pointer to LtcAfeStorage struct, stores runtime data and settings of AFE |
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