Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: rajurulezz007 on March 22, 2012, 08:46:51 AM

Title: Problem with driving a motor with pwm in arduino
Post by: rajurulezz007 on March 22, 2012, 08:46:51 AM
I have constructed a line follower(PID) using arduino and this is my first robot... I have a problem in driving the motor with pwm signals from arduino... Since the default pwm frequency of arduino is low, i hear constant humming sounds from my motors.. And is not driving my bot..

Plz tel me how to increase the pwm frequency of my arduino uno  :(

Or is there any factor tat might have caused tis problem ??
Title: Re: Problem with driving a motor with pwm in arduino
Post by: joe61 on March 22, 2012, 09:00:26 AM
You'd have to setup the timer used for pwm by hand. This tutorial (http://www.societyofrobots.com/member_tutorials/node/228) gives a good introduction in general.

For the Arduino specifically you'd have to check the documentation to see which timer is being used by whichever pins you're using. If you go to the Arduino site  http://www.arduino.cc (http://www.arduino.cc) and do a search for "pwm frequency" you'll see some discussions of this.

Joe
Title: Re: Problem with driving a motor with pwm in arduino
Post by: rajurulezz007 on March 22, 2012, 09:19:30 AM
Thanx for the reply :) Tis is the code i got in the arduino forum for changing the pwm frequency in pins 3 and 11.
 
TCCR2B = TCCR2B & 0b11111000 | 0x01;

Does this single line of code in the setup() changes the pwm frequency of the pins 3 and 11 ??
Title: Re: Problem with driving a motor with pwm in arduino
Post by: joe61 on March 22, 2012, 09:48:22 AM
That looks a little odd to me. It allows bits to be set which I don't think should be set. They probably are not set though, and in that case this will do no harm.

What that does is set the prescaler so that the timer runs at the system clock speed, which on the Arduino is 16MHz. I guess that's fast enough to not cause a hum :-)

Best thing is to try it.

Joe