void current_UpdateSum ( void   )

This function reads the momentary motor current draw and uses this value to recalculate the average current consumption. The new calculated value is stored in mg_u16Sum and is checked for an error condition. The frequency of calling this function and the size of the mg_au16Data array define the span of time used for calculating the motor current sum.

An example: SUM_COUNT = 20 and calling current_UpdateSum() every 512ms (see application loop in main()) results in a time span of 10.24s.

See also:
mg_au16Data
mg_u16Sum
COND_CURR_ERR
MAX_CURRENT
SUM_COUNT
Returns:
void

Definition at line 189 of file current.c.

References ADC_CURRENT, adc_Read(), COND_CURR_ERR, COND_CURR_WARN, MAX_CURRENT, mg_au16Data, mg_u16Sum, mg_u8SumIdx, safety_ClearCondition(), safety_SetCondition(), and SUM_COUNT.

Referenced by main().

{
  /* get momentary current value */
  UINT16 u16Help = adc_Read(ADC_CURRENT);
  
  /* insert in ring array */
  mg_au16Data[mg_u8SumIdx] = u16Help;
  mg_u8SumIdx++;
  if(mg_u8SumIdx >= SUM_COUNT)
  {
    mg_u8SumIdx = 0U;
  }
  
  /* recalculate new sum from array */
  u16Help = 0U;
  for(UINT8 i=0U; i<SUM_COUNT; i++)
  {
    u16Help += mg_au16Data[i];
  }
  mg_u16Sum = u16Help;
  
  /* check for current overload */
  if(mg_u16Sum > (MAX_CURRENT * SUM_COUNT))
  {
    safety_SetCondition(COND_CURR_ERR);
    safety_ClearCondition(COND_CURR_WARN);
  }
  else
  {
    safety_ClearCondition(COND_CURR_ERR);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function: