I have connected a sine wave of amplitude 3V with 1.5V shifted above the zero to 12-bit ADC channel by using dsPIC33FJ32MC204 controller and stored in an array. I want to detect the peak for each interval, so please give me any suggestion on it. I have just posted my logic for max value detection out of five samples. I am getting output as a zero.
void read_adc_Voltage()
{
int arr[100];
int arr1[100];
int max = arr[0];
arr[0]=0;
int i,j=0;
int count = 6;
for (i=1;i<count;i++)
{
var=(ain1Buff[sampleCounter]);
voltage=var*((float)3.3/(float)4095);
arr[j] = voltage;
if(arr[j] > max)
{
max = arr[j];
}
j++;
}
sprintf(data1,"%.2f",max);
LCD_String_xy(1,1,data1);
sampleCounter++;
if(sampleCounter==6)
{
sampleCounter=0;
}
}