ESP32 Wroom PWM and capacitive touch support status

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

ESP32 Wroom PWM and capacitive touch support status

#1 Post by hereiam991 » 07 Jan 2021, 02:04

Hello Ppl,
i hope this is the right section to ask.

i would like to use a ESP32 as i need some propper PWM.
as far i see this is basically supported with a recent esp32 image.

3 Ouestions:

1.what is the max PWM frequency achievable on the ESP32 normally, is it hardware PWM?

2.are there knowen pin restrictions for PWM? it looks like almost every pin can be used for PWM.

one usecase will be driving 3 pin 12V PC fans, i am not sure which frequency i will need .
also not sure how i will solve that, low side or high side switched.
high side switched i could smooth the PWM to DC by using a RC filter with a fat cap,
with a high PWM freq. this would be easy and maybe a elegant way.

3.i saw there is a experimental touch plug in, is there a image including this or does it needs to be complied?

thanks for any insights !

TD-er
Core team member
Posts: 3946
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Wroom PWM and capacitive touch support status

#2 Post by TD-er » 07 Jan 2021, 09:55

It is correct that the recent builds of the ESP32 now use the hardware PWM for constant frequencies. (hardware fade is not yet used)

The ESP32 does have 2 PWM circuits:
- One based on 80 MHz clock
- One based on 1 MHz clock

To me it is not entirely clear when the 80 MHz clock version cannot be used, so let's assume it is just a matter of "used until all high speed options are in use".

This circuit is programmed to have a number of clock "X ticks" up and "Y ticks" down, which can be set per selected pin.
There is a limit on the number of pins that can have their own phase and X/Y values. (3 or 5 I think, have to look into the libs to be sure)

The Arduino library layer does add an abstraction layer on top of this which essentially splits the 80 MHz into a "frequency", "resolution" and "PWM duty".
For example 1024 steps (10 bit) of PWM resolution means the max frequency = 80'000'000 Hz / 1024 = 78'125 Hz. (which is the PWM resolution we use)

For servo's the PWM is only set in the first few usec of a period, but the frequency can be very low.
Therefore the resolution is then set to 16 bits, thus lowering the max. frequency to 1220 Hz.

The Ethernet chip (LAN8710A for example) may need the ESP to supply a high frequency clock, so I guess (not sure) this uses also one of these circuits. But that doesn't really matter I guess, because with using LAN, you don't have many pins left for other things.


About the available pins... I have to check the library to know which pins can and cannot be used for this.
At least the upper 4 pins cannot be used as those are input only.


Plugin P097 (Touch ESP32) should be included in the "testing" builds of ESP32.
This one also supports the Hall effect sensor present in the ESP32.
It essentially uses the ADCs of the ESP32.
Be aware ADC2 of the ESP32 is also used for WiFi, so don't select pins connected to that ADC when using WiFi or else you may get really strange readings or unstable WiFi.

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESP32 Wroom PWM and capacitive touch support status

#3 Post by hereiam991 » 07 Jan 2021, 11:29

thanks a lot for this very helpfull answer.
sounds quite perfect.
seems the default pwm freq is 78125 Hz then, pretty high.
as long i can use the regular espeasy syntax to set the duty cycle and frequency i should be fine.
very nice youre supporting hardware pwm, i think i can get away without a hardware fade, i think fading could be done from domoticz.

i consider building me a pwm dimmer for some led lights by using optocouplers.
dont think i will need a high pwm frequency for these as there is a internal logic evalauting the signal anyway.
one channel should be capable of driving normal 3 pin dc fans (usefull in summer for me).
here a high pwm could come in handy if i try to make some clean DC out of the signal, with high i mean soemthing above 10khz, maybe 50.
80khz could be a bit too much to handle, idk.
quick and dirty would probably to dim the fan with a low pwm frequency like 30hz, not sure if i can go that low, neither knowing if my fans can be driven by lets say 20khz directly (no PWM fans, just normal 3pin).
20khz and above would allow to create a dc voltage i think, that should be a safe bet.
i dont need many steps or quick reactions.

so we have 5 pwm channels then.

as there are so many pins, why not use the touch capable pins i thought.
so far i planned to use all of the 10.
one pair is up/down for a pwm channel value simply.

planning to use a small i2c oled to display the values.

so the requirements come down to PWM support, full capacitive pin supprt, i2c oled support.

seems its all there allready!

i am orientating myself atm on this pinout
Image
i have no final pinout but so far the plan is.
all touch pins for capacitive pads.
27-38 and 5-8 14-15 would be options for the pwm pins, some dont work iguess while the grafic shows almost all pins cpable of doing pwm :roll: .

its work in progress, i do like how capable this chip is so far.

https://randomnerdtutorials.com/esp32-p ... nce-gpios/

TD-er
Core team member
Posts: 3946
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Wroom PWM and capacitive touch support status

#4 Post by TD-er » 07 Jan 2021, 12:20

Just keep in mind when chosing the touch pins, that you're using the ones connected to the ADC which is not used by the WiFi.
See: https://espeasy.readthedocs.io/en/lates ... ty-and-adc

And before building it, please test using something like a NodeMCU board (with ESP32) to see if you actually can drive different PWMs at the same time.
The log will tell you what the set frequency is, so you may also tell if you're running out of the "80 MHz" clock driven pins.
But if you set the PWM frequency to like 1000 Hz give or take, you will always get what you're asking for (1 MHz clock/1024 steps is slightly below 1000 Hz)

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESP32 Wroom PWM and capacitive touch support status

#5 Post by hereiam991 » 07 Jan 2021, 13:44

very valid points.
seems almost all touch pins are on the ADC2.
i can not say if the simple function of a button still works in conjunction with WLAN, maybe there are enoguh gaps to get a press of a button?
while it looks like i may should go another route then.
any idea?
basically i want to show 5 channels/values on the oled and would like to have a apossibiy to influence these, doesnt need to be realised by 10 buttons but it seemed to be a straight forward simple way.

also good hint with the pwm frequency, i need to check if the esp32 can do 2 frequencies at once , timers.
for my led dimming i will be fine with 1khz, 100hz to 3khz should work fine.
for a 3pin fan 1khz is quite nasty, very audible and not easy to smooth.

edit: i think ill skip the buttons then, shame for all the unused pins.

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESP32 Wroom PWM and capacitive touch support status

#6 Post by hereiam991 » 07 Jan 2021, 14:24

for the 2 seperate pwm frequencies.

https://rntlab.com/question/esp32-two-f ... wm-output/
it looks like it would work if using channel 0 and channel 2.
some are grouped, some not.

is there a recommendation for PWM pins not causing troubble?

TD-er
Core team member
Posts: 3946
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Wroom PWM and capacitive touch support status

#7 Post by TD-er » 07 Jan 2021, 15:43

The way I programmed it, is so it will keep track of pins that are assigned for a "channel" (maybe not the "channel" as used in the ESP32 definition) so they will at least not interfere with each other as long as you keep the frequency the same.
So you have to test whether it may cause issues if mixing frequencies is really needed.
This feature has not yet been tested that extensive. At least it is now better than before as there were no checks for conflicting settings and now there is a check.
But as you have seen, there are more things that may cause conflicts if you mix frequencies too and that's not being looked at in the code for now as that would make the code much more complex to keep it generic.
For example the order in which PWM pins are set to use PWM may matter more than the GPIO pin you use.

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESP32 Wroom PWM and capacitive touch support status

#8 Post by hereiam991 » 08 Jan 2021, 01:18

i see the problem.
in the end it looks like i simply have to test it.
the eps32 pwm frequencies arent as straight forward as on a atmega328 f.e..

so i will probably use 5 pins in the range of 16-33 for pwm outputs.

its cool that the esp32 is basically supported allready and giving some propper hardware pwm.
this is a huge help allready.
in worst case i need to drive the fan with 1khz, or maybe 2 or 3khz if it works out.

this is some interessting read.
https://github.com/micropython/micropython/pull/6276

its probably vs a generic concept, but maybe with the tone function, DAC1 DAC2, gpio 25 and 26 one could generate a independent second frequency?

TD-er
Core team member
Posts: 3946
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Wroom PWM and capacitive touch support status

#9 Post by TD-er » 08 Jan 2021, 10:55

Yep, I could add a check for matching frequencies when assigning a channel.
Just have to check/test if frequency is the only limiting factor.

I also added a wrapper for this check to the Servo calls, so have to check what will happen if I mess with channels for another pin, which is a shared channel used by a servo.
So this may become quite intensive regarding the number of tests that have to be done.

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESP32 Wroom PWM and capacitive touch support status

#10 Post by hereiam991 » 08 Jan 2021, 12:18

can imagine that this would cause much work.
dont want cause any stress there and i think i am fine allready.

i have just oredered a esp32 development board, just 8266 at hand otherwise.
when this is here i could try to set some pwm frequencies on dif pins and check these on a scope.
i can report my findings if theyre of any help for you.
so far i will simply take a compiled version of the latest release.

TD-er
Core team member
Posts: 3946
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Wroom PWM and capacitive touch support status

#11 Post by TD-er » 08 Jan 2021, 13:27

Maybe you can also add a separate feature request issue on Github for this?
Requests like these are later next to impossible to find when I want to work on them. (and also to remind me to work on them)

hereiam991
Normal user
Posts: 31
Joined: 24 Oct 2020, 15:18

Re: ESP32 Wroom PWM and capacitive touch support status

#12 Post by hereiam991 » 09 Jan 2021, 13:43

thanks, a feature request is something to consider if its ok for you.
while its none of my urgent problems and as i say, can probably get away well like it is.
i will see whats comming from the pins first.

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests