void current_UpdateAvg ( void   )

This function reads the momentary motor current draw and uses this value to store it in the mg_au16AvgData array for futher calculations. The frequency of calling this function and the size of the mg_au16AvgData array define the span of time used for calculating the average motor current.

An example: AVG_COUNT = 8 and calling current_UpdateSum() every 128ms (see application loop in main()) results in a time span of 1.024s.

See also:
mg_au16AvgData
AVG_COUNT
Returns:
void

Definition at line 241 of file current.c.

References ADC_CURRENT, adc_Read(), AVG_COUNT, mg_au16AvgData, and mg_u8AvgIdx.

Referenced by main().

{
  /* get momentary current value */
  UINT16 u16Help = adc_Read(ADC_CURRENT);
  
  /* insert in ring array */
  mg_au16AvgData[mg_u8AvgIdx] = u16Help;
  mg_u8AvgIdx++;
  if(mg_u8AvgIdx >= AVG_COUNT)
  {
    mg_u8AvgIdx = 0U;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function: