EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Dithering PWM?

Started by Tom Becker May 6, 2005
I'm PWM'ing a DC motor with Timer2, so it's 8-bit PWM, which I'm running
at 450Hz. 30:1 gearing brings the output shaft to 1RPS when the motor
is at 1800RPM. I'd like the 1RPS to be as accurate and stable as
possible.

Currently, the motor approaches 1800RPM but, due to the relatively large
PWM steps, hunts about the target speed slightly as code alternately
accelerates and decelerates the motor with a Hall feedback loop. The
long-term average speed is correct.

Has anyone achieved an extra bit of virtual PWM by dithering its LSB?
The Hall feedback, for example, generates an interrupt at 30Hz. The
service routine calcs the interval and nudges the speed accordingly but,
if the interval change is small, no PWM change will occur if the
calculated PWM is well between 8-bit steps; that can be a relatively
stable state resulting in a slightly fast or slow speed that stays close
but is slightly and persistently wrong.

If I, however, add one-half a PWM bit of noise to the calculated speed
float value - at a faster rate than the feedback update - I figure the
average PWM will be more correct, resulting in less hunting about the
target speed. Any chance? Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700


Tom, I'm sure this will be stupid questions but for the dither are
using bipolar (ie: Add or Subtract)?. Have you considered PID? I ask
this as I'm dealing with this on my robot with two NuBotics
WheelWatcher WW02 encoders but I have not got that far yet. Your
dither idea is interesting. My initial approach was simple
measurement with a dead-band but I want to go with PID.

Thanks,

- Tom

--- In basicx@basi..., "Tom Becker" <gtbecker@r...> wrote:
> I'm PWM'ing a DC motor with Timer2, so it's 8-bit PWM, which I'm
running
> at 450Hz. 30:1 gearing brings the output shaft to 1RPS when the
motor
> is at 1800RPM. I'd like the 1RPS to be as accurate and stable as
> possible.
>
> Currently, the motor approaches 1800RPM but, due to the relatively
large
> PWM steps, hunts about the target speed slightly as code alternately
> accelerates and decelerates the motor with a Hall feedback loop.
The
> long-term average speed is correct.
>
> Has anyone achieved an extra bit of virtual PWM by dithering its
LSB?
> The Hall feedback, for example, generates an interrupt at 30Hz. The
> service routine calcs the interval and nudges the speed accordingly
but,
> if the interval change is small, no PWM change will occur if the
> calculated PWM is well between 8-bit steps; that can be a relatively
> stable state resulting in a slightly fast or slow speed that stays
close
> but is slightly and persistently wrong.
>
> If I, however, add one-half a PWM bit of noise to the calculated
speed
> float value - at a faster rate than the feedback update - I figure
the
> average PWM will be more correct, resulting in less hunting about
the
> target speed. Any chance? > Tom >
> Tom Becker
> --... ...--
> GTBecker@R... www.RighTime.com
> The RighTime Clock Company, Inc., Cape Coral, Florida USA
> +1239 540 5700


> ... Have you considered PID?

Yup, but I haven't dug into that, yet. I suppose the I term would solve
it. Maybe worth a try. Thanks. Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700


The darn thing about PID is it's incredibly hard to model in
software. You have to play with it in the 'real world' to pin down the
constants. Once you have done that, you can get really good results.

- Tom

--- In basicx@basi..., "Tom Becker" <gtbecker@r...> wrote:
> > ... Have you considered PID?
>
> Yup, but I haven't dug into that, yet. I suppose the I term would
solve
> it. Maybe worth a try. Thanks. > Tom >
> Tom Becker
> --... ...--
> GTBecker@R... www.RighTime.com
> The RighTime Clock Company, Inc., Cape Coral, Florida USA
> +1239 540 5700


Here's an extension of PWM dithering, with feedback, a sigma-delta
modulator. This method uses PWM output feedback to force the average to
the desired value, despite the available output resolution.

Perhaps the logical extreme of this notion is used in consumer audio
gear, a dithered _one-bit_ DAC that reproduces 16-bit signals. I should
be able to squeeze more from Timer 2's eight bits, I think.

DAC and PWM folks: this is worth taking a look at.

http://www.embedded.com/showArticle.jhtml?articleID"101730 Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700


Tom, I just checked that web site below and found it very helpfull.
Just exactly what are you trying to do?

- Tom

--- In basicx@basi..., "Tom Becker" <gtbecker@r...> wrote:
> Here's an extension of PWM dithering, with feedback, a sigma-delta
> modulator. This method uses PWM output feedback to force the
average to
> the desired value, despite the available output resolution.
>
> Perhaps the logical extreme of this notion is used in consumer audio
> gear, a dithered _one-bit_ DAC that reproduces 16-bit signals. I
should
> be able to squeeze more from Timer 2's eight bits, I think.
>
> DAC and PWM folks: this is worth taking a look at.
>
> http://www.embedded.com/showArticle.jhtml?articleID"101730 > Tom >
> Tom Becker
> --... ...--
> GTBecker@R... www.RighTime.com
> The RighTime Clock Company, Inc., Cape Coral, Florida USA
> +1239 540 5700


> ... Just exactly what are you trying to do?

Part of the current project requires a precisely rotating low-mass
instrument platform. It ain't easy, I find. Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700


I've corrected incorrectly used critical terms "rate" and "duty cycle"
in a few places below.

Two follow-ups:

PWM feedback is easy; the average duty cycle can be read on an analog
pin if an integrating capacitor on the analog input is charged through a
resistor from the PWM output. This forms a low-pass filter; it's values
should yield a RC time constant that is significantly longer than the
PWM rate period. If code then uses that analog input for feedback, the
effective dithered PWM resolution can be limited by the analog input
resolution - not by the PWM output resolution - which can be less.

I found, though, that no single PWM duty cycle is ever correct for an
entire rotation of my platform; integrated feedback shows that the
platform rotation rate varies roughly as a +/-1% sine (i.e., the rate is
fast on one side of rotation and slow on the other side), not good
enough for my requirements, and that changes somewhat with attitude and
temperature. Since the motor is geared 30:1 and I take a Hall tach from
the motor shaft, code has 30 (or 60) opportunities to correct PWM during
one output shaft rotation. I'm using a 30-bin FRAM buffer to maintain
30 independent period integrators and corresponding PWM duty cycles, one
for each 12 degrees of output shaft rotation, in a single multiplexed
closed loop. That has reduced the rotation irregularity, after some
tuning, to below 0.1% peak once it stabilizes in a few seconds from a
dead start.

That's superb for this simple system and I am a happy guy watching the
tach magnet stand absolutely still under a 30Hz strobe. Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700

Yahoo! Groups Links



I said:
> ... I'm using a 30-bin FRAM buffer to maintain 30 independent period
integrators and corresponding PWM duty cycles...

Well, a few days later I am a wiser man. While the initial results
looked good, simply moving the apparatus wreaked havoc. That led to
trying to logically couple adjacent bins, essentially smoothing the lot
of them, but still I had what amounted to a train of locomotives, all
trying to drive the train.

Today, I gained insight. I realized that I am trying to change
something that naturally wants to do something else. I see now that it
is foolish to force anything exotic upon physics, but to, instead, just
accurately measure it and use that measurement in later data
manipulation to apply a correction mathematically, in lieu of correcting
physically. Much smarter.

This is an extension, I think, of the decision we make all the time: is
this function best implemented in hardware or software? In this case,
forcing physical reality to behave - making something rotate better - is
much more difficult than correcting the record of its behavior. The 30
FRAM bins still measure periods but don't feed back to the drive; they
provide, instead, the values I need to fix data later.

FWIW. Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700



Memfault Beyond the Launch