Use LEDC library for phase-shifted PWMs

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Use LEDC library for phase-shifted PWMs

Postby RichPiano » Wed Nov 16, 2022 1:22 pm

We have a lamp which uses esps LEDC library to drive seven high-speed led channels. The problem arises when they start to light up which happens almost simultanously. This brings with it the problem with high initial currents: At this time the leds will draw so much current that we're running the risk of blowing the fuse. Of course this could be mitigated by using other electronical components but can we do something from the software side, e.g. phase-shift the PWM's? Unfortunately I can find no such API in LEDC. Is it possible?

ESP_Sprite
Posts: 9749
Joined: Thu Nov 26, 2015 4:08 am

Re: Use LEDC library for phase-shifted PWMs

Postby ESP_Sprite » Thu Nov 17, 2022 1:10 am

We don't have support for phase shifting, but what you can do is invert the polarity of an output (can be done in software) and feed it the inverse of the duty-cycle.

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Re: Use LEDC library for phase-shifted PWMs

Postby RichPiano » Fri Nov 18, 2022 9:25 am

Thank you @ESP_Sprite. That could be useful, but it's still a binary approach. As said we have 7 channels, parting it to 3 high-starting and 4 low-starting channels would mitigate the problem, but not solve it. Would be nice if I could provide this as a feedback to you or another ESP team member for further improvement :)

ESP_Sprite
Posts: 9749
Joined: Thu Nov 26, 2015 4:08 am

Re: Use LEDC library for phase-shifted PWMs

Postby ESP_Sprite » Sat Nov 19, 2022 1:29 am

You could also look into using the MCPWM instead; I think it allows different phases (but I'm not 100% sure on that). I'll note your feedback, perhaps in future chips we can have a phase offset setting.

EDIT: Just browsed the TRM again... looks like you actually *can* set the phase, it's just not documented in that way. The LEDC has a concept called the 'hpoint', which is from what I understand effectively an offset of the waveform, with a value of 0 to 2^duty_resolution.

If this is true, you can already change it in the current driver. I'll make an issue to make this a bit clearer and more accessible as well.

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Re: Use LEDC library for phase-shifted PWMs

Postby RichPiano » Mon Nov 21, 2022 6:51 am

The hpoint! Of course! I remember seeing it documented somewhere (technical reference manual maybe?) Need to look it up again, as far as I can remember, it allows you to set the upper limit of the pwm counter (effectively defining the point where the signal switches from high to low and vice versa). But I didn't consider that you might be able to set an offset that way.

ESP_Sprite
Posts: 9749
Joined: Thu Nov 26, 2015 4:08 am

Re: Use LEDC library for phase-shifted PWMs

Postby ESP_Sprite » Mon Nov 21, 2022 9:04 am

Yep, I had the same thing; kinda knew it existed, never made the connection with phase changes. Seemingly the person writing the LEDC driver also had no real idea what it does.

If you get around to implementing this, I'd like to hear how you fare; could be useful to poke the driver guys to add this in a more better documented fashion.

Who is online

Users browsing this forum: No registered users and 113 guests