Hi
I have a strange behavior of my code depending on a place where my variables are defined.
Example 1: I have a variable called defined as: int conversion_count=0;
It is used to count each ADC conversion. If this variable is defined at top of my code outside the ADC ISR it is working fine, but if it is defined inside the ADC_ISR it is not working. Why?
Code example:
DATA_array[conversion_count] = AdcRegs.ADCRESULT0 >>4;
if(conversion_count == 99)
{
conversion_count = 0;
}
else conversion_count++;
Example 2: a different situation is with another variable defined as: int average = 1;
It is used to collect a number of samples to calculate an average
When it is defined inside the ADC ISR everything works fine, but it it is defined outside, it doesn't work well. Why
Code example:
if (average == 3) // average of 3 samples
{
DATA = ( DATA_array[conversion_count] +
DATA_array[conversion_count-1] +
DATA_array[conversion_count-2])/average;
}
else average++;
So to summarize two similar situations - one work if the variable is defined outside the ADC ISR, another works when the variable is defined inside the ADC ISR. Why?
Thanks