Skip to content

Commit 01c8cae

Browse files
authored
Added method to change the ledc PWM frequency programmatically (#5003)
Added method to change the ledc PWM frequence programmatically Returning frequency from ledcChangeFrequency
1 parent 57cf2fb commit 01c8cae

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Diff for: cores/esp32/esp32-hal-ledc.c

+9
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,12 @@ void ledcDetachPin(uint8_t pin)
318318
{
319319
pinMatrixOutDetach(pin, false, false);
320320
}
321+
322+
double ledcChangeFrequency(uint8_t chan, double freq, uint8_t bit_num)
323+
{
324+
if (chan > 15) {
325+
return 0;
326+
}
327+
double res_freq = _ledcSetupTimerFreq(chan, freq, bit_num);
328+
return res_freq;
329+
}

Diff for: cores/esp32/esp32-hal-ledc.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ uint32_t ledcRead(uint8_t channel);
3535
double ledcReadFreq(uint8_t channel);
3636
void ledcAttachPin(uint8_t pin, uint8_t channel);
3737
void ledcDetachPin(uint8_t pin);
38+
double ledcChangeFrequency(uint8_t channel, double freq, uint8_t resolution_bits);
3839

3940

4041
#ifdef __cplusplus

0 commit comments

Comments
 (0)