user7807: I am using NodeMCU and I program it using Arduino IDE, I need to change the PWM frequency of a port, in Arduino I used to change the frequency using timers registers like that:
TCCR1B = (TCCR1B & 0xF8) | 1 ;

How can I change the frequency of a digital pin using some function like that: 
analogWriteFrequency(pin, 31250);

So that the code will looks like that:
#ifdef __AVR__
TCCR1B = (TCCR1B & 0xF8) | 1 ; //generates the MCKL signal
#else
analogWriteFrequency(pin, 31250);
#endif
analogWrite(pin, 128) ;

Thanks.

user368: 
PWM frequency is 1kHz by default. Call analogWriteFreq(new_frequency) to change the frequency.

source

7807: <p>I am using NodeMCU and I program it using Arduino IDE, I need to change the PWM frequency of a port, in Arduino I used to change the frequency using timers registers like that:</p>

<pre><code>TCCR1B = (TCCR1B &amp; 0xF8) | 1 ;
</code></pre>

<p>How can I change the frequency of a digital pin using some function like that: </p>

<pre><code>analogWriteFrequency(pin, 31250);
</code></pre>

<p>So that the code will looks like that:</p>

<pre><code>#ifdef __AVR__
TCCR1B = (TCCR1B &amp; 0xF8) | 1 ; //generates the MCKL signal
#else
analogWriteFrequency(pin, 31250);
#endif
analogWrite(pin, 128) ;
</code></pre>

<p>Thanks.</p>
 368: <blockquote>
  <p>PWM frequency is 1kHz by default. Call <code>analogWriteFreq(new_frequency)</code> to change the frequency.</p>
</blockquote>

<p><a href="https://github.com/esp8266/Arduino/blob/master/doc/reference.md" rel="nofollow">source</a></p>
