DPRG
DPRG List  



[DPRG] encoder submission

Subject: [DPRG] encoder submission
From: Dan Miner miner at centtech.com
Date: Tue Sep 25 19:34:56 CDT 2001

David,

The encoder article looks great!  The custom encoder boards
>from Kip pushed me over the edge - I ordered 4 of the motors
today.  :-)  *If* we do a group build or buy of these boards, 
put me down for 8 of them (if the price is low enough).  I'll 
use them on other motors too.  I'm interested in fully built
boards OR just the blank boards.

A comment about how you measure speed.  In section "C. Encoder
Segments", you discuss how you measure the number of encoder
counts per motor update period (100 msec or 50msec) and use
that to determine speed.  

I do it a different way that you might benefit from.  I use the 
TIC (Timer Input Capture) function of my HC12 (also available 
on HC11 and 68322 and many non-Motorola CPUs for those on the 
list that don't know).  

This gives me the number of CPU clocks (ECLKs) between encoder 
signal edges.  From that, I compute speed.  My HC12 runs at 
8MHz so an example is:

     8000000 ECLKs/sec
  -----------------------   = 1190 encoder ticks/sec
  6723 ECLKs/encoder tick

Actually, I keep a small circular buffer of these times and 
compute a running average to determine average speed.

To be even more precise - I have a buffer of 4 encoder ticks.
When I get a new time, I subtract the oldest time in the buffer 
>from the newest time.  This automatically gives me the total 
time of the 4 ticks (no summing required) and I just have to 
shift right twice ( = divide by 4) to get the average time of 
the 4 ticks.  Then the newest time overwrites the oldest time 
and I increment the pointer in the circular buffer.

The only "boundary case" is when the motor first starts moving
and the buffer isn't full yet.  I handle this by looking at only
the most recent 2 edges.  *IF* there is only 1 edge so far, 
then I pick a default max_time of $00FFFFFF which translates
to roughly 0.5 encoder ticks per second.

This way, I still get a very accurate speed even at low speed.

				- Dan Miner

More information about the DPRG mailing list

Copyright © 1984 - 2006 Dallas Personal Robotics Group. All rights reserved.
Website Design by NCC

For the latest robot news visit robots.net