2 different PWM frequencies required, but ledcAttachChannel was not declared in this scope

Heiner
Posts: 2
Joined: Sat Jan 27, 2024 7:25 pm

2 different PWM frequencies required, but ledcAttachChannel was not declared in this scope

Postby Heiner » Sat Jan 27, 2024 7:40 pm

I need two different frequencies for my project, 4KHz and 20KHz.
The use of:

Code: Select all

ledcAttach(2, 4000,8);
ledcWrite(2, 127);
ledcAttach(10, 20000,8);
ledcWrite(10, 127);
deliver on both channels/Pins 20KHz;

The use of:

Code: Select all

ledcAttach(10, 20000,8);
ledcWrite(10, 127);
ledcAttach(2, 4000,8);
ledcWrite(2, 127);
deliver on both channels/Pins 4KHz;

If I try to fix the channels with:

Code: Select all

ledcAttachChannel(2, 4000, 8, 0);
ledcAttachChannel(10, 20000, 8, 1);
I get the Message: Compilation error: 'ledcAttachChannel' was not declared in this scope

HW is:
ESP32-C6-DevKitC-1 with 3.0.0 alpha package on Arduino IDE

lbernstone
Posts: 673
Joined: Mon Jul 22, 2019 3:20 pm

Re: 2 different PWM frequencies required, but ledcAttachChannel was not declared in this scope

Postby lbernstone » Sun Jan 28, 2024 11:13 am

Make sure you are using the latest version of 3.0.0 alpha. Note that it is alpha- if there are issues you should file a bug report so it can be fixed. However, this works for me with the latest master.

Code: Select all

void setup() {
  Serial.begin(115200);
  ledcAttach(10, 20000, 8);
  ledcWrite(10, 127);
  delay(1);
  Serial.printf("pin %d\tduty %d\tfreq %d\n", 10, ledcRead(10), ledcReadFreq(10));
  ledcAttach(2, 4000, 8);
  ledcWrite(2, 127);
  delay(1);
  Serial.printf("pin %d\tduty %d\tfreq %d\n", 2, ledcRead(2), ledcReadFreq(2));
  ledcAttachChannel(4, 8000, 8, 1);
  delay(1);
  Serial.printf("pin %d\tduty %d\tfreq %d\n", 4, ledcRead(4), ledcReadFreq(4));
  Serial.printf("pin %d\tduty %d\tfreq %d\n", 2, ledcRead(2), ledcReadFreq(2));
}

Code: Select all

06:10:08.913 -> [    92][I][esp32-hal-ledc.c:116] ledcAttachChannel(): LEDC attached to pin 10 (channel 0, resolution 8)
06:10:08.913 -> pin 10	duty 127	freq 20000
06:10:08.913 -> [   102][I][esp32-hal-ledc.c:116] ledcAttachChannel(): LEDC attached to pin 2 (channel 1, resolution 8)
06:10:08.913 -> pin 2	duty 127	freq 4000
06:10:08.946 -> [   114][I][esp32-hal-ledc.c:116] ledcAttachChannel(): LEDC attached to pin 4 (channel 1, resolution 8)
06:10:08.946 -> pin 4	duty 127	freq 8000
06:10:08.946 -> pin 2	duty 127	freq 8000

Heiner
Posts: 2
Joined: Sat Jan 27, 2024 7:25 pm

Re: 2 different PWM frequencies required, but ledcAttachChannel was not declared in this scope

Postby Heiner » Fri Feb 09, 2024 9:37 am

Sorry, this does not solve the problem. I used the latest 3.0.0-alpha3.
In the migration documentation there is a link from 2. to 3:
https://docs.espressif.com/projects/ard ... /ledc.html
which is clearly described here:

Code: Select all

bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution);
.
is available.

What am I doing wrong on the Arduino side that this is not available?

lbernstone
Posts: 673
Joined: Mon Jul 22, 2019 3:20 pm

Re: 2 different PWM frequencies required, but ledcAttachChannel was not declared in this scope

Postby lbernstone » Fri Feb 09, 2024 11:33 am

ledcAttachChannel is only available in the current master. You will need to install manually to get this function. The list of PRs is getting very low, so there may be a 3.0.0-rc1 very soon.

Who is online

Users browsing this forum: No registered users and 134 guests