Author Topic: ESP 32 is fa.........st  (Read 4660 times)

0 Members and 1 Guest are viewing this topic.

Offline ebclrTopic starter

  • Super Contributor
  • ***
  • Posts: 2331
  • Country: 00
ESP 32 is fa.........st
« on: February 19, 2017, 02:31:31 pm »
Quick reply without calculating

What will be signal frequency on output5, on a standard esp32 board using Arduino and espressif


void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite( 5,HIGH );
//  delay(100);
  digitalWrite( 5,LOW );
//  delay(100);
}
 

Offline cowana

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: gb
Re: ESP 32 is fa.........st
« Reply #1 on: February 19, 2017, 02:48:19 pm »
No idea!

But if a 16MHz ATMEGA328 manages about 200kHz with the bloat of digitalWrite, I'd expect somewhere around 3MHz from an ESP32 running at 240MHz?
 

Offline ebclrTopic starter

  • Super Contributor
  • ***
  • Posts: 2331
  • Country: 00
Re: ESP 32 is fa.........st
« Reply #2 on: February 19, 2017, 02:50:00 pm »
Amazing 3.65 Mhz
 

Offline daybyter

  • Frequent Contributor
  • **
  • Posts: 397
  • Country: de
Re: ESP 32 is fa.........st
« Reply #3 on: February 19, 2017, 09:50:08 pm »
How fast is analogRead ?
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 628
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: ESP 32 is fa.........st
« Reply #4 on: February 20, 2017, 12:33:57 am »
if a 16MHz ATMEGA328 manages about 200kHz with the bloat of digitalWrite,
Or, without the bloat...
Code: [Select]
.include "m328def.inc"
 ldi  r16,1<<5
 out  DDRB,r16
loop:
 out  PINB,R16
 rjmp loop
2.67MHz (3.33MHz @20MHz)
 
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3056
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: ESP 32 is fa.........st
« Reply #5 on: February 20, 2017, 01:40:29 am »
It's no secret that the pin operations in the Arduino main core are very bloated and slow.

Frustratingly it would be possible to refactor the functions (pinMode, digitalWrite, digitalRead...) a bit and use some GCC compile-time magic to make serious optimisation for constant (compile time known) arguments such that a digitalWrite or pinMode for example would be optimised down to a single sbi or cbi instruction, like I did for my ATTinyCore fork

But I think any such pull request on the main arduino core would probably languish in the pit of "oh but it might break [insert random thing that a developer happens to use] which was relying on the slowness".

~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline pancio

  • Contributor
  • Posts: 14
  • Country: pl
    • SystemEmbedded.eu
Re: ESP 32 is fa.........st ?
« Reply #6 on: October 17, 2024, 11:14:56 am »
Hi,

I've question regarding max possible frequency on ESP32 Wemos D32 Pro module...

I wrote very simple program (as a ESP-idf framework):

Code: [Select]
#include "driver/gpio.h"


#define LED 5

void app_main() {
    gpio_reset_pin(LED);
    gpio_set_direction(LED, GPIO_MODE_OUTPUT);
   
    while(1)
    {       
        gpio_set_level(LED, 1);
        gpio_set_level(LED, 0);
    }
}

and it's works perfect but so slow... I can't imagine that max frequency on GPIO is lower than 1.5MHz. The question is how to increase speed on GPIO?



Best Regards,
pancio

« Last Edit: October 17, 2024, 11:16:29 am by pancio »
SystemEmbedded.eu - Power without the price! :-)
 

Offline xvr

  • Frequent Contributor
  • **
  • Posts: 566
  • Country: ie
    • LinkedIn
Re: ESP 32 is fa.........st
« Reply #7 on: October 17, 2024, 01:15:32 pm »
Quote
The question is how to increase speed on GPIO?
Write directly to IO registers. gpio_set_level is wrapper around that write (you can extract it source from ESP-IDF). And quite fat wrapper :(
 

Offline wek

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: sk
Re: ESP 32 is fa.........st
« Reply #8 on: October 17, 2024, 01:17:54 pm »
Code: [Select]
esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level)
{
    GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO output gpio_num error", ESP_ERR_INVALID_ARG);
    gpio_hal_set_level(gpio_context.gpio_hal, gpio_num, level);
    return ESP_OK;
}

-->

#define gpio_hal_set_level(hal, gpio_num, level) gpio_ll_set_level((hal)->dev, gpio_num, level)

-->

__attribute__((always_inline))
static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t level)
{
    if (level) {
        if (gpio_num < 32) {
            hw->out_w1ts = (1 << gpio_num);
        } else {
            HAL_FORCE_MODIFY_U32_REG_FIELD(hw->out1_w1ts, data, (1 << (gpio_num - 32)));
        }
    } else {
        if (gpio_num < 32) {
            hw->out_w1tc = (1 << gpio_num);
        } else {
            HAL_FORCE_MODIFY_U32_REG_FIELD(hw->out1_w1tc, data, (1 << (gpio_num - 32)));
        }
    }
}
Try to look at disasm to see into how many instructions does this compile.

JW
 
The following users thanked this post: pancio

Offline agehall

  • Frequent Contributor
  • **
  • Posts: 390
  • Country: se
Re: ESP 32 is fa.........st
« Reply #9 on: October 17, 2024, 03:07:08 pm »
I mean, if you want fast, don’t use Arduino.
 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 4734
  • Country: nl
Re: ESP 32 is fa.........st ?
« Reply #10 on: October 17, 2024, 05:48:53 pm »
and it's works perfect but so slow... I can't imagine that max frequency on GPIO is lower than 1.5MHz. The question is how to increase speed on GPIO?

I'm not familiar with ESP32 and it's framework, but might it be that the core clock is low?

This will also result in slow toggling of the IO.

Your code does not show any setup of the hardware, so no way to know about if the speed is increase able or not.

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 28502
  • Country: nl
    • NCT Developments
Re: ESP 32 is fa.........st
« Reply #11 on: October 17, 2024, 06:41:49 pm »
There are quite a few layers of software between hardware and application layer. However, there is a hardware manual describing the registers so controlling the hardware registers directly is definitely possible and should increase speed considerably.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline pancio

  • Contributor
  • Posts: 14
  • Country: pl
    • SystemEmbedded.eu
Re: ESP 32 is fa.........st
« Reply #12 on: October 18, 2024, 07:28:35 am »
Thanks @All for answer.

I thought that so short program which not using any additional layer e.g. FreeRTOS shall be compiled with some kind of optimization. Moreover - it was compiled under ESP-IDF delivered by ESP. I'm not familiar with Arduino, so I tried to do it as simply as possible. Ok, I'll try to do it directly using register as proposed by @wek :-)

According HW and clock... I'm using WEMOS D32 PRO (LOLIN) module and I suppose it's working with  default configuration - suppose it's 240MHz. I haven't any additional configuration in my project. I'm working on Linux, VSC and PlatformiO with newest libraries.     
« Last Edit: October 18, 2024, 07:35:21 am by pancio »
SystemEmbedded.eu - Power without the price! :-)
 

Offline glenenglish

  • Frequent Contributor
  • **
  • Posts: 473
  • Country: au
  • RF engineer. AI6UM / VK1XX . Aviation pilot. MTBr
Re: ESP 32 is fa.........st
« Reply #13 on: October 18, 2024, 07:17:10 pm »
As usual, an 8 MHz AVR can beat a ESP32 on toggle for all the reasons outlined above.
ESP32 are a good option for those more familiar with high level machines , but is not suited to being a low level down and dirty better controller because of ll the abstraction.
Beware, some of the GPIOs because of the way they are driven, are subject to glitches. That's in the tech manual, avoid those for specific uses....
 
The following users thanked this post: pancio

Offline tooki

  • Super Contributor
  • ***
  • Posts: 13262
  • Country: ch
Re: ESP 32 is fa.........st
« Reply #14 on: October 18, 2024, 07:52:45 pm »
This is a mostly academic question, in that the ESP32 is known for not having fast GPIO toggling. But that’s because one isn’t supposed to rely on that for critical IO. The I2S/LCD interface, on the other hand, is intended for that, and supports much, much higher speeds.

Edit: And just to be clear, while the I2C/LCD interface is called that, it can be used for anything. I’ve seen it used for driving LED video wall modules, for example.
« Last Edit: October 19, 2024, 11:10:32 am by tooki »
 
The following users thanked this post: pancio

Offline pancio

  • Contributor
  • Posts: 14
  • Country: pl
    • SystemEmbedded.eu
Re: ESP 32 is fa.........st
« Reply #15 on: October 19, 2024, 11:04:36 am »
As usual, an 8 MHz AVR can beat a ESP32 on toggle for all the reasons outlined above.
ESP32 are a good option for those more familiar with high level machines , but is not suited to being a low level down and dirty better controller because of ll the abstraction.
Beware, some of the GPIOs because of the way they are driven, are subject to glitches. That's in the tech manual, avoid those for specific uses....

I released mentioned by you reasons... normally I'm using smaller uCs like CH32V003 or if I need more GPIOs V307 version. I tried to use ESP32 just for PoC to be sure it's possible to use it with projects which needs more power. It's for future use.
SystemEmbedded.eu - Power without the price! :-)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf