Page 1 of 1

Change PWM Frequency ?

Posted: 10 Aug 2017, 01:05
by forgoden
Whats the easiest way to change PWM Frequency?

Default is 1khz and dimming leds will flickering

I am using ESPEasy_v2.0.0-dev10

Re: Change PWM Frequency ?

Posted: 10 Aug 2017, 11:05
by Domosapiens
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.

Re: Change PWM Frequency ?

Posted: 10 Aug 2017, 18:00
by forgoden
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.

Re: Change PWM Frequency ?

Posted: 10 Aug 2017, 18:28
by Domosapiens

Re: Change PWM Frequency ?

Posted: 11 Aug 2017, 15:04
by Ernst
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

Re: Change PWM Frequency ?

Posted: 19 Jan 2018, 22:45
by ahlermi
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
}

Re: Change PWM Frequency ?

Posted: 22 Jan 2018, 13:59
by toffel969
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.

Re: Change PWM Frequency ?

Posted: 22 Jan 2018, 17:35
by ahlermi

Re: Change PWM Frequency ?

Posted: 22 Jan 2018, 18:00
by toffel969
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)

Re: Change PWM Frequency ?

Posted: 22 Jan 2018, 21:21
by cr3pt
So no changes for fixit via software?

Re: Change PWM Frequency ?

Posted: 23 Jan 2018, 00:11
by Domosapiens

Re: Change PWM Frequency ?

Posted: 23 Jan 2018, 10:29
by ahlermi
in witch way would you build in the capacitor?
pwm + and ground - ?

Re: Change PWM Frequency ?

Posted: 23 Jan 2018, 11:48
by toffel969
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/

Re: Change PWM Frequency ?

Posted: 23 Jan 2018, 20:35
by cr3pt
And that help you??

Re: Change PWM Frequency ?

Posted: 24 Jan 2018, 12:26
by toffel969
Yes it reduces the squeaking noise on the fan by about 90%

Re: Change PWM Frequency ?

Posted: 25 Jan 2018, 18:41
by ahlermi
the result of adding the condensator is that speed is always i think 100%

Re: Change PWM Frequency ?

Posted: 26 Jan 2018, 11:33
by toffel969
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

Re: Change PWM Frequency ?

Posted: 01 Feb 2018, 15:37
by ahlermi
Meine Lösung

Re: Change PWM Frequency ?

Posted: 07 Apr 2019, 23:16
by bastibasti
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

Re: Change PWM Frequency ?

Posted: 08 Apr 2019, 21:43
by Domosapiens
Did you see?

Code: Select all

PWM,<GPIO>,<duty>,<duration>,<frequency>
https://espeasy.readthedocs.io/en/lates ... hlight=pwm

Re: Change PWM Frequency ?

Posted: 25 Jun 2019, 15:42
by malla
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 43444 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 ;)

Re: Change PWM Frequency ?

Posted: 23 Sep 2019, 07:26
by lm317t
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

Re: Change PWM Frequency ?

Posted: 23 Sep 2019, 08:35
by grovkillen
PWM,<GPIO>,<duty>,<duration>,<frequency>

Try duration to something above 0. Does it work then?

Re: Change PWM Frequency ?

Posted: 26 Sep 2019, 18:25
by malla
as you can see in my post above it is not working.

Re: Change PWM Frequency ?

Posted: 26 Sep 2019, 18:26
by grovkillen
I asked you to do a longer interval than zero. Try 1000 as a test.

Re: Change PWM Frequency ?

Posted: 26 Sep 2019, 18:27
by grovkillen
Ok, I saw your first post now. Sorry. We need to test it ourselves.

Re: Change PWM Frequency ?

Posted: 17 Dec 2019, 13:42
by waspie
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.

Re: Change PWM Frequency ?

Posted: 17 Dec 2019, 15:48
by grovkillen
I haven't no, have you tried the latest releases using newer core?

Re: Change PWM Frequency ?

Posted: 17 Dec 2019, 15:52
by waspie
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.

Re: Change PWM Frequency ?

Posted: 18 Jan 2020, 01:16
by stefanru
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

Re: Change PWM Frequency ?

Posted: 18 Jan 2020, 12:03
by Patou
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

Re: Change PWM Frequency ?

Posted: 18 Jan 2020, 18:41
by stefanru
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

Re: Change PWM Frequency ?

Posted: 19 Jan 2020, 14:33
by Patou
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

Re: Change PWM Frequency ?

Posted: 19 Jan 2020, 15:40
by stefanru
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

Re: Change PWM Frequency ?

Posted: 20 Jan 2020, 15:06
by Patou
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

Re: Change PWM Frequency ?

Posted: 20 Jan 2020, 21:38
by stefanru
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

Re: Change PWM Frequency ?

Posted: 20 Jan 2020, 21:42
by grovkillen
Why not have a rule that trigger a relay in the case of PWM set to 0?

Re: Change PWM Frequency ?

Posted: 20 Jan 2020, 22:03
by stefanru
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

Re: Change PWM Frequency ?

Posted: 22 Jan 2020, 00:26
by stefanru
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