Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

source

share|improve this answer
    
Thanks. but, can I adjust it to a specific pin ? – Mostafa Khattab Jul 10 at 12:30
    
Probably not. They probably all use the same single PWM generator. – Ignacio Vazquez-Abrams Jul 10 at 12:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.