This function will be called every 512ms and reads the battery voltage and recalculates the average voltage value. The battery voltage will be read and stored in the ring array mg_au16Data at index mg_u8Idx. After this, the index position will be incremented. Finally the new average value will be calculated from all array values and stored in mg_u16Avg.
Definition at line 162 of file voltage.c. References adc_Read(), ADC_VOLTAGE, AVG_COUNT, COND_VOLT_ERR, mg_au16Data, mg_u16Avg, mg_u16Ref, mg_u8Idx, safety_ClearCondition(), and safety_SetCondition(). Referenced by main(). { UINT16 u16Help = adc_Read(ADC_VOLTAGE); /* insert voltage value in ring array */ mg_au16Data[mg_u8Idx] = u16Help; /* step to next position in array */ mg_u8Idx++; if(mg_u8Idx >= AVG_COUNT) { mg_u8Idx = 0U; } /* calculate new average value */ u16Help = 0U; for(UINT8 i=0U; i<AVG_COUNT; i++) { u16Help += mg_au16Data[i]; } u16Help /= AVG_COUNT; mg_u16Avg = u16Help; if(mg_u16Avg < mg_u16Ref) { safety_SetCondition(COND_VOLT_ERR); } else { safety_ClearCondition(COND_VOLT_ERR); } }
Here is the call graph for this function:
![]()
Here is the caller graph for this function:
![]() |