Data Structures | Defines | Typedefs | Enumerations | Functions | Variables

# bq_pack.h File Reference

this file contains all the definitions of the BQ76PL536 devices More...

`#include "data_flash.h"`

Go to the source code of this file.

## Data Structures
struct | CELL_DATA
struct | BQ_DEV
struct | BQ_PACK
## Defines
#define | IN_HOST_CHG_OP BIT0
| BQ pack signals defines .
#define | BQ76PL536_OUTPUTS_VECTOR PORT1_VECTOR
| *BQ76PL536 to MSP430 signals defines*/
#define | BQ76PL536_OUTPUTS_PxIV P1IV
#define | BQ76PL536_CONV_PxIN P1IN
#define | BQ76PL536_CONV_PxOUT P1OUT
#define | BQ76PL536_CONV_PxDIR P1DIR
#define | BQ76PL536_CONV_PxIFG P1IFG
#define | BQ76PL536_CONV_PxIES P1IES
#define | BQ76PL536_CONV_PxIE P1IE
#define | BQ76PL536_CONV_PxSEL P1SEL
#define | BQ76PL536_CONV_PxREN P1REN
#define | OUT_BQ_CONV BIT4
#define | BQ76PL536_LED_PxIN P1IN
#define | BQ76PL536_LED_PxOUT P1OUT
#define | BQ76PL536_LED_PxDIR P1DIR
#define | BQ76PL536_LED_PxIFG P1IFG
#define | BQ76PL536_LED_PxIES P1IES
#define | BQ76PL536_LED_PxIE P1IE
#define | BQ76PL536_LED_PxSEL P1SEL
#define | BQ76PL536_LED_PxREN P1REN
#define | OUT_BQ_LED BIT0
#define | BQ76PL536_DRDY_PxIV P1IV
#define | BQ76PL536_DRDY_PxIN P1IN
#define | BQ76PL536_DRDY_PxOUT P1OUT
#define | BQ76PL536_DRDY_PxDIR P1DIR
#define | BQ76PL536_DRDY_PxIFG P1IFG
#define | BQ76PL536_DRDY_PxIES P1IES
#define | BQ76PL536_DRDY_PxIE P1IE
#define | BQ76PL536_DRDY_PxSEL P1SEL
#define | BQ76PL536_DRDY_PxREN P1REN
#define | BQ76PL536_ALERT_PxIN P1IN
#define | BQ76PL536_ALERT_PxOUT P1OUT
#define | BQ76PL536_ALERT_PxDIR P1DIR
#define | BQ76PL536_ALERT_PxIFG P1IFG
#define | BQ76PL536_ALERT_PxIES P1IES
#define | BQ76PL536_ALERT_PxIE P1IE
#define | BQ76PL536_ALERT_PxSEL P1SEL
#define | BQ76PL536_ALERT_PxREN P1REN
#define | BQ76PL536_FAULT_PxIN P1IN
#define | BQ76PL536_FAULT_PxOUT P1OUT
#define | BQ76PL536_FAULT_PxDIR P1DIR
#define | BQ76PL536_FAULT_PxIFG P1IFG
#define | BQ76PL536_FAULT_PxIES P1IES
#define | BQ76PL536_FAULT_PxIE P1IE
#define | BQ76PL536_FAULT_PxSEL P1SEL
#define | BQ76PL536_FAULT_PxREN P1REN
#define | IN_BQ_DRDY BIT3
#define | IN_BQ_ALERT BIT2
#define | IN_BQ_FAULT BIT1
#define | ADC_CONTROL_VAL_6 ((1<<6)|(3<<4)|(0<<3)|(5<<0))
#define | ADC_CONTROL_VAL_5 ((1<<6)|(3<<4)|(0<<3)|(4<<0))
#define | ADC_CONTROL_VAL_4 ((1<<6)|(3<<4)|(0<<3)|(3<<0))
#define | IO_CONTROL_VAL ((0<<7)|(0<<6)|(0<<5)|(0<<2)|(0<<1)|(0<<0))
#define | CB_CTRL_VAL 0
#define | CB_TIME_VAL 0
#define | ADC_CONVERT_VAL (1<<0)
#define | SHDW_CTRL_ACCESS_EN_VAL 0x35
#define | SHDW_CTRL_REFRESH_EN_VAL 0x27
#define | E_EN_OTP_EN_VAL 0x91
#define | FUNC_CONFIG_VAL_6 ((0x1<<6)|(0<<5)|(0<<4)|(0x0<<2)|(0<<0))
#define | FUNC_CONFIG_VAL_5 ((0x1<<6)|(0<<5)|(0<<4)|(0x1<<2)|(0<<0))
#define | FUNC_CONFIG_VAL_4 ((0x1<<6)|(0<<5)|(0<<4)|(0x2<<2)|(0<<0))
#define | IO_CONFIG_VAL (0<<0)
#define | DISCARD_CRC (1)
#define | RETURN_CRC (0)
#define | CONFIG_COV_VAL (0<<7)
#define | CONFIG_COVT_VAL (1<<7)
#define | CONFIG_CUV_VAL (0<<7)
#define | CONFIG_CUVT_VAL (1<<7)
#define | CONFIG_OT_VAL (3<<4)
#define | CONFIG_OTT_VAL (200<<0)
#define | adc_step_mul 6250
#define | adc_step_div 16383
#define | BROADCAST_ADDR 0x3F
#define | DISCOVERY_ADDR 0x00
#define | BQ76PL536_RESET 0xa5
#define | FAULT_COV_POS 0
#define | FAULT_CUV_POS 1
#define | ALERT_OT1_POS 0
#define | ALERT_OT2_POS 1
#define | STATUS_ERROR_POT_COV BIT1
#define | STATUS_ERROR_CUV BIT2
#define | STATUS_ERROR_IMBALANCE_FAIL BIT3
#define | STATUS_ERROR_MAX_BALANCE_TIME BIT4
#define | START_END_OF_CHG_DSCHG_TIMER BIT0
#define | START_CHARGE_TAPER_TIMER BIT1
#define | START_CELL_BALANCE_TIMER BIT2
#define | START_CHG_DSCHG_OP_TIMER BIT3
#define | bq_dev_write_reg(a, b, c) spi_write_reg(a,(unsigned char)b,c)
#define | bq_dev_read_reg(a, b, c, d, e) spi_read_reg(a,(unsigned char)b,c,d,e)
## Typedefs
typedef enum BQ_DEV_REGS | bq_dev_regs_t
typedef struct CELL_DATA | cell_data_t
typedef struct BQ_DEV | bq_dev_t
typedef enum OP_MODES | op_modes_t
typedef struct BQ_PACK | bq_pack_t
## Enumerations
enum | BQ_DEV_REGS { DEVICE_STATUS_REG = 0x00, GPAI_L_REG = 0x01, GPAI_H_REG = 0x02, VCELL1_L_REG = 0x03, VCELL1_H_REG = 0x04, VCELL2_L_REG = 0x05, VCELL2_H_REG = 0x06, VCELL3_L_REG = 0x07, VCELL3_H_REG = 0x08, VCELL4_L_REG = 0x09, VCELL4_H_REG = 0x0a, VCELL5_L_REG = 0x0b, VCELL5_H_REG = 0x0c, VCELL6_L_REG = 0x0d, VCELL6_H_REG = 0x0e, TEMPERATURE1_L_REG = 0x0f, TEMPERATURE1_H_REG = 0x10, TEMPERATURE2_L_REG = 0x11, TEMPERATURE2_H_REG = 0x12, ALERT_STATUS_REG = 0x20, FAULT_STATUS_REG = 0x21, COV_FAULT_REG = 0x22, CUV_FAULT_REG = 0x23, PRESULT_A_REG = 0x24, PRESULT_B_REG = 0x25, ADC_CONTROL_REG = 0x30, IO_CONTROL_REG = 0x31, CB_CTRL_REG = 0x32, CB_TIME_REG = 0x33, ADC_CONVERT_REG = 0x34, SHDW_CTRL_REG = 0x3a, ADDRESS_CONTROL_REG = 0x3b, RESET_REG = 0x3c, TEST_SELECT_REG = 0x3d, E_EN_REG = 0x3F, FUNCTION_CONFIG_REG = 0x40, IO_CONFIG_REG = 0x41, CONFIG_COV_REG = 0x42, CONFIG_COVT_REG = 0x43, CONFIG_CUV_REG = 0x44, CONFIG_CUVT_REG = 0x45, CONFIG_OT_REG = 0x46, CONFIG_OTT_REG = 0x47, USER1_REG = 0x48, USER2_REG = 0x49, USER3_REG = 0x4A, USER4_REG = 0x4B, BQ_SPI_REG_MAX = 0x4F }
enum | OP_MODES { INITIAL_MODE = 0, CHARGE_OP, END_OF_CHARGE, DISCHARGE_OP, END_OF_DISCHARGE, FAULT_MODE, SOV_MODE }
## Functions
short | bq_pack_address_discovery (void)
| Function Name: bq_pack_address_discovery .
short | bq_pack_init (void)
| Function Name: bq_pack_init.
void | update_bq_pack_data (void)
| Function Name: update_bq_pack_data.
void | BatteryPackManager (void)
| Function Name: BatteryPackManager .
void | bq_pack_start_conv (void)
| Function Name: bq_pack_start_conv .
unsigned short | get_bq_pack_voltage (void)
| Function Name: get_bq_pack_voltage.
unsigned short | get_bq_pack_timer (void)
| Function Name: get_bq_pack_timer.
void | update_bq_pack_timer (void)
| Function Name: update_bq_pack_timer .
op_modes_t | get_bq_pack_mode (void)
| Function Name: get_bq_pack_mode .
void | set_bq_pack_mode (op_modes_t mode)
void | CheckFaultConditions (void)
| Function Name: CheckFaultConditions.
unsigned short | find_imbalanced_cell (unsigned short bq_pack_id)
| Function Name: find_imbalanced_cell .
void | conf_bq_dev (bq_dev_t *this)
| Function Name: conf_bq_dev .
void | init_bq_dev_data_structure (bq_dev_t *this)
| Function Name: init_bq_dev_data_structure .
short | bq_dev_read_cell_voltage (bq_dev_t *this)
| Function Name: bq_dev_read_cell_voltage.
short | bq_dev_read_temps (bq_dev_t *this)
| Function Name: bq_dev_read_temps.
short | bq_dev_read_errors (bq_dev_t *this)
| Function Name: bq_dev_read_errors.
short | bq_dev_read_status (bq_dev_t *this)
| Function Name: bq_dev_read_status.
void | bq_dev_clear_alerts (bq_dev_t *this)
| Function Name: bq_dev_clear_alerts .
void | bq_dev_clear_faults (bq_dev_t *this)
| Function Name: bq_dev_clear_faults.
void | update_state_machine (op_modes_t new_mode)
short | check_for_cov (void)
| Function Name: check_for_cov .
short | check_for_cuv (void)
| Function Name: check_for_cuv .
short | check_for_pot (void)
| Function Name: check_for_pot .
void | update_op_mode (op_modes_t new_mode)
| Function Name: update_op_mode .
void | copy_cell_voltage_values (void)
| Function Name: copy_cell_voltage_values.
unsigned short | check_for_discharge_op (void)
| Function Name: check_for_discharge_op .
unsigned short | check_for_charge_op (void)
| Function Name: check_for_charge_op.
void | CellBalancing (void)
| Function Name: CellBalancing.
void | CheckChargeDischargeModes (void)
| Function Name: CheckChargeDischargeModes.
void | CheckEndOfChargeOrDischargeModes (void)
| Function Name: CheckEndOfChargeOrDischargeModes .
void | enable_bypass_resistor (unsigned short in_dev_id, unsigned short in_value)
| Function Name: enable_bypass_resistor.
void | disable_bypass_resistor (unsigned short in_dev_id, unsigned short in_value)
| Function Name: disable_bypass_resistor.
void | disable_all_bypass_resistors (void)
| Function Name: disable_all_bypass_resistors.
unsigned short | cell_imbalance_threshold_reached (void)
| Function Name: cell_imbalance_threshold_reached .
## Variables
bq_pack_t | bq_pack
unsigned char | HOST_CONTROL_IN

## Detailed Description

this file contains all the definitions of the BQ76PL536 devices

Author:
  Texas Instruments, Inc

Date:
  November 2010

Version:
  1.0 Initial version

Note:
  Built with IAR for MSP430 Version: 5.10

Definition in file bq_pack.h.

## Define Documentation

#define IN_HOST_CHG_OP BIT0

BQ pack signals defines .

SW flag that controls the charge/discharge mode

Definition at line 77 of file bq_pack.h.

## Function Documentation

void BatteryPackManager | ( | void |  | ) |

Function Name: BatteryPackManager .

Description : Battery Manger Function.

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 472 of file bq_pack.c.

void bq_dev_clear_alerts | ( | bq_dev_t * | this | ) |

Function Name: bq_dev_clear_alerts .

Description : Clear the alert flags on the BQ device.

Parameters:

  | parameters | : specific device ID

Returns:
  Value : none

Definition at line 711 of file bq_pack.c.

void bq_dev_clear_faults | ( | bq_dev_t * | this | ) |

Function Name: bq_dev_clear_faults.

Description : Clears the fault flags on the BQ device.

Parameters:

  | parameters | : Device ID

Returns:
  Value : none

Definition at line 744 of file bq_pack.c.

short bq_dev_read_cell_voltage | ( | bq_dev_t * | this | ) |

Function Name: bq_dev_read_cell_voltage.

Description : reads the cell voltage on a specific BQ device.

Parameters:

  | parameters | : BQ device number in the stack

Returns:
  Value : returns the cell voltage read from the BQ device

Definition at line 676 of file bq_pack.c.

short bq_dev_read_errors | ( | bq_dev_t * | this | ) |

Function Name: bq_dev_read_errors.

Description : Reads the device status, alert status, fault status, COV status, CUV status registers.

Parameters:

  | parameters | : Device ID

Returns:
  Value : zero when the BQ device was read sucessfully

Definition at line 779 of file bq_pack.c.

short bq_dev_read_status | ( | bq_dev_t * | this | ) |

Function Name: bq_dev_read_status.

Description : reads the devoce status register.

Parameters:

  | parameters | : Device ID

Returns:
  Value : zero when the BQ device was read sucessfully

Definition at line 824 of file bq_pack.c.

short bq_dev_read_temps | ( | bq_dev_t * | this | ) |

Function Name: bq_dev_read_temps.

Description : reads the temperature registers.

Parameters:

  | parameters | : Device ID

Returns:
  Value : zero when the BQ device was read sucessfully

Definition at line 802 of file bq_pack.c.

short bq_pack_address_discovery | ( | void |  | ) |

Function Name: bq_pack_address_discovery .

Description : BQ Pack address discovery and assignement algorithm .

Parameters:

  | parameters | : void

Returns:
  Value : number of stacked BQ76PL536 devices

Definition at line 102 of file bq_pack.c.

short bq_pack_init | ( | void |  | ) |

Function Name: bq_pack_init.

Description : Configure each BQ device in the stack and initialize data structures for whole BQ stack .

Parameters:

  | parameters | : none

Returns:
  Value : return if there isn't problems while init the pack

Definition at line 164 of file bq_pack.c.

void bq_pack_start_conv | ( | void |  | ) |

Function Name: bq_pack_start_conv .

Description : triggers the ADC on the BQ devices.

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 262 of file bq_pack.c.

unsigned short cell_imbalance_threshold_reached | ( | void |  | ) |

Function Name: cell_imbalance_threshold_reached .

Description : Checks if the cell imbalance threshold is reached

Parameters:

  | parameters | : none

Returns:
  Value : 1 when the condition exist, 0 when it doesn't

Definition at line 1193 of file bq_pack.c.

void CellBalancing | ( | void |  | ) |

Function Name: CellBalancing.

Description : Identify the unbalanced cells and enables the bypass resistors to balance the cells while in charging mode .

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 338 of file bq_pack.c.

unsigned short check_for_charge_op | ( | void |  | ) |

Function Name: check_for_charge_op.

Description : Checks if the battery pack is in charge mode by checking if the cell voltages have increased.

Parameters:

  | parameters | : none

Returns:
  Value : 1 when the condition exist, 0 when it doesn't

Definition at line 1104 of file bq_pack.c.

short check_for_cov | ( | void |  | ) |

Function Name: check_for_cov .

Description : Checks for COV conditions.

Parameters:

  | parameters | : none

Returns:
  Value : 1 when the COV condition exist, 0 when it doesn't

Definition at line 992 of file bq_pack.c.

short check_for_cuv | ( | void |  | ) |

Function Name: check_for_cuv .

Description : Checks for CUV conditions.

Parameters:

  | parameters | : none

Returns:
  Value : 1 when the condition exist, 0 when it doesn't

Definition at line 1039 of file bq_pack.c.

unsigned short check_for_discharge_op | ( | void |  | ) |

Function Name: check_for_discharge_op .

Description : Checks if the battery pack is in discharge mode by checking if the cell voltages have decreased.

Parameters:

  | parameters | : none

Returns:
  Value : 1 when the condition exist, 0 when it doesn't

Definition at line 1137 of file bq_pack.c.

short check_for_pot | ( | void |  | ) |

Function Name: check_for_pot .

Description : Checks for POT conditions.

Parameters:

  | parameters | : none

Returns:
  Value : 1 when the condition exist, 0 when it doesn't

Definition at line 1085 of file bq_pack.c.

void CheckChargeDischargeModes | ( | void |  | ) |

Function Name: CheckChargeDischargeModes.

Description : Check if the pack is in charge or discharge mode.

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 303 of file bq_pack.c.

void CheckEndOfChargeOrDischargeModes | ( | void |  | ) |

Function Name: CheckEndOfChargeOrDischargeModes .

Description : Identifies if the pack is in end of charge or end of discharge modes .

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 448 of file bq_pack.c.

void CheckFaultConditions | ( | void |  | ) |

Function Name: CheckFaultConditions.

Description : Check fault conditions on the pack.

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 275 of file bq_pack.c.

void conf_bq_dev | ( | bq_dev_t * | this | ) |

Function Name: conf_bq_dev .

Description : configures each BQ76PL536 included in the stack.

Parameters:

  | parameters | : number of BQ device in the stack

Returns:
  Value : none

Definition at line 583 of file bq_pack.c.

void copy_cell_voltage_values | ( | void |  | ) |

Function Name: copy_cell_voltage_values.

Description : creates a backup of the last known cells voltages.

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 1169 of file bq_pack.c.

void disable_all_bypass_resistors | ( | void |  | ) |

Function Name: disable_all_bypass_resistors.

Description : disable all battery pack bypass resistors by controlling the CB outputs .

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 1279 of file bq_pack.c.

void disable_bypass_resistor | ( | unsigned short | in_dev_id,
|  | unsigned short | in_value |
| ) |  |  |

Function Name: disable_bypass_resistor.

Description : disable bypass resistors by controlling the CB outputs .

Parameters:

  | parameters | : Device ID, CB outputs to be controlled

Returns:
  Value : none

Definition at line 1256 of file bq_pack.c.

void enable_bypass_resistor | ( | unsigned short | in_dev_id,
|  | unsigned short | in_value |
| ) |  |  |

Function Name: enable_bypass_resistor.

Description : Enable bypass resistors by controlling the CB outputs.

Parameters:

  | parameters | : Device ID, CB outputs to be controlled

Returns:
  Value : none

Definition at line 1239 of file bq_pack.c.

unsigned short find_imbalanced_cell | ( | unsigned short | in_dev_id | ) |

Function Name: find_imbalanced_cell .

Description : finds the imbalanced cells.

Parameters:

  | parameters | : device ID

Returns:
  Value : Returns 0 if cells are balanced and other if there are any imbalanced cells .

Definition at line 1209 of file bq_pack.c.

op_modes_t get_bq_pack_mode | ( | void |  | ) |

Function Name: get_bq_pack_mode .

Description : returns current pack mode.

Parameters:

  | parameters | : none

Returns:
  Value : returns the current value of the mode

Definition at line 561 of file bq_pack.c.

unsigned short get_bq_pack_timer | ( | void |  | ) |

Function Name: get_bq_pack_timer.

Description : Returns BQ Pack time counter (for End of Charge or End of Discharge).

Parameters:

  | parameters | : none

Returns:
  Value : returns the last known value of the pack timer

Definition at line 502 of file bq_pack.c.

unsigned short get_bq_pack_voltage | ( | void |  | ) |

Function Name: get_bq_pack_voltage.

Description : Returns Pack voltage parameter.

Parameters:

  | parameters | : none

Returns:
  Value : returns last known pack voltage

Definition at line 490 of file bq_pack.c.

void init_bq_dev_data_structure | ( | bq_dev_t * | this | ) |

Function Name: init_bq_dev_data_structure .

Description : initializes the structure that stores the information of each BQ device .

Parameters:

  | parameters | : number of BQ device in the stack

Returns:
  Value : none

Definition at line 642 of file bq_pack.c.

void update_bq_pack_data | ( | void |  | ) |

Function Name: update_bq_pack_data.

Description : Reads data from BQ DEV registers and updates BQ PACK structure

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 207 of file bq_pack.c.

void update_bq_pack_timer | ( | void |  | ) |

Function Name: update_bq_pack_timer .

Description : update the multiple pack virtual timers.

Parameters:

  | parameters | : none

Returns:
  Value : none

Definition at line 513 of file bq_pack.c.

void update_op_mode | ( | op_modes_t | new_mode | ) |

Function Name: update_op_mode .

Description : updates the battery pack status.

Parameters:

  | parameters | : new operating mode

Returns:
  Value : none

Definition at line 837 of file bq_pack.c.