I found a bug in FFT example.
Because PIC hardware clears ADCON1.DONE after A/D conversion started, (not after sampling started),
this code
Code: Select all
function ReadAdc: word;
begin
ADCON1.1 := 1; // Start AD conversion
while ADCON1.0 = 0 do // Wait for ADC to finish
nop;
result := ADCBUF0; // Get ADC value
end;
Code: Select all
function ReadAdc: word;
begin
ADCON1.0 := 0; // Clear Done-Flag before sample start
ADCON1.1 := 1; // Start AD conversion
while ADCON1.0 = 0 do // Wait for ADC to finish
nop;
result := ADCBUF0; // Get ADC value
end;
Code: Select all
function ReadAdc: word;
begin
ADCON1.1 := 1; // Start AD conversion
while ADCON1.1 = 1 do nop; // Wait for finish Sampling
while ADCON1.0 = 0 do // Wait for ADC to finish
nop;
result := ADCBUF0; // Get ADC value
end;
Code: Select all
function ReadAdc: word;
begin
ADCON1.1 := 1; // Start AD conversion
while ADCON1.0 = 1 do nop; // Wait for ADC to start
while ADCON1.0 = 0 do // Wait for ADC to finish
nop;
result := ADCBUF0; // Get ADC value
end;