Change PWM Frequency ?
Moderators: grovkillen, Stuntteam, TD-er
Change PWM Frequency ?
Whats the easiest way to change PWM Frequency?
Default is 1khz and dimming leds will flickering
I am using ESPEasy_v2.0.0-dev10
Default is 1khz and dimming leds will flickering
I am using ESPEasy_v2.0.0-dev10
-
- Normal user
- Posts: 292
- Joined: 06 Nov 2016, 13:45
Re: Change PWM Frequency ?
I don't see any call to analogWriteFreq in the source.PWM frequency is 1kHz by default. Call analogWriteFreq(new_frequency) to change the frequency.
Thought experiment:
You could try to add a line:
analogWriteFreq(new_frequency)
to module:
_P001_Switch.ino
in the section:
case PLUGIN_INIT
as first line
So
Code: Select all
case PLUGIN_INIT:
{
// add this line
analogWriteFreq(5000) //should give 5Khz
// go on with existing code
if (Settings.TaskDevicePin1PullUp[event->TaskI ....
Integration of this function in the GUI by the Dev's, could be an enhancement of (already great!) ESPEasy.
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.
Re: Change PWM Frequency ?
Thank you very much! Are there any instructions how I can compile the source of espeasy?
I want to build
ESPEasy_v2.0.0-dev10_normal_4096.bin
again with changed pwm frequency.
I want to build
ESPEasy_v2.0.0-dev10_normal_4096.bin
again with changed pwm frequency.
-
- Normal user
- Posts: 292
- Joined: 06 Nov 2016, 13:45
Re: Change PWM Frequency ?
See the Wiki:
https://www.letscontrolit.com/wiki/inde ... evelopment
https://www.letscontrolit.com/wiki/inde ... Platformio
Not that complicated ...even I did it
https://www.letscontrolit.com/wiki/inde ... evelopment
https://www.letscontrolit.com/wiki/inde ... Platformio
Not that complicated ...even I did it

30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.
Re: Change PWM Frequency ?
How can you see the led's flickering?
A human doesn't see flickering above 50Hz?
I use PWM on ESP a lot and not 1 is flickering
Gr Ernst
A human doesn't see flickering above 50Hz?

I use PWM on ESP a lot and not 1 is flickering
Gr Ernst
Re: Change PWM Frequency ?
I had testet with
no reaction, same result, fan is making noise if it is set under pwm 900
on arduino is no noise with
Code: Select all
case PLUGIN_INIT:
{
// add this line
analogWriteFreq(31300); //should give 31300Hz
// go on with existing code
on arduino is no noise with
Code: Select all
void setup() {
TCCR1B = TCCR1B & 0b11111000 | 0x01; // Setzt Timer1 (Pin 9 und 10) auf 31300Hz
}
- Attachments
-
- Unbenannt.png (176.63 KiB) Viewed 9723 times
Re: Change PWM Frequency ?
ahlermi wrote: ↑19 Jan 2018, 22:45I had testet with
no reaction, same result, fan is making noise if it is set under pwm 900Code: Select all
case PLUGIN_INIT: { // add this line analogWriteFreq(31300); //should give 31300Hz // go on with existing code
on arduino is no noise with
Code: Select all
void setup() { TCCR1B = TCCR1B & 0b11111000 | 0x01; // Setzt Timer1 (Pin 9 und 10) auf 31300Hz }
One question, one suggestion:
Question: when you say "on Arduino", do you mean on a physical Arduino, or do you mean an ESP8266 using Arduino IDE
Suggestion: I had the same problem with fan noise, I put a capacitor (rather large) that helped a lot.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Re: Change PWM Frequency ?
I don't think the pwm on ESP has the same quality. Maybe you can use the I2C pwm extender.ahlermi wrote: ↑22 Jan 2018, 17:35physical Arduino
https://we-mod-it.com/board258-diy-do-i ... m-steuern/
Then I suggest you try the solution with a cap, it will smoothen the ripple. Das Pfeifen ist dann zwar auch nicht ganz weg, gefühlt aber 90-95% reduziert, (220µF)
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Re: Change PWM Frequency ?
So no changes for fixit via software?
-
- Normal user
- Posts: 292
- Joined: 06 Nov 2016, 13:45
Re: Change PWM Frequency ?
Vote here a thumb up:
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.
Re: Change PWM Frequency ?
in witch way would you build in the capacitor?
pwm + and ground - ?
pwm + and ground - ?
Re: Change PWM Frequency ?
yes, and you might want to add a resistor too (its then a Low-pass filter) https://provideyourown.com/2011/analogw ... o-voltage/
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Re: Change PWM Frequency ?
And that help you??
Re: Change PWM Frequency ?
Yes it reduces the squeaking noise on the fan by about 90%
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Re: Change PWM Frequency ?
the result of adding the condensator is that speed is always i think 100%
Re: Change PWM Frequency ?
No, it doesn't make sense to me, nor reflects actual expierience
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Re: Change PWM Frequency ?
Meine Lösung
- Attachments
-
- 3.jpg (551.95 KiB) Viewed 8636 times
-
- 2.jpg (510.71 KiB) Viewed 8636 times
-
- 1.jpg (599.96 KiB) Viewed 8636 times
-
- Normal user
- Posts: 25
- Joined: 31 Jul 2018, 11:41
Re: Change PWM Frequency ?
strange that this option is not implemented, as a command.
I think instead of recompiling (which usually breaks things)
I think i will have to add an avr that reads the pwm from the esp and outputs on different frequenccy
I think instead of recompiling (which usually breaks things)
I think i will have to add an avr that reads the pwm from the esp and outputs on different frequenccy
-
- Normal user
- Posts: 292
- Joined: 06 Nov 2016, 13:45
Re: Change PWM Frequency ?
Did you see?
https://espeasy.readthedocs.io/en/lates ... hlight=pwm
Code: Select all
PWM,<GPIO>,<duty>,<duration>,<frequency>
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.
Re: Change PWM Frequency ?
Hey guys,
i am desperatrly looking for a release which includes working PWM-Frequency settings.
I read that the moving from the GPIO functionality out of the Swith-Module caused some problems, and that this might caused the functionality was removed accidently.
I am happy for any hints in this direction =)
The lastest release:
-duty-cycle is set correctly, but the frequency remains at 1kHz instead the 2.5kHz as in the command
wanted.
The command leads me to this outcome.
I am using to PWM-Power some Fans with that, sadly we can hear the 1kHz, so 20kHz would be nice
i am desperatrly looking for a release which includes working PWM-Frequency settings.
I read that the moving from the GPIO functionality out of the Swith-Module caused some problems, and that this might caused the functionality was removed accidently.
I am happy for any hints in this direction =)
The lastest release:
-duty-cycle is set correctly, but the frequency remains at 1kHz instead the 2.5kHz as in the command
Code: Select all
PWM,14,250,1000,2500
The command leads me to this outcome.
Code: Select all
INIT : Booting version: mega-20190607 (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 PUYA support)
59 : INIT : Free RAM:24960
60 : INIT : Warm boot #6 - Restart Reason: External System
62 : FS : Mounting...
87 : FS : Mount successful, used 75802 bytes of 957314
438 : CRC : program checksum ...OK
475 : CRC : SecuritySettings CRC ...OK
583 : INIT : Free RAM:22160
585 : INIT : I2C
585 : INIT : SPI not enabled
599 : INFO : Plugins: 47 [Normal] (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 PUYA support)
I am using to PWM-Power some Fans with that, sadly we can hear the 1kHz, so 20kHz would be nice

Re: Change PWM Frequency ?
hi anyone! i want to change the frequency too
I also found how to change this:
PWM,<GPIO>,<duty>,<duration>,<frequency>
my code rules has the form
pwm,12,100,0,500
but the frequency remains 1 kHz
I am in complete despair((
why the developer gave the instruction and is silent that it is invalid
I also found how to change this:
PWM,<GPIO>,<duty>,<duration>,<frequency>
my code rules has the form
pwm,12,100,0,500
but the frequency remains 1 kHz
I am in complete despair((
why the developer gave the instruction and is silent that it is invalid
- grovkillen
- Core team member
- Posts: 3332
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Change PWM Frequency ?
PWM,<GPIO>,<duty>,<duration>,<frequency>
Try duration to something above 0. Does it work then?
Try duration to something above 0. Does it work then?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



Re: Change PWM Frequency ?
as you can see in my post above it is not working.
- grovkillen
- Core team member
- Posts: 3332
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Change PWM Frequency ?
I asked you to do a longer interval than zero. Try 1000 as a test.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



- grovkillen
- Core team member
- Posts: 3332
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Change PWM Frequency ?
Ok, I saw your first post now. Sorry. We need to test it ourselves.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



Who is online
Users browsing this forum: Bing [Bot] and 2 guests