Pages: [1]   Go Down
Author Topic: How to get a faster analogRead() ?  (Read 111 times)
1 Member and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I just bought an Arduino Due. For my project I need to sample the signal as fast as possible using analogRead(). I have observed that without any changing, my Arduino Due takes about 5us for one analogRead().
Is it possible to even improve it (reduce the time it takes for one analogRead() ) ? And if so, how can we do it ? (a sample code would be nice).

  And by the way, I tried the following code from this link http://www.djerickson.com/arduino/  , but it did change nothing. The analogRead() still takes about 5us

 REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000;

The author of this page said that we can obtain a 500kHz ADC conversion. But I dont know how to achieve it.
Thanks a lot
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2557
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you gonna to do with data? Serial link isn't fast to transfer at high rate, and you 'd need to use DMA if SPI/I2C interface in perspective
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you gonna to do with data? Serial link isn't fast to transfer at high rate, and you 'd need to use DMA if SPI/I2C interface in perspective

Hi, I don't need to print the data to the Serial window. I need to sample the received signal and then process it. The received signal is an ultrasonic wave 40kHz. Currently my analogRead() is about 6us, which us about 166kHz. This sampling rate is not really ok for me, cause I need a high precision for my project.

Thanks
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2557
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

User in reply #5 of this thread http://forum.arduino.cc/index.php?topic=137635.0
reported 1MHz
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The received signal is an ultrasonic wave 40kHz. Currently my analogRead() is about 6us, which us about 166kHz. This sampling rate is not really ok for me, cause I need a high precision for my project.

Thanks
I'm not sure I follow you on this, for two reasons.
Firstly, if you are trying to capture the 40KHz carrier, then sampling at 80KHz will allow you to fully reconstruct the waveform (as per Nyquist, Shannon et al). You say you can sample at 166KHz which is double what you need. (Admittedly this may not leave you much time for any processing but that is another story.)
Secondly, you probably want to look at the modulated signal rather than the carrier. Typical uses of ultrasonic devices are motion detection and the like where the modulation is at a much lower frequency than the carrier. Here you have 2 options: firstly sample at twice the highest modulated frequency you are interested (and yes there may be some distortion from the carrier in this case but in this situation Nyquist is helping you). Alternatively you can demodulate the signal before you try to sample it - depending on the modulation used this can be trivial or a little more complex - and again sample the result at twice the maximum modulation frequency.
The advantage of the 2nd approach is to give you a lot more processing time to do something with the samples.
Trying to sample faster will not add precision to your result - only more samples that you need to process.
Susan
Logged

Pages: [1]   Go Up
Jump to: