I want to transfer data from my smartphon to the Arduino by using the audio jack of my smartphone. For this I need verry high reading frequencys.
I have used
bitClear(ADCSRA,ADPS0);
bitSet(ADCSRA,ADPS1);
bitClear(ADCSRA,ADPS2);
to boost analogread to ~10microseconds, which would be enough. But somehow I am still wasting 5.4 ms at the beginning of the transmission.
The only thing between signal start and first analogread is a start of a for loop:
while(analogRead(A0)<50) (true); //wait for start of transmission
for(i = 0; i<500;i++){
data[i]=analogRead(A0);
}
But does starting a for loop take 5.4 ms? Do you have any ideas?
2 Answers 2
It sounds like you could benefit from interrupt handled free running sampling, doing that should get you sampling rates up to the maximum listed on the 328's datasheet, 76.9 kSPs. Although, that's at a reduced resolution. This site explains better, under the section "Free running sampling".
I did some further analysis on the signal and the problem was not the Arduino. It did everything quick and correct. The problem was my smartphone. I used androids AudioTrack class and somehow it did cut off parts of the signal. This could be "fixed" by increasing the length of the signal. I just added 0's at the beginning and end.
A normal conversion takes 13 ADC clock cycles. The first conversion after the ADC is switched on (ADEN in ADCSRA is set) takes 25 ADC clock cycles in order to initialize the analog circuitry.
. Try doing a dummy analogRead in the setup function.