I am trying to acquire a sine wave signal generated by the AD9833 using a PIC's onboard high-speed ADC. Instead of acquiring the signal in real-time, I am using downsampling to build up a single sine wave cycle out of multiple cycles. For example, if the sine wave signal is 1000Hz, and my ADC is operating at 999 Samples/s, then after 999 samples I should have exactly one cycle of the signal. In other words, since the f_sampling and f_signal are slightly off, every sample captures a point on the sine wave slightly offset in phase compared to the previous point.

Anyway, getting predictable results relies heavily on synchronization. If the relative sampling frequency isn't exactly 0.999*signal frequency, then after 999 points I'll be significantly off, in that the phase of the first point won't match the phase of the last point.

So the problem should be solved by sharing a clock source, right? If I clock the ADC timer using the same clock source as the one that feeds the AD9833, then they should always be perfectly synchronized, right? Even if there is error and/or temperature variation in the clock source, it shouldn't matter.

The problem is that I am seeing non-synchronization error, so that I cannot predict how much of the sine wave I will capture (can't predict the ending phase relative to the starting phase). Are my assumptions about a shared clock source wrong, or does the problem lie elsewhere?

To put the question another way:

Let's assume I'm taking 999 samples, and I'm expecting exactly one sine wave period in the results, but I receive 1.3 periods. That doesn't mean my sampling frequency is 30% off. A signal frequency of 1000Hz has a period of 1ms, and a sampling frequency of 999Hz has a period of ~1.001ms. The difference between these two periods is 1microsecond. This is where the 30% error is. So if the difference between the periods is actually 1.3microseconds, then my sampling period is 1.0013ms, and the sampling period is 998.7Hz. This means I have a sampling frequency that's off by 0.03%.

Is less than 0.03% too much to ask from my hardware? I realize that the absolute sampling and signal frequencies will not be this accurate, but I was under the impression that the

ratioof the frequencies would be exact if the ADC and AD9833 shared the same clock source.