ESP32 - Controlling 2 PWM Applications with 2 LEDC Channels fails

Hello everyone! I‘m new but this Forum already helped me alot.
But now I‘m stuck with a problem and couldn‘t find anyone with the same neither here or elsewhere.

So I‘ve recently been building 2 PWM Application using ESP32, ESPHome and Homeassistant.

The first one controls a Light through the 0-10V PWM-Input of a Meanwell LED Driver.
The second one controls the Speed of a 12V 4-Pin PC-Fan through its PWM Channel.

I was able to implement this on 2 separate ESP32 quite quickly and to my full satisfaction.

Now comes the part where I‘m stuck: Since the Light and the PC-Fan are in the same location, naturally I would like to let one single ESP32 control both the Light and the Fan.

But as soon as I add the second PWM Output for the PC-Fan in the ESPHome Config, the Light-PWM does not work. It goes to the minimum Output. So the light brightness is set to minimum although the corresponding Button in Homassistant is set to 50%.

The PC-Fans are working though…

I‘ve tried using different channels, but nothing changed.
I also tried to use separate GROUND Pins for the Optocoupler and the GROUND from 12V which is connected to ESP32.

What am I missing?

Here‘s the code I‘m using (at the moment 2nd part of the code is disabled since my Light wont work then)


output:
  - platform: ledc
    id: licht_pwm
    pin: GPIO23
    frequency: 1220Hz
    inverted: true
    channel:  0
    
  # - platform: ledc
    # id: umluft_pwm
    # pin: GPIO17
    # frequency: 25000Hz
    # channel:  1


light:
  - platform: monochromatic
    name: "Licht"
    output: licht_pwm     
    gamma_correct: 1.0
       
# fan:
  # - platform: speed
    # output: umluft_pwm
    # name: "Lüfter"

I‘m not sure the Hardware/Wiring is important but to be sure I‘m still posting it:

For the light I‘m using a PC817 Optocoupler with a Resistance.
For the Fan I‘m directly injecting the PWM Signal into the PWM Channel of the PC Fan which has 4-Pins .
The 12Volts com from a separate Powersource, the ESP32 and 12Volt Powersource are connected through Ground.
The 12V positive Wire goes directly to the PC-Fan.

As I mentioned, both cases are working when on separate ESPs.

Thanks in advance!

No one?

If something was not clear or if I didn‘t follow rules that I don‘t know about, please tell me.

Thanks :slight_smile:

Sorry, I thought something changed, but rereading my Original Post I realized it hasn‘t…

Finally, I found the solution!

The light needs to be assigned a high channel over 7 which is for low Frequencies.
Before I only tried to assign the Fan Channel to a higher one, which of course is wrong. Don‘t know why I didn‘t try the other way…

I don‘t really understand, why it does work with a low channel when only using 1 PWM Channel, but anyway, I‘m happy to have found the solution.