-->
Page 1 of 2

What is maximum pulse count freq. in ESP8266 GPIOs?

PostPosted: Tue Dec 07, 2021 1:22 am
by mskamal1992
Hello,
I am trying to count the number of pulses via my GPIO interrupt.
My application requires an esp8266 to count the pulses of signal (50% duty cycle) maxed at 1MHz, however, I am able to get the number of counts up to 150-160KHz. I was wondering if this is the maximum I can get using esp8266, or there is something I can do to improve and achieve my target.
I am using the esp8266 module "esp-wroom-02", and tried compiling and flashing via PlatformIO & Arduino.
I also tried clocking CPU at 80MHz, and 160MHz, but with no luck.
My code is like this,

Code: Select all#define clockPin 13 //tried using other gpio like 14, 2 etc.
void setup()
{
  Serial.begin(115200, SERIAL_8N1); //tried using lower baud rates as well
  delay(100);
  Serial.println("Start");
attachInterrupt(clockPin, Clock_Interrupt_Handler, RISING);//tries using falling, low, high, but not change since it will double the count
}
uint32_t varTemp = 0;
void loop()
{
 Serial.println(varTemp);
varTemp = 0;
delay(100); //tried using less and more delay,
yield();//tried without using  it
}

void ICACHE_RAM_ATTR Clock_Interrupt_Handler()
{
//important to use few instruction cycles here
  varTemp++;
}



If I keep a signal generator on at a frequency greater than 160KHz, the controller gets busy in interrupt and after a few seconds, it gets reset (wdt). In order to avoid that I turn on/off the signal at regular intervals so that it does not get reset.

But even if my signal frequency is greater than 160KHz (say 500KHz or 1MHz), my count values still says (after revert calculations) that frequency is 150-160KHz.

Can esp8266 only count up to that frequency? Or is there a way to count pulses at 1MHz or greater?

Re: What is maximum pulse count freq. in ESP8266 GPIOs?

PostPosted: Tue Dec 07, 2021 6:58 pm
by davydnorris
This may be an Arduino limitation but I'm not an Arduino expert and I don't know how they wrap interrupts.

You could also try running the ESP at 160MHz instead - it has two clock speeds.

Other than that you may need to use a dedicated counter circuit

Re: What is maximum pulse count freq. in ESP8266 GPIOs?

PostPosted: Wed Dec 15, 2021 12:05 am
by jsmwrench
davydnorris,

How do you change the ESP8266 to 160MHz? I've been looking for this information for hours!

Ron.

Re: What is maximum pulse count freq. in ESP8266 GPIOs?

PostPosted: Wed Dec 15, 2021 5:53 am
by QuickFix
In Arduino it can be set under the "Tools" -> "CPU Frequency" option:
ESP_CPU_Freq.png