ADC samples half frequency
When you toggle a pin at a certain rate, the resulting waveform will have a frequency at half of the toggle rate.  So if your output waveform was a 8kHz square wave, then your ADC sample rate is actually 16kHz, which explains the factor of 2 error.