ADuC831 variable corruption issue in ISR

I have a customer running into a variable corruption issue on a ADuC831 while in an ISR.   See below for the details and question.

We’re using an ADuC831 microconverter to control an LED based backlight solution via a PWM signal.  We vary the width of the PWM pulse based on a 5V analog line input that we’re currently oversampling with the ADC and then decimating.  All of this activity is scheduled on a VSync pulse we receive on the INT0 input.

 

Our problem is this: occasionally, the variable I’m storing the aggregation of ADC samples is getting corrupted by the uConverter.  This is throwing off the PWM value and thus causing our backlight to flash.  I’ve attached the ADCI ISR that handles the oversampling/decimation and the loop that controls its execution.  Can you spot where/why the variable “dimResult” is getting corrupted?

Thanks,

AK

codesnippet.txt.zip