EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Stepper motor control with PIC

Started by Roy Wheaton February 8, 2005

Has anyone developed software and/or hardware for controlling the
absolute position of a stepper motor with a potentiometer? It has to
be a stepper, not a servo. I need the stepper to follow the movement
of a potentiometer shaft around a 180 degree axis. I work in PicBasic
Pro, so that would be my preference, but any help will be very
appreciated.



http://www.piclist.com/io/stepper/linistep has source code and schematics for the stepper control part.
 
piclist.com has gobbs of code for A2D. Your challenge will be to marry the two.
 
---
James.
 
 


From: Roy Wheaton [mailto:r...@yahoo.com]
Sent: 2005 Feb 08, Tue 16:26
To: p...@yahoogroups.com
Subject: [piclist] Stepper motor control with PIC


Has anyone developed software and/or hardware for controlling the
absolute position of a stepper motor with a potentiometer? It has to
be a stepper, not a servo. I need the stepper to follow the movement
of a potentiometer shaft around a 180 degree axis. I work in PicBasic
Pro, so that would be my preference, but any help will be very
appreciated.


to unsubscribe, go to http://www.yahoogroups.com and follow the instructions


--- In , "Roy Wheaton" <roy_wheaton@y...> wrote:
>
> Has anyone developed software and/or hardware for controlling the
> absolute position of a stepper motor with a potentiometer? It has to
> be a stepper, not a servo. I need the stepper to follow the movement
> of a potentiometer shaft around a 180 degree axis. I work in PicBasic
> Pro, so that would be my preference, but any help will be very
> appreciated.

I know I'm gonna get yelled at, but I'll say it anyway....You can't!
You need some way to sense the position to get the movement to follow
the pot.

Now, you can use the pot to move the stepper relative to where you
thought you told it to go previously. But there'll be initialization
issues, maximum step rate issues, missed step issues, etc.
While it's certailnly possible to buy very linear pots, don't make
the mistake of thinking any old pot will be sufficiently linear.
Or that two samples of the same pot will have the exact same curve.
You can't set the pot very accurately anyway. Maybe you can use some
visual feedback from the motion system instead of some dial on the pot.
If you're trying to get two mechanical systems to track, you've got
a lot of pot issues...

All I'm sayin's that you got a lot more issues than just generating
the quadrature step signals. Somewhere I've got some pic code
in PBP that uses lookup () and generates steps to get linearly from one
point to another in 3D space. If you're clever, you can get all 3
sets of up/down/none direction sequences out of a single lookup table
and just bang on the step command till you run out of steps. But
there's no feedback to guarantee that the stepper actually went there.
mike




Re: Stepper motor control with PIC

--- In , "gettingalongwouldbenice"
<gettingalongwouldbenice@y...> wrote:
>
> --- In , "Roy Wheaton" <roy_wheaton@y...>
wrote:
> >
> > Has anyone developed software and/or hardware for controlling
the
> > absolute position of a stepper motor with a potentiometer? It
has to
> > be a stepper, not a servo. I need the stepper to follow the
movement
> > of a potentiometer shaft around a 180 degree axis. I work in
PicBasic
> > Pro, so that would be my preference, but any help will be very
> > appreciated.
>
> I know I'm gonna get yelled at, but I'll say it anyway....You
can't!
> You need some way to sense the position to get the movement to
follow
> the pot.
>
> Now, you can use the pot to move the stepper relative to where you
> thought you told it to go previously. But there'll be
initialization
> issues, maximum step rate issues, missed step issues, etc.
> While it's certailnly possible to buy very linear pots, don't make
> the mistake of thinking any old pot will be sufficiently linear.
> Or that two samples of the same pot will have the exact same curve.
> You can't set the pot very accurately anyway. Maybe you can use
some
> visual feedback from the motion system instead of some dial on the
pot.
> If you're trying to get two mechanical systems to track, you've got
> a lot of pot issues...
>
> All I'm sayin's that you got a lot more issues than just generating
> the quadrature step signals. Somewhere I've got some pic code
> in PBP that uses lookup () and generates steps to get linearly
from one
> point to another in 3D space. If you're clever, you can get all 3
> sets of up/down/none direction sequences out of a single lookup
table
> and just bang on the step command till you run out of steps. But
> there's no feedback to guarantee that the stepper actually went
there.
> mike

To get it right, you probably need to have an encoder on the stepper
motor. There are a lot of ways to do this including just coupling
an absolute encoder (kind of like a pot but with more wires) to the
shaft. If should be an absolute encoder so you can tell the exact
position of the stepper.

Depending on resolution you can make a simple Gray scale encoder but
it would take 8 bits to get down to 1.8 degree resolution.

With an absolute encoder the process is easy. Convert the pot
voltage to some kind of position and step the motor until the
feedback matches.

If you want to use an incremental encoder then you need to start
from a known position. If the process allows, you could drive the
stepper to an end point switch (or optical) and then keep track from
there. But, if you miss a step the result will be wrong forever.
Maybe periodic recalibration against the end point?

It all depends on the application.



--- In , "rtstofer" <rstofer@p...> wrote:
>
> --- In , "gettingalongwouldbenice"
> <gettingalongwouldbenice@y...> wrote:
> >
> > --- In , "Roy Wheaton" <roy_wheaton@y...>
> wrote:
> > >
> > > Has anyone developed software and/or hardware for controlling
> the
> > > absolute position of a stepper motor with a potentiometer? It
> has to
> > > be a stepper, not a servo. I need the stepper to follow the
> movement
> > > of a potentiometer shaft around a 180 degree axis. I work in
> PicBasic
> > > Pro, so that would be my preference, but any help will be very
> > > appreciated.
> >
> > I know I'm gonna get yelled at, but I'll say it anyway....You
> can't!
> > You need some way to sense the position to get the movement to
> follow
> > the pot.
> >
> > Now, you can use the pot to move the stepper relative to where you
> > thought you told it to go previously. But there'll be
> initialization
> > issues, maximum step rate issues, missed step issues, etc.
> > While it's certailnly possible to buy very linear pots, don't make
> > the mistake of thinking any old pot will be sufficiently linear.
> > Or that two samples of the same pot will have the exact same curve.
> > You can't set the pot very accurately anyway. Maybe you can use
> some
> > visual feedback from the motion system instead of some dial on the
> pot.
> > If you're trying to get two mechanical systems to track, you've got
> > a lot of pot issues...
> >
> > All I'm sayin's that you got a lot more issues than just generating
> > the quadrature step signals. Somewhere I've got some pic code
> > in PBP that uses lookup () and generates steps to get linearly
> from one
> > point to another in 3D space. If you're clever, you can get all 3
> > sets of up/down/none direction sequences out of a single lookup
> table
> > and just bang on the step command till you run out of steps. But
> > there's no feedback to guarantee that the stepper actually went
> there.
> > mike
>
> To get it right, you probably need to have an encoder on the stepper
> motor. There are a lot of ways to do this including just coupling
> an absolute encoder (kind of like a pot but with more wires) to the
> shaft. If should be an absolute encoder so you can tell the exact
> position of the stepper.
>
> Depending on resolution you can make a simple Gray scale encoder but
> it would take 8 bits to get down to 1.8 degree resolution.
>
> With an absolute encoder the process is easy. Convert the pot
> voltage to some kind of position and step the motor until the
> feedback matches.
>
> If you want to use an incremental encoder then you need to start
> from a known position. If the process allows, you could drive the
> stepper to an end point switch (or optical) and then keep track from
> there. But, if you miss a step the result will be wrong forever.
> Maybe periodic recalibration against the end point?
>
> It all depends on the application.


He is right. I wouldnt use a pot because we want stepper motors to be
free running and a pot isnt. The best is to use an encoder disc. The
type depends on the accuracy you need. You can even use the entire
assembly from a mouse which has a encoder disc and a light all
assembled. And basically a stepper motor has to do homing in when you
start your system. Even commercial systems advise this, to safeguard
against controller problems and mechanical drift. So best is to add a
limit switch and use that as your 0,0 reference.From there, the whole
thing performs as a incremental encoding. Since the encoder can sense
direction, you are have directional control as well.

B




--- In , "bg3009" <bg3009@y...> wrote:
>
> --- In , "rtstofer" <rstofer@p...> wrote:
> >
> > --- In , "gettingalongwouldbenice"
> > <gettingalongwouldbenice@y...> wrote:
> > >
> > > --- In , "Roy Wheaton"
<roy_wheaton@y...>
> > wrote:
> > > >
> > > > Has anyone developed software and/or hardware for controlling
> > the
> > > > absolute position of a stepper motor with a potentiometer? It
> > has to
> > > > be a stepper, not a servo.............

Wow! Thanks to each of you that took the time to respond. I have a
much better idea as to how to proceed. I hope that I can return the
favor some day!



At 08:10 AM 2/9/2005, rtstofer wrote:

>To get it right, you probably need to have an encoder on the stepper
>motor. There are a lot of ways to do this including just coupling
>an absolute encoder (kind of like a pot but with more wires) to the
>shaft. If should be an absolute encoder so you can tell the exact
>position of the stepper.

The tried and true method used by the tens of thousands of keytag engraving
machines scattered around the world is to just drive the stepper against a
mechanical end stop during initialization. Kind of clunky (in my opinion)
but why argue with sucess?

So: you would drive the stepper hard against its end stop for more pulses
than 1 full turn needs, then fall into your main loop. The main loop would
read the pot value and compare that to a counter that represents the
stepper position. You simply generate the 4 phase signals as needed (think
of a 4 or 8 count phase counter) and increment or decrement both counters
at the same time.

Its harder to explain than to do.

dwayne

--
Dwayne Reid <>
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(780) 489-3199 voice (780) 487-6397 fax

Celebrating 20 years of Engineering Innovation (1984 - 2004)
.-. .-. .-. .-. .-. .-. .-. .-. .-. .-
`-' `-' `-' `-' `-' `-' `-' `-' `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.



Hi Dwayne-

In the prehistoric days of the Apple II when they developed the
floppy disk drive for the Apple, the design engineers there
decided that the flag stop on the Sugart drive indicating track
zero was redundant and they stepped the drive out more than
40 tracks to establish the home track 0 position rather than
being more "gentle" and stepping out until the track zero
optocoupler indicated the head was at track zero. We, who also
did floppy disk controllers, didn't think to highly of Apple's
solution, but I guess in hindsight, they got away with it.

I would certianly suggest that in order to give the associated
mechanical hardware a break that the designer incorporate some sort of
electrical signal to indicate limits. Simple optocouplers are
often used as are switches.

Best of luck on your project.

Cheers,

Rich S.

--- In , Dwayne Reid <dwayner@p...> wrote:
> At 08:10 AM 2/9/2005, rtstofer wrote:
>
> >To get it right, you probably need to have an encoder on the
stepper
> >motor. There are a lot of ways to do this including just coupling
> >an absolute encoder (kind of like a pot but with more wires) to the
> >shaft. If should be an absolute encoder so you can tell the exact
> >position of the stepper.
>
> The tried and true method used by the tens of thousands of keytag
engraving
> machines scattered around the world is to just drive the stepper
against a
> mechanical end stop during initialization. Kind of clunky (in my
opinion)
> but why argue with sucess?
>
> So: you would drive the stepper hard against its end stop for more
pulses
> than 1 full turn needs, then fall into your main loop. The main
loop would
> read the pot value and compare that to a counter that represents
the
> stepper position. You simply generate the 4 phase signals as
needed (think
> of a 4 or 8 count phase counter) and increment or decrement both
counters
> at the same time.
>
> Its harder to explain than to do.
>
> dwayne
>
> --
> Dwayne Reid <dwayner@p...>
> Trinity Electronics Systems Ltd Edmonton, AB, CANADA
> (780) 489-3199 voice (780) 487-6397 fax
>
> Celebrating 20 years of Engineering Innovation (1984 - 2004)
> .-. .-. .-. .-. .-. .-. .-. .-. .-. .-
> `-' `-' `-' `-' `-' `-' `-' `-' `-'
> Do NOT send unsolicited commercial email to this email address.
> This message neither grants consent to receive unsolicited
> commercial email nor is intended to solicit commercial email.




Memfault Beyond the Launch