interupt with timer and ADC to read signal

hi, im trying to read sine wave signal… i found this code by NickGammon. The code can display the sine wave signal but the sine is not smooth… how to make the adc interrupt read the signal precisely so we can calculate the phase angle of the graph. any idea to make adc read exactly the value of wave.

here the code and the result before

const byte adcPin = 0;
volatile int adcReading;
volatile boolean adcDone;
boolean adcStarted;
int xt=0;
void setup ()
{
  Serial.begin (115200);
  // set the analog reference (high two bits of ADMUX) and select the
  // channel (low 4 bits).  this also sets ADLAR (left-adjust result)
  // to 0 (the default).
  ADMUX = _BV (REFS0) | (adcPin & 0x07);

}  // end of setup

// ADC complete ISR
ISR (ADC_vect)
  {
  byte low, high;
  
  // we have to read ADCL first; doing so locks both ADCL
  // and ADCH until ADCH is read.  reading ADCL second would
  // cause the results of each conversion to be discarded,
  // as ADCL and ADCH would be locked when it completed.
  low = ADCL;
  high = ADCH;

  adcReading = (high << 8) | low;
  adcDone = true;  
  }  // end of ADC_vect
  
void loop ()
{
  // if last reading finished, process it
  if (adcDone)
    {
    adcStarted = false;

    // do something with the reading, for example, print it
  //  xt= ((adcReading*5)/1024);
    Serial.println (adcReading/4);
    delay (100);

    adcDone = false;
    }
    
  // if we aren't taking a reading, start a new one
  if (!adcStarted)
    {
    adcStarted = true;
    // start the conversion
    ADCSRA |= _BV (ADSC) | _BV (ADIE);
    }    
  
  // do other stuff here

}  // end of loop

Your sine wave looks "clipped", don't apply more voltage than arduino can handle. Try this: http://coolarduino.wordpress.com/2013/01/09/audio-vu-meter/

It is your hardware that is the problem not the software. What input circuit do you have?

ok Magician i will look at your link..

Grumpy_Mike, the output voltage to arduino pin0 is 2VAC, i also put voltage bias +2.5V.

2 V rms or 2 V peak to peak?

2 V rms or 2 V peak to peak?

2Vrms… it come from transformer after i step down to 2vac.

What you get is exactly right. It is what you should get. A voltage of 2V RMS is 5.6V peak to peak so you will see clipping top and bottom. You divide the reading by four so 255 will be the maximum you see, so what is the problem? If you want it not to clip then don't put so much voltage in. If you want the full range of the A/D then fon't divide it by four.

ooo...so the result i get is correct.. so i need to step down more the voltage input to get the smooth sine wave right? beside that any idea how can i calculate the frequency of the wave.

Yes a lower input. For frequency count the number of samples between successive peaks and multiply that by the sample interval. Then take the reciprocal of that number to give the frequency.