1

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?

| improve this question | | | | |
  • Before we spend any more time on this, what conversion speed/rate do you require? – Ignacio Vazquez-Abrams Jan 23 '15 at 3:24
  • Currently recieving a 40 bit packet takes about 10ms. I would consider 5ms a good value. – gorilla Jan 23 '15 at 11:14
  • An Instructable on audio sampling got 125us per sample using analogRead(), down to 26us per sample by bypassing analogRead, reading straight from the register, and clipping to 8-bit resolution. See sections 5 and 6. I suspect that's pretty much as fast as it gets. instructables.com/id/Arduino-Audio-Input/?ALLSTEPS – j-g-faustus Jan 23 '15 at 12:27
  • I am allready at 10us. But between seeing the first signal and saving the next signal 5.4 ms pass. – gorilla Jan 23 '15 at 12:56
  • So only the first cycle (i==0) takes 4.5ms, all the others (i>0) take 10uS? From the datasheet; 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. – Gerben Jan 23 '15 at 16:39
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".

| improve this answer | | | | |
1

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.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.