0

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.

asked Jul 10, 2016 at 9:53

1 Answer 1

1

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

source

answered Jul 10, 2016 at 12:04
2
  • Probably not. They probably all use the same single PWM generator. Commented Jul 10, 2016 at 12:33
  • Source link is 404. Commented Oct 3, 2019 at 13:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.