Author Topic: Encoder pulse measurement  (Read 1710 times)

0 Members and 1 Guest are viewing this topic.

Offline kasuntTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Encoder pulse measurement
« on: June 07, 2011, 10:36:50 PM »
Hi guys,

Im really stuck at this problem of reading encoder pulses for a two wheeled robot. The platform im coding is for mega128. And I need to accurately calculate motor speed.

The robot is fitted with the following,

Two 24v Wheelchair motors - RPM unknown
Two HEDS encoders - 256 CPR
Platform - mega128 running at 16Mhz
Wheel circumference - 1.0367m
Gear ratio - 51.56:1
Axel distance - 0.508m

Could someone kindly help me with the speed calculation. My attempt at it wasn't very successful because I started using floating points.

So far I am able to read the encoder CHA channels in two interrupts INT2 and INT3. And I have a integer counter that increments or decrements based on the CHB channels correspondingly. But I have no idea how to read the actual ticks between two triggers to measure the speed.

Offline Billy

  • Robot Overlord
  • ****
  • Posts: 132
  • Helpful? 2
Re: Encoder pulse measurement
« Reply #1 on: June 08, 2011, 06:39:15 PM »
But I have no idea how to read the actual ticks between two triggers to measure the speed.

There are two ways to do what you need to do.
1 - Count the time if takes for successive encoder pulses to come in.
2 - Count the encoder pulses that comes in per unit time.

For # 1, set an interrupt to increment a counter every 100 uS or so. When one pulse comes in, check the counter to see how long since the last pulse, then reset the counter and be ready for the next pulse
For #2, set an interrupt to run every 100mS (or so) and see how many pulses have come in the last 100mS.

Either way, to get the speed, you need a reference to time as in both the examples above.

NOTE: Method #1 cannot be used to track position speed accurately, only speed position, as you will lose partial counts when the pulse comes in. - added at edit - to gain more speed accuracy using this method, the interrupts need to get shorter, taking up more and more of the processor bandwidth -
Method #2 can be used to get both speed and position. If you set up the interrupts correctly, you will not lose any counts.
« Last Edit: June 08, 2011, 11:28:29 PM by Billy »

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: Encoder pulse measurement
« Reply #2 on: June 09, 2011, 03:35:59 AM »
Motor speed will be:
1/T rev/s or 60/T rpm

Where T is the time taken in seconds for 256 encoder counts (in the same direction).

Robot speed will be:
Motor speed (rev/s) * (Wheel Circumference / Gear ratio) = Motor speed * 0.020107 m/s

In other words 1 motor revolution is a 2cm distance travelled, and 1 encoder pulse is 0.07mm. This kind of precision is possibly a bit much? your controller has to check direction and count every encoder pulse. Travelling at 1m/s will give 12800 pulses/second/wheel or 1 interrupt every 39us...

Avoid floating point if at all possible, m/s and rpm etc have no meaning to a robot so don't have your robot calculate them if it doesn't need to. Try to work in integer encoder counts and time 'ticks' - the same distance/time information but much more robot friendly.


Get Your Ad Here