/******************************************************************************
  Function:
    void APP_ADC_Average ( void )

  Remarks:
    Called by the ADC ISR after "ADC_16SAMPLES_PER_INTERRUPT"
    (per MHC selection) have been acquired.
 */
void APP_ADC_Average ( void )
{
    int i;

    appData.dataReady = true;

    /* Must read results before clearing persistent interrupt flag. */
    for (i=0; i < ADC_NUM_SAMPLE_PER_AVERAGE; i++)
    {
        appData.potValue += PLIB_ADC_ResultGetByIndex(ADC_ID_1, i);
    }

    appData.potValue = appData.potValue / ADC_NUM_SAMPLE_PER_AVERAGE ;

    /* If the "Stop Conversion on the First ADC Interrupt?" box in MHC is checked,
       the Hardware will disable auto-sampling when the interrupt condition
       occurs (after obtaining the sixteenth result). Auto-sampling needs to be
       re-enabled every ADC interrupt. */
    PLIB_ADC_SampleAutoStartEnable(ADC_ID_1); 
}