Change PWM frequency Pololu library

Good day
I am working on a project in which I want to achieve variable motor speed control (through PWM) with the Baby Orangutan. I use this example code(motors1) and try to modify PWM frequency

I modifying PWM control file OrangutanMotors.cpp by new setup timer0 and timer2 to Phase Correct PWM and prescaler to divide the clock by 64.

line 131
TCCR0A = TCCR2A = 0xF3;
change to
TCCR0A = TCCR2A = 0xF1;

line 137
TCCR0B = TCCR2B = 0x02;
change to
TCCR0B = 0x03;
TCCR2B = 0x04;

Than compiling the Pololu AVR Library with type “make clean”, then “make” to compile the entire library
without any error. I recompile and build the programm, but unfortunately PWM frequency doesn’t change, remains as before 9.8kHz
I would greatly appreciate your help and advise.


I moved your post to our A-Star and Orangutan subforum, which seemed more appropriate.

Is there are particular reason why you want to change the PWM frequency? Did you install the library after building it? If so, what command did you use? Also, what operating system are you using?

- Amanda

In my project I use servo motors, which require PWM 500-1000Hz. How can I modify POLOLU library to change PWM frequency? I use Baby Orangutan, Wndows XP, AVR Studio4. I have a good experience in my working program. It is necessary to change PWM frequency only by modifying and recompiling library.

What kind of servos are you using? Can you provide a link to the electrical specifications for them?

It is not clear what environment you are using to run make in, but you should try running make install to install the library after rebuilding it. However, instead of trying to modify the Pololu AVR C/C++ library, it probably would be easier for you to just write your own code to set the PWM frequency in your program.

- Amanda

Thanks for your usefull advice. The library was reinstalled correctly and the frequency of PWM servo motors changed as I wanted.

1 Like