Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ESP32S2 (S2FN4R2) and LEDC #7388

stef-ladefense started this conversation in General
Discussion options

Hi there
I have a few questions, remarks

  1. what is the minimum frequency of LEDC?
  2. what are the GPIOs of the S2 that support LEDC?

I work on 4 bits (so from 0 to 15), and the minimum frequency is 2500Hz, below that it doesn't work.
on the other hand in 8-bit mode, 1000Hz works well.
in the S2FN4R2 datasheet, it says PWM on all GPIOs, but it doesn't wo,rk on GPIO14, GPIO10.
work well 1, 6 ,8, dont have test other gpio for moment

merci

You must be logged in to vote

Replies: 3 comments

Comment options

@P-R-O-C-H-Y Can you help answering this?

You must be logged in to vote
0 replies
Comment options

Hi @stef-ladefense,

  1. Minimum frequency is 1Hz. You need to be careful what frequency and duty resolution you select. See ESP-IDF LEDC docs for more info -> link. There is a simple rule for setting LEDC frequency:
    lower frequencies -> higher resolution
    higher frequencies -> lower resolution (example 40MHz freq can be set only with bit resolution 1)
    I was able to set 1Hz frequency using 12 bits resolution ledcSetup(0,1,12);

  2. LEDC should work on all available pins, if they are not used for anything else or "reserved" for something. I can test GPIO 10 / 14 to check it.

You must be logged in to vote
0 replies
Comment options

hi @P-R-O-C-H-Y
I tested the frequencies on an S2, just to realize the limits.
besides, it is useless to go too low otherwise it flashes.
for the pins, I have not tested further, but the limits that I have found are on an assembly with a screen driven in SPI.

// Test on Lolin S2 Mini ESP32-S2FN4R2 on gpio15 (internal led) https://www.wemos.cc/en/latest/s2/s2_mini.html
// bits freq min freq max (Hz)
// 1 19532 ?
// 2 9766 10019569
// 3 4883 5009784
// 4 2442 2504892
// 5 1221 1252446
// 6 611 626223
// 7 306 313111
// 8 153 156555
// 9 77 78277
// 10 39 39138
// 11 20 19569
// 12 10 9784
// 13 5 4892
// 14 3 2446
#define bit_num 3
#define freq 5000
#define channel 0
#define pin 15
const uint16_t maxi = (1 << bit_num) - 1;
uint16_t dutyCycle = 0;
int8_t _direction = 1;
void setup() {
 ledcSetup(channel, freq, bit_num);
 ledcAttachPin(pin, channel);
}
void loop() {
 if (dutyCycle == maxi) _direction = -1;
 else if (dutyCycle == 0) _direction = 1;
 
 dutyCycle += _direction;
 ledcWrite(channel, dutyCycle);
 delay(5);
}
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /