Hi,
The design of my firmware to handle reading of battery data is highly relied on the alert signal which could be triggered by CC_READY, or fault of bqOV, bqUV, bqSCD, bqOCD etc..
Detection of triggering of the signal is handled in an input interrupt routine like below,
//port1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void isr_port_1(void)
{
if (P1IFG & BIT5)
{
P1IFG &= ~BIT5; // clear interrupt flag
bqAlert=TRUE; <== !!!!!!!!!!!!!!!!!!!!!!!!
}
}
In a task the reading of data is carrying out if the "bqAlert" flag is set, like below code,
void taskA(void)
{
uint8_t i;
static uint16_t time_out_counter=0;
time_out_counter++;
if (bqAlert==TRUE) <==!!!!!!!!!!!!!!!!!!!!!!!!
{
bqAlert=FALSE; <==!!!!!!!!!!!!!!!!!!!!!!!!!
bqI2CError = NO_SIGNIFICANCE;
bqStatus.StatusByte = BqGetRegisterByte(SYS_STAT); <==!!!!!!!!!!!
bqI2CStatusReadError = bqI2CError;
BqSetRegisterByte(SYS_STAT, STAT_CC_READY); <==!!!!!!!!!!!!!!!!!!!!!!!!!
if(bqI2CStatusReadError == FALSE || time_out_counter > 500)
{
if (bqStatus.StatusBit.DEVICE_XREADY == TRUE)
{
//for this fault data can not be trusted
fault.BQ.bit.XREADY = TRUE;
}
else
{
fault.BQ.bit.XREADY = FALSE;
// 250ms cycle completed
if(bqStatus.StatusBit.CC_READY == TRUE) <==!!!!!!!!!!!!!!!!!!!!!
{
// read Coulomb counter
//int32_t cur;
float_t cur;
int16_t tmp;
tmp = BqGetCoulombCounter();
if(bqI2CError == FALSE)
{
if (tmp>=0)
bqCoulomb = tmp+1;
else
bqCoulomb = tmp;//-1;
.. etc.
}
else
{
//i2C error
fault.BQ.bit.i2c = TRUE;
}
// read cell voltage
uint16_t min=65535, max=0;
for(i=0; i<NUMBER_OF_CELLS;i++)
{
tmp = BqGetCellVoltage(i+1);
if (bqI2CError == FALSE)
{
RAM_Volt_Cell[i] =(uint16_t) gain2*tmp;
//RAM_Volt_Cell[i] = tmp;
if (RAM_Volt_Cell[i]<min)
{
min=RAM_Volt_Cell[i];
LowestCellIndex = i;
}
if (RAM_Volt_Cell[i]>max)
max=RAM_Volt_Cell[i];
}
else...
The interesting thing is happening if there is bqOV/bqUV event on, the alert signal will not generate any more, thus the battery data can not be read out,
Since recovery of such events rely on the continuous reading of battery data, like below
static void fault_bq_uv_recovery_routine(void)
{
fault.delayCounter_1++;
if(fault.delayCounter_1 > (5*ONE_SECOND)) //20s
{
fault.delayCounter_1 = (5*ONE_SECOND) + 1; //keep in
fault.delayCounter_2++;
if(fault.delayCounter_2 > (5*ONE_SECOND))
{
if(RAM_LowestVolt>=thresholds[CUV_RECOVERY_THRESHOLD]) <========!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
//criteria matched,clear faults
fault.BQ.byte = 0x00;
fault.SYS.byte = 0x00;
BqSetRegisterByte(SYS_STAT, STAT_FLAGS); //clear faults and alert
logic.regbyte_sys_ctrl2.SysCtrl2Byte = BqGetRegisterByte(SYS_CTRL2);
//close FETs
logic.regbyte_sys_ctrl2.SysCtrl2Bit.DSG_ON = TRUE;
logic.regbyte_sys_ctrl2.SysCtrl2Bit.CHG_ON = TRUE;
BqSetRegisterByte(SYS_CTRL2, logic.regbyte_sys_ctrl2.SysCtrl2Byte); //turn on FETs on bq uv recovery
fault.delayCounter_1 = 0;
fault.delayCounter_2 = 5*ONE_SECOND;
}
else
{
fault.delayCounter_2 = 0;
}
}
}
}
I would like to know how the ALERT signal is processed in the bq76940 when a fault enent like bqUV is on, and mixed with CC_READY event?
Best regard.