ADC Sample rate
ADC Sample rate
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
Thanks!
William
Re: ADC Sample rate
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
Re: ADC Sample rate
I already found my answer in another thread. The other thread was asking about timers. I started this thread before I got the answer.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?
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?
Re: ADC Sample rate
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
https://forum.pycom.io/topic/170/lopy-w ... formance/8
William
Re: ADC Sample rate
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:
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
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);
}
and then dumps the results to the console.
Seems to be plenty fast, you should give it a try
Cheers
Hans
Re: ADC Sample rate
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:
This works correctly, triggers correctly at 9600:
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
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);
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
Re: ADC Sample rate
One other thing, in my testing it reveals the timer clock runs at 80Mhz, not the CPU clock of 240Mhz. Why is this?
William
William
Re: ADC Sample rate
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.
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.
Re: ADC Sample rate
Thanks! That was very helpful. I will run some test and report back.
Regards,
William
Regards,
William
-
- Posts: 4
- Joined: Sat Sep 08, 2018 5:23 pm
Re: ADC Sample rate
Hi all,
I would like to encode and decode AFSK1200 signals directly with ESP32.
Is there any progress?
Thank you very much.
Stephan
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: No registered users and 41 guests