ADC Sample rate

whemming
Posts: 10
Joined: Fri Feb 17, 2017 3:13 am

ADC Sample rate

Postby whemming » Fri Feb 17, 2017 3:57 pm

Anyone know the MAX ADC sample rate? I'm attempting to sample the ADC at 9600 sps, I'm using the analogRead(); function. Is there a faster way? Or is the ADC just too slow for this sample rate?

Thanks!

William

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ADC Sample rate

Postby kolban » Sat Feb 18, 2017 6:34 am

A post on this thread talking about ADC in connection with the ESP-IDF APIs mentions that the max sample frequency is 6KHz ... or a maximum sps of 6000. Do you have a project in mind that needs higher sample rates than that?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

whemming
Posts: 10
Joined: Fri Feb 17, 2017 3:13 am

Re: ADC Sample rate

Postby whemming » Sat Feb 18, 2017 7:24 pm

kolban wrote:A post on this thread talking about ADC in connection with the ESP-IDF APIs mentions that the max sample frequency is 6KHz ... or a maximum sps of 6000. Do you have a project in mind that needs higher sample rates than that?
I already found my answer in another thread. The other thread was asking about timers. I started this thread before I got the answer.

But yes I require a faster rate. I tested with an external ADC and the lowest sample rate that will work with my application is 9600. I am taking samples of AFSK1200. 8 samples per bit (1200 x 8) works well. I tried lowering my sampling to 6k, but I could not get reliable results. My application is a AFSK modem. For now I will continue to use the ESP-12E with external ADC/DAC, as its working well. I was just hoping the ESP32 would negate the need for the external chips. I never got around to testing the ESP32 DAC, is there any documentation on the DAC sample rate?

whemming
Posts: 10
Joined: Fri Feb 17, 2017 3:13 am

Re: ADC Sample rate

Postby whemming » Sat Feb 18, 2017 7:34 pm

I just read this post about the WiPy2 which is a ESP32 based python dev board. It states a 21.3k sps actual tested rate. So makes me thing the 6k rate is based on firmware, not hardware.

https://forum.pycom.io/topic/170/lopy-w ... formance/8

William

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: ADC Sample rate

Postby Hans Dorn » Tue Feb 21, 2017 2:28 am

FWIW, I see the following sample rates with analogRead:

ADC1: about 105,000 Samples/second (9.5µs per sample)
ADC2: about 87,000 Samples/second (11.5µs per sample)

Example code:

Code: Select all

// Get CPU cycle counter (240MHz)
uint32_t IRAM_ATTR cycles()
{
    uint32_t ccount;
    __asm__ __volatile__ ( "rsr     %0, ccount" : "=a" (ccount) );
    return ccount; 
}

void setup() {
  Serial.begin(115200);
}

#define SAMPLES 500
uint32_t t[SAMPLES];
uint32_t val[SAMPLES];

void loop() {
  int i;
  
  for(i=0; i<SAMPLES; i++)
  {
    t[i] = cycles();
    val[i] = analogRead(25);    
  }

  for(i=1; i<SAMPLES; i++)
  {
    Serial.print((t[i]-t[i-1]) / 240.0, 3); Serial.print(" "); Serial.println(val[i]);
  }
  delay(500);
}

The little sketch collects 500 samples + cycle counts into a buffer,
and then dumps the results to the console.

Seems to be plenty fast, you should give it a try :)

Cheers
Hans

whemming
Posts: 10
Joined: Fri Feb 17, 2017 3:13 am

Re: ADC Sample rate

Postby whemming » Tue Feb 21, 2017 8:24 pm

I think my issue was with the timer. Not sure why the first timer is off. I try your code when I get a chance.

This doesn't time correctly, does not trigger at 9600:

Code: Select all

 timer = timerBegin(3, 1, 1);
  timerAttachInterrupt(timer, &sample_isr, 1);
  timerAlarmWrite(timer, 13333, true);// 9600
  timerAlarmEnable(timer);
This works correctly, triggers correctly at 9600:

Code: Select all

 timer = timerBegin(3, 80, 1);
  timerAttachInterrupt(timer, &sample_isr, 1);
  timerAlarmWrite(timer, 104, true);// 9600
  timerAlarmEnable(timer);

Why does the timer not work when using divide by 1
?

I was not getting the correct 9600 samples using the divide by 1. So when I was told the limit was 6k, I gave up. Then in another project I discovered the timer issue. I will need to go back and try my original code with a different timer division.

What am I missing with these timer divisions?

William

whemming
Posts: 10
Joined: Fri Feb 17, 2017 3:13 am

Re: ADC Sample rate

Postby whemming » Tue Feb 21, 2017 8:36 pm

One other thing, in my testing it reveals the timer clock runs at 80Mhz, not the CPU clock of 240Mhz. Why is this?


William

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: ADC Sample rate

Postby Hans Dorn » Tue Feb 21, 2017 9:25 pm

Hi William,

the minimum timer divider seems to be 2. If you select a divider of 1, it gets changed to 2. The reason for this is probably somewhere in the hardware.

I also found that the alarm interrupt rate is 1 timer count slower than what you select, you have to use

timerAlarmWrite(timer, 103, true);

to get at 104µs


Cheers
Hans

P.S: I guess the CPU clock is a multiple (1x, 2x or 3x) of an internal 80MHz clock, that is also used for the timers.

whemming
Posts: 10
Joined: Fri Feb 17, 2017 3:13 am

Re: ADC Sample rate

Postby whemming » Wed Feb 22, 2017 1:22 am

Thanks! That was very helpful. I will run some test and report back.

Regards,

William

stephensworld
Posts: 4
Joined: Sat Sep 08, 2018 5:23 pm

Re: ADC Sample rate

Postby stephensworld » Sat Sep 08, 2018 5:27 pm

Hi all,

I would like to encode and decode AFSK1200 signals directly with ESP32.
Is there any progress?

Thank you very much.

Stephan

Who is online

Users browsing this forum: axellin and 14 guests