Direct GPIO pin toggling at different CPU frequencies
Posted: Wed Sep 08, 2021 12:54 pm
Hello,
using an ESP8266, I have the following code
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
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