To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 1648
1647  |  1649
Subject: 
ROM stuff: Better than PWM
Newsgroups: 
lugnet.robotics
Date: 
Sat, 19 Dec 1998 06:16:30 GMT
Viewed: 
1059 times
  
So I was thinking about writing a motor driver that is better than what is
in the ROM already.  Here's the problem:

You have a function called once every 1/1000th of a second.  You want to
allow n speeds of the motor at minimal cost in lookup tables.  You can only
turn the motor on or off, and you can only do it in the function mentioned.
How do you do it?  Assume a speed of p is on p/n of the time, so valid
values of p are between 1 and n, inclusive.

One way to do this is to use PWM with a period of n, and to use a lookup
table to store the waveforms.  This is how the RCX does it already, for
n=8.  The RCX has an 8 ms period and turns on the motor on for 1 to 8 of
those 8 ms depending on the speed of the motor.  The main problem with this
method is that the table size is O(n^2).  Bleah!

You can avoid the O(n^2) table cost by keeping a counter.  Count p cycles
on, then count n-p cycles off.  This works.  But as n gets large, the
period of n ms drops low enough that the motor becomes ineffective.  For
example, if n is 1000 and p is 500, the motor is on for 1/2 sec then off
for 1/2 sec.  That won't drive the motor the way you want it to be driven.
Even for n = 100, things are very jittery.

So here's my solution:

every 1/1000th sec:
    count += p
    if (count >= n)
turn motor on
count -= n
    else
turn motor off

That's it.

I'm sure this algorithm has been thought of before; I got the idea from
Bresenham's line drawing algorithm and from the Floyd-Steinberg error
diffusion dithering algorithm, but I believe this algorithm is a typical
one used in one-bit D/A converters.

-Kekoa



Message has 2 Replies:
  Re: ROM stuff: Better than PWM
 
(...) Funny - I was thinking of doing exactly the same thing - and also basing it on Bresenham. I've always wondered about 1-bit D/A, but if you actually read the docco it is wrapped up in so much weird signal theory it is very hard to understand (...) (26 years ago, 19-Dec-98, to lugnet.robotics)
  Re: ROM stuff: Better than PWM
 
(...) In fact, I'm using exactly this algorithm to drive the motors for my laser scanner - though the host platform is an embedded PC, not the RCX. I'm currently rewriting the motor drivers to: * keep an 1ms resolution system clock * call the task (...) (26 years ago, 19-Dec-98, to lugnet.robotics)

3 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR