Page 1 of 2
change PWM frequency?
Posted:
Fri Aug 14, 2015 10:23 am
by Jerry Jackson
Is there a way to change PWM frequency to something other than 1000 Hz using Arduino IDE ?
Something in the range of 4 to 20kHz would probably be perfect for my application
Re: change PWM frequency?
Posted:
Sun Aug 16, 2015 12:45 am
by ridge
https://github.com/esp8266/Arduino/blob ... ring_pwm.cHave a look at the
analogWriteFreq command.
I haven't used it yet. Let us know how it works for you.
Re: change PWM frequency?
Posted:
Tue Aug 18, 2015 1:50 pm
by Jerry Jackson
Thanks for directing me to analogWriteFreq()
It mostly works great for my needs. I am directly driving the gate on some logic level MOSFETs and noticed something strange:
At some frequency threshold above around 4.5 to 5 kHz it does not appear to have a solid level of control of the PWM pulse stream. For example, at 10% pulse width I was seeing very brief and random 100% on periods which was causing my MOSFET controlled LED lighting to go to 100% (like a camera flash) then settle back at 20% and randomly continue with the 100% spikes. It made no difference with or without the MOSFET gate connected. I could easily see these 100% periods with my oscilloscope.
I finally settled on 4 kHz as it appears to be stable there.
Otherwise, I am happy that it seems more than capable of supplying enough current to charge my MOSFET gate very quickly (around 16 nanoseconds rise time) after experimenting with several different MOSFET choices to hopefully give me the least amount of heating problems.
Re: change PWM frequency?
Posted:
Thu Sep 10, 2015 12:47 am
by Phil Price
I noticed this also. I was hoping to be able to generate a 38Khz carrier for an IR project but unfortunately I don't think it will be possible with the sporadic 100% I'm seeing on PWM. Not sure if this can be fixed in software or if it is a hardware limitation (i.e interrupts getting delayed to deal with network stuff).
Also the frequency did not seem to be correct either, appeared to be around 45Khz - but that could just be me not using the scope properly...