Author Topic: Problem with driving a motor with pwm in arduino  (Read 2426 times)

0 Members and 1 Guest are viewing this topic.

Offline rajurulezz007Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
  • Newbie :)
Problem with driving a motor with pwm in arduino
« 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 ??
« Last Edit: March 22, 2012, 08:51:34 AM by rajurulezz007 »

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Problem with driving a motor with pwm in arduino
« Reply #1 on: March 22, 2012, 09:00:26 AM »
You'd have to setup the timer used for pwm by hand. This tutorial 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 and do a search for "pwm frequency" you'll see some discussions of this.

Joe

Offline rajurulezz007Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
  • Newbie :)
Re: Problem with driving a motor with pwm in arduino
« Reply #2 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 ??

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Problem with driving a motor with pwm in arduino
« Reply #3 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

 


Get Your Ad Here

data_list