Use LEDC library for phase-shifted PWMs
Use LEDC library for phase-shifted PWMs
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?
-
- Posts: 9749
- Joined: Thu Nov 26, 2015 4:08 am
Re: Use LEDC library for phase-shifted PWMs
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.
Re: Use LEDC library for phase-shifted PWMs
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
-
- Posts: 9749
- Joined: Thu Nov 26, 2015 4:08 am
Re: Use LEDC library for phase-shifted PWMs
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.
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.
Re: Use LEDC library for phase-shifted PWMs
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.
-
- Posts: 9749
- Joined: Thu Nov 26, 2015 4:08 am
Re: Use LEDC library for phase-shifted PWMs
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.
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: MicroController and 123 guests