Change PWM Frequency ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
forgoden
New user
Posts: 3
Joined: 07 Jul 2017, 07:03

Change PWM Frequency ?

#1 Post by forgoden » 10 Aug 2017, 01:05

Whats the easiest way to change PWM Frequency?

Default is 1khz and dimming leds will flickering

I am using ESPEasy_v2.0.0-dev10

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Change PWM Frequency ?

#2 Post by Domosapiens » 10 Aug 2017, 11:05

PWM frequency is 1kHz by default. Call analogWriteFreq(new_frequency) to change the frequency.
I don't see any call to analogWriteFreq in the source.

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 ....
and compile your own version

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.

forgoden
New user
Posts: 3
Joined: 07 Jul 2017, 07:03

Re: Change PWM Frequency ?

#3 Post by forgoden » 10 Aug 2017, 18:00

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.

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Change PWM Frequency ?

#4 Post by Domosapiens » 10 Aug 2017, 18:28

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.

Ernst
New user
Posts: 2
Joined: 11 Mar 2017, 20:57

Re: Change PWM Frequency ?

#5 Post by Ernst » 11 Aug 2017, 15:04

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

ahlermi
Normal user
Posts: 21
Joined: 19 Jan 2018, 16:04

Re: Change PWM Frequency ?

#6 Post by ahlermi » 19 Jan 2018, 22:45

I had testet with

Code: Select all

    case PLUGIN_INIT:
      {
        // add this line
        analogWriteFreq(31300); //should give 31300Hz
        // go on with existing code
        
no reaction, same result, fan is making noise if it is set under pwm 900

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
Unbenannt.png (176.63 KiB) Viewed 49426 times

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Change PWM Frequency ?

#7 Post by toffel969 » 22 Jan 2018, 13:59

ahlermi wrote: 19 Jan 2018, 22:45 I had testet with

Code: Select all

    case PLUGIN_INIT:
      {
        // add this line
        analogWriteFreq(31300); //should give 31300Hz
        // go on with existing code
        
no reaction, same result, fan is making noise if it is set under pwm 900

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

ahlermi
Normal user
Posts: 21
Joined: 19 Jan 2018, 16:04

Re: Change PWM Frequency ?

#8 Post by ahlermi » 22 Jan 2018, 17:35


User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Change PWM Frequency ?

#9 Post by toffel969 » 22 Jan 2018, 18:00

ahlermi wrote: 22 Jan 2018, 17:35 physical Arduino

https://we-mod-it.com/board258-diy-do-i ... m-steuern/
I don't think the pwm on ESP has the same quality. Maybe you can use the I2C pwm extender.
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

cr3pt
New user
Posts: 2
Joined: 22 Jan 2018, 11:55

Re: Change PWM Frequency ?

#10 Post by cr3pt » 22 Jan 2018, 21:21

So no changes for fixit via software?

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Change PWM Frequency ?

#11 Post by Domosapiens » 23 Jan 2018, 00:11

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.

ahlermi
Normal user
Posts: 21
Joined: 19 Jan 2018, 16:04

Re: Change PWM Frequency ?

#12 Post by ahlermi » 23 Jan 2018, 10:29

in witch way would you build in the capacitor?
pwm + and ground - ?

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Change PWM Frequency ?

#13 Post by toffel969 » 23 Jan 2018, 11:48

ahlermi wrote: 23 Jan 2018, 10:29 in witch way would you build in the capacitor?
pwm + and ground - ?
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

cr3pt
New user
Posts: 2
Joined: 22 Jan 2018, 11:55

Re: Change PWM Frequency ?

#14 Post by cr3pt » 23 Jan 2018, 20:35

And that help you??

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Change PWM Frequency ?

#15 Post by toffel969 » 24 Jan 2018, 12:26

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

ahlermi
Normal user
Posts: 21
Joined: 19 Jan 2018, 16:04

Re: Change PWM Frequency ?

#16 Post by ahlermi » 25 Jan 2018, 18:41

the result of adding the condensator is that speed is always i think 100%

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Change PWM Frequency ?

#17 Post by toffel969 » 26 Jan 2018, 11:33

ahlermi wrote: 25 Jan 2018, 18:41 the result of adding the condensator is that speed is always i think 100%
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

ahlermi
Normal user
Posts: 21
Joined: 19 Jan 2018, 16:04

Re: Change PWM Frequency ?

#18 Post by ahlermi » 01 Feb 2018, 15:37

Meine Lösung
Attachments
3.jpg
3.jpg (551.95 KiB) Viewed 48527 times
2.jpg
2.jpg (510.71 KiB) Viewed 48527 times
1.jpg
1.jpg (599.96 KiB) Viewed 48527 times

bastibasti
Normal user
Posts: 25
Joined: 31 Jul 2018, 11:41

Re: Change PWM Frequency ?

#19 Post by bastibasti » 07 Apr 2019, 23:16

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

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Change PWM Frequency ?

#20 Post by Domosapiens » 08 Apr 2019, 21:43

Did you see?

Code: Select all

PWM,<GPIO>,<duty>,<duration>,<frequency>
https://espeasy.readthedocs.io/en/lates ... hlight=pwm
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.

malla
New user
Posts: 2
Joined: 25 Jun 2019, 12:51

Re: Change PWM Frequency ?

#21 Post by malla » 25 Jun 2019, 15:42

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

Code: Select all

PWM,14,250,1000,2500
wanted.


The command leads me to this outcome.
pwm.PNG
pwm.PNG (30.56 KiB) Viewed 43437 times

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 ;)

lm317t
New user
Posts: 1
Joined: 23 Sep 2019, 06:57

Re: Change PWM Frequency ?

#22 Post by lm317t » 23 Sep 2019, 07:26

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

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Change PWM Frequency ?

#23 Post by grovkillen » 23 Sep 2019, 08:35

PWM,<GPIO>,<duty>,<duration>,<frequency>

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 :idea: :idea: :idea:

malla
New user
Posts: 2
Joined: 25 Jun 2019, 12:51

Re: Change PWM Frequency ?

#24 Post by malla » 26 Sep 2019, 18:25

as you can see in my post above it is not working.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Change PWM Frequency ?

#25 Post by grovkillen » 26 Sep 2019, 18:26

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 :idea: :idea: :idea:

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Change PWM Frequency ?

#26 Post by grovkillen » 26 Sep 2019, 18:27

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 :idea: :idea: :idea:

waspie
Normal user
Posts: 127
Joined: 09 Feb 2017, 19:35

Re: Change PWM Frequency ?

#27 Post by waspie » 17 Dec 2019, 13:42

grovkillen wrote: 26 Sep 2019, 18:27 Ok, I saw your first post now. Sorry. We need to test it ourselves.
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.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Change PWM Frequency ?

#28 Post by grovkillen » 17 Dec 2019, 15:48

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 :idea: :idea: :idea:

waspie
Normal user
Posts: 127
Joined: 09 Feb 2017, 19:35

Re: Change PWM Frequency ?

#29 Post by waspie » 17 Dec 2019, 15:52

grovkillen wrote: 17 Dec 2019, 15:48 I haven't no, have you tried the latest releases using newer core?
nope! i might get around to it this evening. just trying to get ahead of the game.

stefanru
Normal user
Posts: 41
Joined: 29 Jul 2017, 00:48

Re: Change PWM Frequency ?

#30 Post by stefanru » 18 Jan 2020, 01:16

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

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Change PWM Frequency ?

#31 Post by Patou » 18 Jan 2020, 12:03

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

stefanru
Normal user
Posts: 41
Joined: 29 Jul 2017, 00:48

Re: Change PWM Frequency ?

#32 Post by stefanru » 18 Jan 2020, 18:41

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.

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)
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

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Change PWM Frequency ?

#33 Post by Patou » 19 Jan 2020, 14:33

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

stefanru
Normal user
Posts: 41
Joined: 29 Jul 2017, 00:48

Re: Change PWM Frequency ?

#34 Post by stefanru » 19 Jan 2020, 15:40

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

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Change PWM Frequency ?

#35 Post by Patou » 20 Jan 2020, 15:06

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

stefanru
Normal user
Posts: 41
Joined: 29 Jul 2017, 00:48

Re: Change PWM Frequency ?

#36 Post by stefanru » 20 Jan 2020, 21:38

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

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Change PWM Frequency ?

#37 Post by grovkillen » 20 Jan 2020, 21:42

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 :idea: :idea: :idea:

stefanru
Normal user
Posts: 41
Joined: 29 Jul 2017, 00:48

Re: Change PWM Frequency ?

#38 Post by stefanru » 20 Jan 2020, 22:03

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

stefanru
Normal user
Posts: 41
Joined: 29 Jul 2017, 00:48

Re: Change PWM Frequency ?

#39 Post by stefanru » 22 Jan 2020, 00:26

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

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests