mobyd said:
Playing around with a motor fader (Alps "K" type conductive plastic). Currently can store a random value and seek that stored value (a PIC and an L293D "H" bridge) but looking for a better way of "hitting the target" - currently the inertia in the system causes a bit of oscillation around the endpoint before the system stabilises (will no doubt get worse with the additional weight of a knob). How do the "big boy" console makers do it ?. Full steam ahead until within, say, 5% of the endpoint, then reduce current to the motor and creep the last bit ?. Any other ways ?.
M
Basically, you need to do a trapezoidal velocity profile. You can't set the velocity at full tilt boogie from a dead start, nor can you come to a dead stop in zero time. So you gradually ramp up the speed until you're going as fast as possible. And then you need to know when to start decelerating so by the time you're at your desired stop position, your velocity is near zero, too.
This Silicon Labs app note has a really good explanation of the problem.
Here's the interesting part of the problem. The profile tells you, essentially, the velocity as a function of position. That means that when you're at position X you're moving some particular speed. That's all well and good, but think about how you'd actually implement that using a micro controller.
See, when you drive a stepper motor, the only control you have is the time between steps. As you speed up, you decrease the time between steps until it is some minimum and then you're slewing. At some point you have to start decelerating, which you do by gradually increasing the time between steps.
The trick, then, is to pre-calculate the step time ramp (assume that acceleration and deceleration have the same profile) and store the time steps in a lookup table. When you're told to move, you load your timer with an initial step interval. The timer expires, triggering an interrupt, and in the ISR you move one step, bump to the next index in the lookup table, get the new interval, load it into the timer, and restart the timer.
This continues until you've done all entries in the ramp table, at which point you're moving at full speed. That is, in your ISR you do the step and then reload the counter with the smallest interval (time between steps).
When you reach the number of steps after which you have to start decelerating, you index through the lookup table in the opposite direction. And finally you're done.
You need at least one position sensor, so you know if you're "home" because you need a reference. Of course, if you have something that tells you the absolute position, then you always know where you are.
-a