Chat freely about anything...

User avatar
By xjn
#92263 Hello,

using an ESP8266, I have the following code

Code: Select all#include <Arduino.h>

#define TST_PIN     4

//  gpio pin to HIGH
#define High_x1() \
    GPOS = (1 << TST_PIN)

//  gpio pin to LOW
#define Low_x1() \
    GPOC = (1 << TST_PIN)

//
#define High_x10() \
    High_x1(); \
    High_x1(); \
    High_x1(); \
    High_x1(); \
    High_x1(); \
    High_x1(); \
    High_x1(); \
    High_x1(); \
    High_x1(); \
    High_x1()

//
#define High_x100() \
    High_x10(); \
    High_x10(); \
    High_x10(); \
    High_x10(); \
    High_x10(); \
    High_x10(); \
    High_x10(); \
    High_x10(); \
    High_x10(); \
    High_x10()

//  ----
//
IRAM_ATTR void xjnRun()
{
    cli();
    High_x100();
    Low_x1();
    sei();
}

//  ----
//
void setup()
{
    pinMode(TST_PIN, OUTPUT);
}

//  ----
//
void loop()
{
    xjnRun();
}




This sets the GPIO testpin 100 times to HIGH and then one time to LOW.
The 100 times repeat, because my Logic Analyzer has only 24MS/s sampling rate.
In the assembly listing the 100 times pin set to HIGH are there ...


At 80MHz CPU frequency I measured a high period of about 8.75 µs.

At 160MHz CPU frequency I measured a high period of about 7.5 µs.


I would expect that measuring a high period for 160MHz CPU is half the period
of 80MHz CPU setting.
This is not the case and I have no idea why.

Could anyone explain this to me ?


br
xjn
User avatar
By eriksl
#92314 It's very simple. I/O pins run on the APB (the "advanced peripheral bus") and not directly on the CPU. The APB always runs on 80 MHz, also when the CPU is set to 160 MHz.

Asides from that, the GPIO subsystem isn't very fast anyway. If you think you can toggle a pin at say 10 MHz, you are going to be disappointed. If you want fast transitions of an I/O pin, you'd better look for ways to "use" the UART or the I2S subsystem.
User avatar
By xjn
#92316 Thx,

> It's very simple. I/O pins run on the APB (the "advanced peripheral bus") and not directly on the CPU.
> The APB always runs on 80 MHz, also when the CPU is set to 160 MHz.

so GPIO operations on ESP8266 always run/are synchronized at 80Mhz ?

And the faster GPIO on 160MHz I measured, is due to faster instruction cycles for faster
CPU frequency ?

Is this the same for ESP32 ?


I wasn't aware of APB (the "advanced peripheral bus"),
I'll now read the manual for the topic ...


br
xjn
User avatar
By btidey
#92317 I agree that as suggested using i2s is a good way of doing really fast toggling but one can get reasonably fast control using program.

I did a quick test and got more like 100nS periods which is consistent with the speed of the GPIO bus.

6.jpg


Code: Select all//test

void setup() {
   pinMode(4,OUTPUT);
}
int i;   
void loop() {
   for(i=0; i < 1000; i++) {
      GPOS = 16;
      GPOC = 16;
      GPOS = 16;
      GPOC = 16;
      GPOS = 16;
      GPOC = 16;
      GPOS = 16;
      GPOC = 16;
      GPOS = 16;
      GPOC = 16;
      GPOS = 16;
      GPOC = 16;
      GPOS = 16;
      GPOC = 16;
      GPOS = 16;
      GPOC = 16;
   }
}