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: 307
- 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: 307
- 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 65739 times
Re: Change PWM Frequency ?
ahlermi wrote: ↑19 Jan 2018, 22:45 I 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:35 physical 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: 307
- 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 64888 times
-
- 2.jpg (510.71 KiB) Viewed 64888 times
-
- 1.jpg (599.96 KiB) Viewed 64888 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: 307
- 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: 3621
- 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: 3621
- 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: 3621
- 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



Re: Change PWM Frequency ?
Did you ever get a chance to work on this? i have a need to run a PWM output to a device that specifies 67-93Hz or 127-199Hz . I haven't tried it yet, but wanted to see ahead of time if this is going to work.grovkillen wrote: ↑26 Sep 2019, 18:27 Ok, I saw your first post now. Sorry. We need to test it ourselves.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Change PWM Frequency ?
I haven't no, have you tried the latest releases using newer core?
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 ?
nope! i might get around to it this evening. just trying to get ahead of the game.grovkillen wrote: ↑17 Dec 2019, 15:48 I haven't no, have you tried the latest releases using newer core?
Re: Change PWM Frequency ?
Hi,
i attached a 12 Volt PC fan to my ESP8266.
PWM signal line is connected to GPIO2.
I tried with the pwm command from above.
It is working, but not as i would like.
From above the syntax is: PWM,<GPIO>,<duty>,<duration>,<frequency>
Setting duration or frequency does not change the fans speed.
The only parameter which does is duty.
Setting:
pwm,2,1023 => Nearly full speed, but perhaps 90%
pwm,2,1 => Perhaps 60 - 70%
All values in between change the speed between 1 and 1023.
But i am not able to ste anything under 60 - 70% even pwm,2,0 does not top or speed down the fan more.
Can you help me?
P.S.: after a little bit more testing i think 1023 is 100% and 1 brings it to perhaps 50%.
duration also works if i set duty from 1 to 1023 and duartion to 5000 it chnages the speed slowly over 5 seconds.
But frequency has no effect at all.
P.P.S.: It is a 12 Volt CPU Fan from Intel.
Thanks and best regards,
Stefan
i attached a 12 Volt PC fan to my ESP8266.
PWM signal line is connected to GPIO2.
I tried with the pwm command from above.
It is working, but not as i would like.
From above the syntax is: PWM,<GPIO>,<duty>,<duration>,<frequency>
Setting duration or frequency does not change the fans speed.
The only parameter which does is duty.
Setting:
pwm,2,1023 => Nearly full speed, but perhaps 90%
pwm,2,1 => Perhaps 60 - 70%
All values in between change the speed between 1 and 1023.
But i am not able to ste anything under 60 - 70% even pwm,2,0 does not top or speed down the fan more.
Can you help me?
P.S.: after a little bit more testing i think 1023 is 100% and 1 brings it to perhaps 50%.
duration also works if i set duty from 1 to 1023 and duartion to 5000 it chnages the speed slowly over 5 seconds.
But frequency has no effect at all.
P.P.S.: It is a 12 Volt CPU Fan from Intel.
Thanks and best regards,
Stefan
Re: Change PWM Frequency ?
Hello
A fan is a quadratic load so even with low voltage the speed is still high.
Please measure the voltage at the fan terminal for different setting from 0 to 1023 and report
Have a nice day
Patou
A fan is a quadratic load so even with low voltage the speed is still high.
Please measure the voltage at the fan terminal for different setting from 0 to 1023 and report
Have a nice day
Patou
Re: Change PWM Frequency ?
Hi Patou,
thanks for your reply.
Do you mean the voltage of pwm terminal?
There i have:
0 = 0.02V
1023 = 3.30V
I think i understand now.
I found a spec describing PWM.
So it should work fine.
I was thinking i could stop the fan with pwm 0, but this seems not to be the case.
Is it a characteristic of the fan how fast or slow it can go at certain pwm levels?
How could i control the fan to also stop? Any idea?
Thanks and best regards,
Stefan
thanks for your reply.
Do you mean the voltage of pwm terminal?
There i have:
0 = 0.02V
1023 = 3.30V
I think i understand now.
I found a spec describing PWM.
Code: Select all
PWM Control Input Signal
he following requirements are measured at the PWM (control) pin of the fan cable conne
WM Frequency: Target frequency 25 kHz, acceptable operational range 21 kHz to 28 kH
Maximum voltage for logic low: VIL = 0.8 V
absolute maximum current sourced: Imax = 5 mA (short circuit current)
absolute maximum voltage level: VMax = 5.25 V (open circuit voltage)
I was thinking i could stop the fan with pwm 0, but this seems not to be the case.
Is it a characteristic of the fan how fast or slow it can go at certain pwm levels?
How could i control the fan to also stop? Any idea?
Thanks and best regards,
Stefan
Re: Change PWM Frequency ?
Strange thing fan voltage is 12 VDC and at 1023 pwm value you measure only 3.3 VDC this is probably at the output of the pwm terminal.
Did you place a transistor between the pwm terminal at 3.3 VDC and the fan with a 12 VDC power supply ?
Patou
Did you place a transistor between the pwm terminal at 3.3 VDC and the fan with a 12 VDC power supply ?
Patou
Re: Change PWM Frequency ?
Hi Patou,
yes i measured the pwm output.
3,3V is the voltage of the ESP PWM output at max.
No i do not have a transistor between 12V and pwm.
Why is this necessary?
Bets regards,
Stefan
yes i measured the pwm output.
3,3V is the voltage of the ESP PWM output at max.
No i do not have a transistor between 12V and pwm.
Why is this necessary?
Bets regards,
Stefan
Re: Change PWM Frequency ?
I do not understand what you are doing.
You apply 3.3 VDC to a 12 VDC fan and it is running at nominal speed ???
Applying 0.02 V ( pwm 0) does not stop the fan ???
Very strange
Please give more details
Patou
You apply 3.3 VDC to a 12 VDC fan and it is running at nominal speed ???
Applying 0.02 V ( pwm 0) does not stop the fan ???
Very strange
Please give more details
Patou
Re: Change PWM Frequency ?
Oh ok, i think i see our misunderstanding.
I have a pwm controlled 12 V Fan for PC CPU.
It has a 4 Pin terminal.
Ground
12 V
Tach
PWM
I connect Ground and 12V to the Fan.
Also i connect my ESP to the same Ground.
I connect PWM to my ESP.
Now i can control the fan with the ESP by driving the PWM input of the Fan.
If i understood it correct the fan has its own regulation steered by the PWM input of the fan.
But i think the FAN has its own logic which says for PC that it runs always at 500 RPM and you can control it up to 1200 RPM with the PWM signal.
I think this is a build in logic so that the CPU Fan in the PC never do not turn.
I ordered now a PC Case Fan and hope that i can switch it off, but even with a PC Case fan i am not sure if a stop is implemented in the pwm logic of the Fan.
Do you think i understood this correct?
Thanks and best regards,
Stefan
I have a pwm controlled 12 V Fan for PC CPU.
It has a 4 Pin terminal.
Ground
12 V
Tach
PWM
I connect Ground and 12V to the Fan.
Also i connect my ESP to the same Ground.
I connect PWM to my ESP.
Now i can control the fan with the ESP by driving the PWM input of the Fan.
If i understood it correct the fan has its own regulation steered by the PWM input of the fan.
But i think the FAN has its own logic which says for PC that it runs always at 500 RPM and you can control it up to 1200 RPM with the PWM signal.
I think this is a build in logic so that the CPU Fan in the PC never do not turn.
I ordered now a PC Case Fan and hope that i can switch it off, but even with a PC Case fan i am not sure if a stop is implemented in the pwm logic of the Fan.
Do you think i understood this correct?
Thanks and best regards,
Stefan
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Change PWM Frequency ?
Why not have a rule that trigger a relay in the case of PWM set to 0?
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 ?
Yes, i also thought about a Relais.
I need one component more. I was hoping that it will work without a relais.
Lets see if the Fan will stop with pwm 0, if not i need to use a relais.
Thanks and bets regards,
Stefan
I need one component more. I was hoping that it will work without a relais.
Lets see if the Fan will stop with pwm 0, if not i need to use a relais.
Thanks and bets regards,
Stefan
Re: Change PWM Frequency ?
Hi,
i wanted to inform you that i got an arctic PC Case Fan now.
This is working fine.
PWM 0 is really stopping the fan!
I think kusing a CPU Fan in the first place was my problem. At least my CPU Fan logic was that it still spins with PWM 0.
But with the case Fan everything is working great now.
Thanks and best regards,
Stefan
i wanted to inform you that i got an arctic PC Case Fan now.
This is working fine.
PWM 0 is really stopping the fan!
I think kusing a CPU Fan in the first place was my problem. At least my CPU Fan logic was that it still spins with PWM 0.
But with the case Fan everything is working great now.
Thanks and best regards,
Stefan
Who is online
Users browsing this forum: Ahrefs [Bot] and 14 guests