Change PWM Frequency ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
forgoden
Normal 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: 291
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
Normal 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: 291
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
Normal 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 9624 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
Normal 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: 291
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
Normal 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 8536 times
2.jpg
2.jpg (510.71 KiB) Viewed 8536 times
1.jpg
1.jpg (599.96 KiB) Viewed 8536 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: 291
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
Normal 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 3446 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
Normal 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: 3324
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
Normal 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: 3324
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: 3324
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:

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests