I am using atmega2560 to sample 50hz sine signal (at 1KHz) and plot it . The plot works fine when I print analog read function. I changed the code to take in 20 samples and then out of this loop print those 20 samples. To my surprise the wave is different from what I saw earlier. Why is it so? Snippet of my code below:
unsigned long curr, end;
void loop()
{
curr = micros();
if(curr - end >= 1000) // 1KHz sample
{
end = micros();
if(n<20)
{
value[n]=analogRead(analogInPin); //accumulate 20 samples - 20ms
n++;
}
else if (n==20) // plot samples after acquisition
{
for (n=0;n<20;n++)
{Serial.println(value[n]);} //Waveform in wierd
n=0;
}
}