# any experience with encoded motor pos control?



## gregc (Apr 25, 2015)

inexpensive motors with relatively simple encoders allow these motor to be controlled precisely. The encoder has two overlapping optical sensors so that direction as well as a bit finer position can be measured. I believe they are used for turntable positioning rather than stepper motors. They can measure a fraction of a rotation.

i believe their use requires something similar to a PID control loop that compensates for speed to minimize overshoot or at least anticipate the approach to the target position. Not sure if close enough may be adequate.

at 20,000 rpm, a 16 step encoder with quadrature detection generates an event every 47 usec. Of course they don't need to be run that fast. I believe interrupts are typically used, but must not waste time

i found that takes over 100 usec with a function call, but can take 12 usec w/o the function call with an Arduino.

anyone w/ any experience playing with encoders? how did you deal with overshoot?


----------



## wvgca (Jan 21, 2013)

isn't what you're referring to labeled a quadature encoder ??
as far as i know, they are used mostly for speed control, rather than position ?


----------



## gregc (Apr 25, 2015)

yes, but if you search for a quadrature motor encoder on ebay, you won't find the inexpensive ones. I think it is actually called an incremental encoder.

yes, speed control is easier. But I saw a indexed turntable and started wondering how it works and realized a stepper motor didn't have enough resolution without gearing. I believe it uses a inexpensive motor with an encoder with gearing.










It also has a calibration function where it rotates the bridge to a position it detects (presumably with an opto) to locate position zero if the bridge gets moved.

as I said, position control requires knowing the speed in order to start slowing down before reaching the target position.


----------



## gunrunnerjohn (Nov 10, 2010)

Long ago in a life far away, I was using similar encoders in panel mounted aircraft instruments. We used a variety of techniques, and yes you do need to manage the acceleration and deacceleration, and that's dependent on the load and also the visual effect you're trying to achieve. With aircraft instruments, overshoot was not an option, pointers had to stop precisely. Most of the later instruments used stepper motors with a single zero flag on the pointer mechanism so you could find your zero.

I have to say, the image in the eBay listing doesn't inspire confidence, looks like a garage-shop operation!


----------



## gregc (Apr 25, 2015)

gunrunnerjohn said:


> I have to say, the image in the eBay listing doesn't inspire confidence, looks like a garage-shop operation!


aside from finer resolution, not sure what more is needed to determine a small fraction of a revolution for our modeler needs. The unit i have came from an inkjet printer.

the circuit boards in the optical packs I worked on at Lucent looked pretty low-tech. But combined with the optical components and firmware resulted in a high performing assembly. I believe that is the nature of good engineering, combining components with low and varying performance into an assembly with high performance.

thanks for the schematic. it matches what i determined


----------



## gunrunnerjohn (Nov 10, 2010)

There's really not much to the process, just counting pulses. The trick here is to determine zero when you power up, there has to be a way to do that. For our instruments, we simply ran the pointers down to a known zero and then started from there.

For really critical readings, like airspeed, there was typically a continuous monitor, frequently a 4-wire resolver, monitoring the pointer position at all times. Needless to say, the geartrain in some of these instruments has to be seen to be believed.

I have this 4" MACH AS squirreled away in one of my boxes, I'll have to take the case off and get a shot of the gear layer when I find it. There are five servo loops in there, two for the drums and three for the pointers. All of the pointers and drums are driven using stepper motors with positive feedback. This was part of the basic instrument package that shipped with every Boeing 737 for about fifteen years before they went to the glass cockpit. After it was in service for a few years, they achieved an MTBF of over 20,000 hours, not bad for something with all this going on!


----------



## gregc (Apr 25, 2015)

the goal is to stop precisely at a specified position. Yes, the position is determined by inc/decrementing pulses depending on direction. But the motor continues to rotate after reaching the target position and turning off the motor.

i just started trying to change motor direction when over/under shooting until the target is reached exactly. The plot below shows the overshoots and undershoots as expected. (the x-axis is not time, but simply measurement index).

a PID type of algorithm would attempt to anticipate reaching the target position based on speed (time between pulses) and either turning off the motor or slowing it down. 

Motor speed is relatively slow. I driving it with 5V and i believe it is at least a 12V motor.


----------



## gunrunnerjohn (Nov 10, 2010)

The beauty of stepper motors is that as long as the geartrain inertia isn't excessive, you can stop precisely where you need to be. Obviously, you have still have acceleration and deacceleration curves at the start and end of the travel in order to overcome the inertia of the load.


----------



## gregc (Apr 25, 2015)

gunrunnerjohn said:


> The beauty of stepper motors is that as long as the geartrain inertia isn't excessive, you can stop precisely where you need to be.


why was an encoder needed if you're using stepper motors.



gunrunnerjohn said:


> Obviously, you have still have acceleration and deacceleration curves at the start and end of the travel in order to overcome the inertia of the load.


can you offer any suggestions?

x-axis is in 100s of uses (16-bits). red indicates when motor was reversed, ccw, and green when motor cw. target is 2688

i'm guessing that code could monitor the first time that the motor voltage is reversed and how many counts it took for the motor direction to reverse. That number could be used (and updated) for all subsequent movements, assuming full speed is reached.

not sure modulating motor voltage is necessary, just on/off/rev, since I'm driving a 12V motor with only a 5V (USB) PWM.


----------



## gunrunnerjohn (Nov 10, 2010)

gregc said:


> why was an encoder needed if you're using stepper motors.


Simple, when you hold the lives of an airplane full of passengers in your hands, not knowing for *SURE* that you haven't missed one or more steps and are presenting an inaccurate indication on a primary flight instrument is not an option!


> can you offer any suggestions?


Truthfully, the curves for the most part on our instruments were determined empirically in the lab. Trying to compute the effects of a significant gear train inertia with 1970's computing power was a lot harder than just testing until you got it right.


----------



## Shdwdrgn (Dec 23, 2014)

For a turntable application, I would think a stepper with a worm gear would be just about ideal, plus probably some kind of sensor to re-calibrate the position each time you apply power? You could even determine the gear lash by approaching the sensor from each direction.


----------



## gregc (Apr 25, 2015)

did you see the picture in the 3rd post? Looks like the Walthers turntable uses a small low voltage DC motor. Assume their cost for such a motor is much less than for a stepper.

position is stored in eeprom (100k erasures) after each movement.

the unit can be recalibrated, where it turns the table until it reaches a detectable position if the bridge is moved accidentally or power interrupted before a move is completed.


----------



## Shdwdrgn (Dec 23, 2014)

Ah I missed that. I was just browsing through and probably missed some details.


----------



## gunrunnerjohn (Nov 10, 2010)

If you want to get fancy, there are anti-backlash gears available, makes that job easier. They might be useful to get accurate positioning with the TT.


----------



## gregc (Apr 25, 2015)

Shdwdrgn said:


> You could even determine the gear lash by approaching the sensor from each direction.


The older Walthers turntable has a ~4" gear w/ ~210 teeth driven by a worm. The shaft that worm is on is in turn driven by a smaller (20 teeth?) gear that is driven by the worm on a small can motor.

i believe by using a large gear minimizes the gear lash (while more than double at the periphery).

below are values for 90 and 130' turntables for a resolution of 1/10 the rail width (~1/16"): 0.058 and 0.040 degrees. Gear ratios for 1.8 deg steppers is listed.

```
DiaFt  DiaIn Res(")   Frac Degree StpGear
    90   12.4  0.006    160  0.058   31.2
   130   17.9  0.006    160  0.040   45.1
```
With the twin worm gearing (4200 = 210x20) the resolution for a can motor w/ 16 step encoder (22.5 deg / step) is 0.005 deg. 

```
22.5   4200  0.005  encoder and TT gearing
```
it's been decades since i played with stepper motors. Is there still a lot of vibration?


----------



## gunrunnerjohn (Nov 10, 2010)

Modern steppers can be as smooth as a baby's behind. 

Obviously, the larger the gear, the less effect that backlash would have. It doesn't necessarily minimize the amount, but since it's not multiplied by nearly as much movement, the effect is there's less.


----------



## Lemonhawk (Sep 24, 2013)

This sure sounds like a stepper motor operation. Put an index switch somewhere to find zero position then store the pulse to each siding. I can see using a dc motor if there is a sensor at each siding and homing to it, expecting to find the right position using that pulse encoder, well I think it's too easy to drop a pulse.


----------



## Shdwdrgn (Dec 23, 2014)

Modern steppers can also be found in incredibly small sizes. I have some standard 4-wire steppers here with bodies of only 3x5mm. You can probably find something that will drop right in the housing above (if that was your goal).


----------



## gregc (Apr 25, 2015)

Lemonhawk said:


> well I think it's too easy to drop a pulse.


based on the numbers i just posted, i think you could drop 8 pulses without affecting the accuracy. The count could be reset whenever the bridge crosses the calibration point. What could could the loss of a pulse?

what is the manufacturers cost for a small stepper vs can motor? What would the electronics cost be?

curious about how and why a vender such as walthers builds a turntable the way they do. Their design has evolved over time. I believe the original design was not that good.


----------



## wvgca (Jan 21, 2013)

gregc said:


> curious about how and why a vender such as walthers builds a turntable the way they do. Their design has evolved over time. I believe the original design was not that good.





i believe that it's based on nothing more than cost of the final item ...by the time you figure advertising, boxing, market awareness, etc .. there isn't too much left for actual product .. they are in the business of making money first and foremost ..
just my three cents worth, lol


----------



## gunrunnerjohn (Nov 10, 2010)

gregc said:


> based on the numbers i just posted, i think you could drop 8 pulses without affecting the accuracy. The count could be reset whenever the bridge crosses the calibration point. What could could the loss of a pulse?


You don't necessarily lose a pulse, but if there's any binding or obstruction to the movement, the motor can simply throw away a few steps. A bipolar stepper motor could easily lose a pulse or two with even a momentary mechanical hitch. The waveform is symmetrical, so it wouldn't even know. FWIW, this is why I previously mentioned positive position feedback for mission critical applications of stepper motors.


----------



## gregc (Apr 25, 2015)

i realized this is why you said with your air speed indicator that you needed the encoder to confirm the position of the shaft driven by a stepper motor.

i don't understand how losing pulses is possible with a can motor. If the shaft is prevented from moving the encoder doesn't generate any pulses.

maybe this is why using a can motor and encoder is both more reliable and less expensive than a stepper on a turntable. Unless the bridge slips on the shaft (desirable), the position is known.


----------



## gunrunnerjohn (Nov 10, 2010)

Precise positioning with a plain DC motor is a lot harder than with something like a stepper, which is why most industrial applications have moved to some version of the stepper. Usually, the encoder on a can motor is used more for speed control that precise positioning. If you're one or two counts off with your can motor, how do you move it only that amount? It's not as easy as it looks!

We used to use DC servo loops and brushless motors before the steppers were practical, but the loop control was all analog, and it was an interesting exercise to get the loops all stable with accuracy and no overshoot. If you build 100 identical instruments with a fairly involved gear-train, no matter how hard you try, the friction in the gears is never truly identical.

Stepper motors made the precise positioning a lot easier, the position sensing was only to insure no gear binding or electrical noise glitch didn't cause an accuracy issue.


----------



## gregc (Apr 25, 2015)

no doubt that a stepper motor for position (and maybe an encoder for confirmation) would be a relatively simple solution. Yet the Walthers turntable using a DC motor appears to be accurate.

i developed a system in college using an Apple II, a stepper motor and phototransistor to measure the optical intensity around the periphery of a specklegram that was described in Applied Optics.

i think(??) that with sufficient loading and when driven relatively slowly near the target, a motor won't have much momentum once voltage is dropped to zero and can stop w/in some +/- of the target encoder position.


----------



## gunrunnerjohn (Nov 10, 2010)

I don't know what Atlas does in their control. FWIW, for my Super-Chuffer, I use dynamic braking on the motor to stop the smoke impeller quickly between chuffs, perhaps Atlas does the same thing.


----------



## wvgca (Jan 21, 2013)

on an atlas HO turn table. a DC motor is used with a rather large gear reduction ... the turntable actually hesitates when the tracks are lined up, not because the motor stops, but because the gear train has a holding position that is fairly wide in magnitude of time ... there is a 'rest' position in the gear train that allows the tracks to line up while the motor coasts to a stop, or continues revolving to the next position


----------



## gregc (Apr 25, 2015)

wvgca said:


> on an atlas HO turn table.


sounds like Atlas turntable has fixed positions.


----------



## wvgca (Jan 21, 2013)

gregc said:


> sounds like Atlas turntable has fixed positions.



yes, it does ...
they are centered on the 'wide' areas of the gear train ..
it requires rudimentary timing when its dis-assembled


----------



## Lemonhawk (Sep 24, 2013)

Well I tried to search for the name of the gear train mechanism that is employed on the atlas turntable, but did not find it. If the DC motor is run continuously it still stops at each index point and the pause in motion allows plenty of time to stop the motor, when it finally reaches the intended position. Some modelers bury the Atlas mechanism below their normal looking turntable to take advantage of its indexing mechanism. Its an exceedingly simple gear mechanism that is used.


----------



## wvgca (Jan 21, 2013)

Lemonhawk said:


> Well I tried to search for the name of the gear train mechanism that is employed on the atlas turntable, but did not find it. If the DC motor is run continuously it still stops at each index point and the pause in motion allows plenty of time to stop the motor, when it finally reaches the intended position.





i -think- it's called a geneva gear train, or movement ... not sure about that ? and yes , the motor runs while the gear train 'pauses' at each index position ..i have a couple of those atlas turntables, they drive some users crazy because they stop for a moment at each index, plus they are usually fairly noisey ..


----------



## gregc (Apr 25, 2015)

the walthers turntable is more conventional


----------



## gunrunnerjohn (Nov 10, 2010)

That scheme makes sense and it allows them to have a very sloppy stop and still keep the TT in exact registration. I couldn't see how they could control it that exact with trying to stop a DC motor at exactly one sensor count.


----------



## wvgca (Jan 21, 2013)

the walthers uses the same style as the atlas, with a DC motor ??
i've never seen a 'live' walthers ..but how are they 'more conventional' ?


----------



## gregc (Apr 25, 2015)

conventional in that tracks can be arbitrarily located around the turntable, not at fixed locations. It doesn't use a Geneva gear


----------

