Author Topic: encoder with Arduino UNO  (Read 4929 times)

0 Members and 1 Guest are viewing this topic.

Offline tipipliouTopic starter

  • Full Member
  • ***
  • Posts: 48
  • Helpful? 0
encoder with Arduino UNO
« on: December 28, 2010, 09:12:20 AM »
I want to control two DC motors for making my robot go forward
what is the best way to do it with an Arduino (I'm new with Arduino & AVR) ?
The simplest way (I think) would be to use an interrupt ,and then do the job .
but with 2 motors?? I'd probably miss some pulses  :-\
it would be better to use Timers,but some functions of the Arduino's API use them ,so.. bad solution (that's what they told me in Arduino's Forum..) Is it true ?
So, I'm lost  :'(,there must be a way to  deal with two encoders INDEPENDENTLY

thanks in advance

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: encoder with Arduino UNO
« Reply #1 on: December 28, 2010, 03:53:34 PM »
My Arduino based motor controller watches two encoders. Details and code @ http://www.billporter.info/s-a-g-a-r-s-smart-motor-controller/  and an update with more pictures @ http://www.billporter.info/sagar-update-new-motor-controller-and-motors/

One channel of both encoders is connect to an external interrupt pin. I hi-jack a timer to accurately measure time. Works fairly well. The timer I hi-jacked (timer 2 if I remember right) only disabled PWM on two pins I don't use anyway.

It works well, you can see it in action on my autonomous rover:

SAGAR Autonomous Robot Waypoint Mission Interface and Vehicle Video

A good description of Arduino uses of timers is here:  http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/

From the site, here's what you affect when you hi-jack a timer.

    * Timer0 (System timing, PWM 5 and 6)
      Used to keep track of the time the program has been running. The millis() function to return the number of milliseconds since the program started using a global incremented in the timer 0 ISR. Timer 0 is also used for PWM outputs on digital pins 5 and 6.
    * Timer1 (PWM 9 and 10)
      Used to drive PWM outputs for digital pins 9 and 10.
    * Timer2 (PWM 3 and 11)
      Used to drive PWM outputs for digital pins 3 and 11.
« Last Edit: December 28, 2010, 03:58:32 PM by madsci1016 »


Get Your Ad Here