PWM Channel Conflicts

TCC-ESP32
Posts: 9
Joined: Wed May 13, 2020 12:32 pm

PWM Channel Conflicts

Postby TCC-ESP32 » Thu Sep 30, 2021 12:02 pm

Hi,
I have an ESP32-S dev. board which I am using to control sound and LEDs.

The LEDs are on GPIO_17 and controlled using the FastLED library.
The sounds are generated with the tone() command and I am using the Tone32 library.

My sound output is on GPIO_2 and the channel is set to 0, as follows:
tone(sndPin, frq, dur, chn);

I am reading a volume pot on GPIO_39 [analogRead(39)].
I am outputting a PWM for the volume on GPIO_32 and the volume channel is set to 2. as follows:
ledcWrite(VolumeChannel, map(Volume, 0, 99, 1, 4095));

The result is almost there.
The sound and volume do work.
However, each time I change the volume I get the following error message in the serial monitor window:
[E][Tone32.cpp:6] tone(): Tone channel 511 is already in use

The "511" referred to in the error is the PWM value at that time, so when the volume pot is turned to full the error reads:
[E][Tone32.cpp:6] tone(): Tone channel 4095 is already in use

Any help or insight would be appreciated.
Thank you.

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

Re: PWM Channel Conflicts

Postby lbernstone » Thu Sep 30, 2021 1:10 pm

I would recommend you use the ESP32Servo library instead of Tone32. It will prevent the channel conflict you are seeing, since it manages all your pwm channels.
https://github.com/madhephaestus/ESP32Servo

Who is online

Users browsing this forum: No registered users and 84 guests