Arduino Forum

Using Arduino => Motors, Mechanics, and Power => Topic started by: sandhuatard on Oct 12, 2011, 01:56 am

Title: Multiple turn motor position control
Post by: sandhuatard on Oct 12, 2011, 01:56 am
Hi,

At the outset, I am posting in this forum because members here seem to have the best grasp on stepper motor control drivers. I need to drive a vacuum variable capacitor with a motor. From it's lowest to highest capacitance, the capacitor goes through several turns. Trying to rotate the rotor of the capacitor beyond those limits can damage it. So my first requirement is to limit the number of turns on either side given the motor is calibrated to start at the middle. For the same constraint, another question is if the driver circuit "knows" how many turns and degrees, can the information be retained when the circuit is powered off?

Thanks.
Title: Re: Multiple turn motor position control
Post by: RuggedCircuits on Oct 12, 2011, 02:03 am
There is a difference between a motor "driver" and a "controller". The driver is usually un-intelligent, converting logic signals to high voltage/current necessary for the motor. The controller is where the brains are. In the Arduino world the controller is usually the Arduino itself, which has non-volatile storage in the form of EEPROM. Drivers generally do not keep track of absolute position.

So it is possible that an Arduino + stepper motor driver (like ours (http://ruggedcircuits.com/html/rugged_motor_driver.html) or others) can meet your need. You will have to write a sketch for the Arduino that keeps track of the position and occasionally updates the EEPROM so that when the power is lost, the position is retained. You should not update on every step as that could burn out the EEPROM (it's only rated for ~1million erasures and you can easily reach that if you write it on every step). But writing once every 10 seconds or so should be fine.

Alternatively, you can keep track of absolute position using an absolute encoder but that is starting to run into some big money. Avago has some that output SPI-type data, but they are >$20.

--
The Ruggeduino (http://ruggedcircuits.com/html/ruggeduino.html): compatible with Arduino UNO, 24V operation, all I/O's fused and protected
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 12, 2011, 02:09 am
Thanks. I think you answered my fundamental query that such control/logic is possible. Sorry, for getting the technical terms wrong. I will research the Arduino option further.
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 12, 2011, 02:32 am
A quick look at the encoder option seems to suggest that since the encoder records only 0 to 360 position information, the absolute position of the capacitor would still need to be recorded on some sort of EEPROM. Right?
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 12, 2011, 05:24 am
Found an interesting way to keep track of number of turns/position.
http://www.migamotors.com/Media/MigaOne-Arduino-v2c.pdf

From what I understand, a pot shaft is coupled to the motor. Voltage drop across pot is fed back to arduino through a ADC that translates to a value between 1 to 1023 and that gives the motor position. Am I understanding is correctly? Sorry, not really an electronics person, though can write C/perl :)

Does this look like a practical solution? Only hitch is my capacitor shaft turns 73 times between it's lowest and highest capacitance :)
Title: Re: Multiple turn motor position control
Post by: cr0sh on Oct 12, 2011, 08:10 am
You should not update on every step as that could burn out the EEPROM (it's only rated for ~1million erasures and you can easily reach that if you write it on every step). But writing once every 10 seconds or so should be fine.


While in practice you shouldn't constantly update the EEPROM as it -does- have limited write cycles, people have done destructive tests of this nature, and it turns out that it really isn't as terrible as most would think. Not that, if you did do this, that you could really trust it in the long term to work - but it isn't "poof-dead" after 1 million writes...

:)
Title: Re: Multiple turn motor position control
Post by: cr0sh on Oct 12, 2011, 08:16 am

Found an interesting way to keep track of number of turns/position.
http://www.migamotors.com/Media/MigaOne-Arduino-v2c.pdf

From what I understand, a pot shaft is coupled to the motor. Voltage drop across pot is fed back to arduino through a ADC that translates to a value between 1 to 1023 and that gives the motor position. Am I understanding is correctly? Sorry, not really an electronics person, though can write C/perl :)

Does this look like a practical solution? Only hitch is my capacitor shaft turns 73 times between it's lowest and highest capacitance :)



Have you thought about using the changing value of the capacitor as the means to measure its position?

There are various methods, but a common one involves measuring the time it takes to charge via a resistor (RC time constant, IIRC):

http://www.picotech.com/experiments/capacitor/capacitor.html
http://www.nxp.com/documents/application_note/AN449.pdf

:)
Title: Re: Multiple turn motor position control
Post by: cr0sh on Oct 12, 2011, 08:28 am
Regarding my last post - check out this thread: http://arduino.cc/forum/index.php/topic,71921.0.html

It may be helpful...
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 12, 2011, 09:21 am
cr0sh, I appreciate your responses. The idea of measuring capacitance to determine capacitor position is simple and straight-forward but in my application, it may not apply or be difficult. I think explaining the application will help. The vacuum variable capacitor is in parallel with a 4' diameter copper pipe loop that behaves as a HF transmitting antenna. The antenna is to be placed outdoors and it is desirable that it be portable and not require a computer to control.

The capacitor, say at 100W RF power, can develop ~4kV of voltage and ~30A of current. The loop antenna is very sensitive to ohmic losses such that even as much as ten milliohms of loss can cause 5-6% drop in antenna efficiency. Introducing a capacitance measuring circuit across the capacitor would mean using some sort of relays to disconnect the capacitor from the loop and connect to measuring circuit. At these currents and voltages, relays will add losses and increase costs.  Also, if the measuring circuitry is exposed to such high voltages, say when discharging the capacitor, it can destroy the measuring circuitry.

So I think a mechanism that mechanically couples with the capacitor, IMHO, is better suited to track rotations. This is what I understand from researching various options so far. Since I am not an electronics person, I could be way off the mark here so would appreciate corrections  :)

Title: Re: Multiple turn motor position control
Post by: Grumpy_Mike on Oct 12, 2011, 01:58 pm
Quote
Only hitch is my capacitor shaft turns 73 times between it's lowest and highest capacitance

That is your main snag with using any sort of pot or rotary shaft encoder.
What I would do is to set up another motor (or a mechanical connection to your shaft) that consists of a threaded rod with a captive nut on the end. Every time you pulse your capacitor's stepping motor you step this slave motor.
Then arrange limit switches on this to detect the both ends of the travel.
It's like having a mechanical memory.
Title: Re: Multiple turn motor position control
Post by: ckiick on Oct 12, 2011, 05:15 pm
Use gears!
Use a couple of gears between the capacitor knob and the potentiometer to reduce the number of turns.  Then you can use a 10-turn potentiometer (which are fairly easy to find) and read it via analogRead().
Title: Re: Multiple turn motor position control
Post by: zoomkat on Oct 13, 2011, 12:30 am
Quote
From it's lowest to highest capacitance, the capacitor goes through several turns.


what level of resolution is needed. Servos might be an answer. There are winch servos that make several turns, and gearing up of a standard servo might be an option.
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 13, 2011, 01:48 am

Use gears!
Use a couple of gears between the capacitor knob and the potentiometer to reduce the number of turns.  Then you can use a 10-turn potentiometer (which are fairly easy to find) and read it via analogRead().


I have seen 10-turn pot based rotation sensors. The cap has 73 turns but let's just say 70. The capacitance range is 7.5-350pF so if the change is linear, we have ~4.9pF / turn. On lower broadcast frequencies, at around 7 Mhz, the required stepping is 1pF so we want the capacitor shaft to be turned in 1/5th or 72 degree turns. Cap to pot, that is 70 to 10 turns, let's say we use a 7:1 reduction gear. Now, pulse the motor to turn the cap 72 degrees. That should turn the pot about 10 degrees. Is that sufficient change in resistance to cause a measurable voltage change for the ADC?

@Grumpy_Mike - With the limit switch arrangement, how do I remotely read the capacitor position?

Title: Re: Multiple turn motor position control
Post by: marzetti on Oct 13, 2011, 06:38 am
Mike-
Are you proposing using the second motor as an encoder?

I would think if you used a stepper motor there would be no need for an encoder. With such a light load there should be no problem with missed steps. It would be necessary to have a homing routine to establish the initial position at startup, though. Limit switches would be a good idea to prevent damage to the capacitor in case of an overtravel event.
Title: Re: Multiple turn motor position control
Post by: Grumpy_Mike on Oct 13, 2011, 09:46 am
You read the capatance by knowing how many steps you have given the motor. The only problem is having a reference point for your motor as once you loose the power you loose the knowledge of the absolute position. A simple mechanical stop won't work as you have multiple turns, therefore you need to translate something into a reference point that you can detect.
You could do this with gears, or a mechanical analog like I suggested before.
Title: Re: Multiple turn motor position control
Post by: marzetti on Oct 13, 2011, 02:30 pm
OK, I see the problem. What if you introduced a threaded shaft with a moving nut between the stepper motor and the capacitor to trip the home switch? The motor homes to said switch on start up giving an initial position just as a CNC machine would do.
Title: Re: Multiple turn motor position control
Post by: marzetti on Oct 13, 2011, 03:27 pm
Another alternative would be to use a double shafted motor and connect a 10 turn pot to one shaft. No gears needed.
Title: Re: Multiple turn motor position control
Post by: Grumpy_Mike on Oct 13, 2011, 03:44 pm
So how is a 10 turn pot going to help when the total travel of this motor is 70 turns???
Title: Re: Multiple turn motor position control
Post by: dc42 on Oct 13, 2011, 04:19 pm
Presumably, trying to move the capacitor beyond the limits of its travel will only damage it if you apply excessive force. Can you limit the stepper motor drive current so that the force is sufficient to move the capacitor but insufficient to damage it? If so, you can reset the system to a known state by driving it in one direction long enough so that you know it has reached the end of its travel (this is what some cheap inkjet printers to to reset the carriage to a known position). After that, you can keep track of the position by writing it to EEPROM, perhaps when you sense that power is about to go down (e.g. by monitoring the voltage on a capacitor on the input side of the voltage regulator).
Title: Re: Multiple turn motor position control
Post by: Grumpy_Mike on Oct 13, 2011, 04:27 pm
Quote
If so, you can reset the system to a known state by driving it in one direction long enough so that you know it has reached the end of its travel

For 70 turns of the motor! That is a long time for the system to take mechanical abuse. You would be better off trying to monitor the current and seeing when it reaches its stalled value.

Quote
by writing it to EEPROM, perhaps when you sense that power is about to go down

Sensing the power is about to go is an entire project in itself. I have done many of these when designing set top boxes and it is not easy unless the power supply is integrated into the system. I actually hold a patent (well it is my companies IP as I was working for them at the time) for a novel way of detecting a power outage on a set top box in order to write things to flash.
Title: Re: Multiple turn motor position control
Post by: dc42 on Oct 13, 2011, 04:48 pm

For 70 turns of the motor! That is a long time for the system to take mechanical abuse. You would be better off trying to monitor the current and seeing when it reaches its stalled value.


I've done that for a DC motor, but never for a stepper motor. How practical is it? Does the current draw of a stepper motor vary significantly with rotation speed and/or load? I would have though that the average current wouldn't vary much, although the shape of the current waveform in each winding should vary with rotation speed. I take your point that 70 revs is a long time - maybe an optical sensor producing one or more pulses per revolution would be an alternative way of detecting that the end stop has been reached.


Sensing the power is about to go is an entire project in itself. I have done many of these when designing set top boxes and it is not easy unless the power supply is integrated into the system.


What I had in mind was monitoring the voltage at the input to the voltage regulator through a voltage divider - which means that at least the regulator is built in to the system, although the power supply could be a wall wart.
Title: Re: Multiple turn motor position control
Post by: Grumpy_Mike on Oct 13, 2011, 05:10 pm
Quote
What I had in mind was monitoring the voltage at the input to the voltage regulator through a voltage divider - which means that at least the regulator is built in to the system, although the power supply could be a wall wart.

Yes you can do that and it is the basis of many designs.  However, the tricky part is that the hold up times are determined by the reservoir capacitors, these tend to be bigger on the unregulated side than the regulated side. This means that when the mains is disconnected it holds up the voltage for a longer time, then when it sags it drops very quickly. What you need to do is to arrange a voltage comparator on the input side of the regulator that triggers an interrupt on the processor that then saves the parameters. In general with that sort of arrangement you had in the order of 50mS to do stuff. My patent involved detecting the actual mains and that gave a whopping 180mS warning. 
Title: Re: Multiple turn motor position control
Post by: Erni on Oct 13, 2011, 05:40 pm
Here is my idea
Take some resistor thread. In one ende connect a spring . As the motor turns the thread will be wound/unwound from the motor.
Now you can measure the resistans between the spring and the sensor placed halfway down the resitor thread.

I can see it is unpractical: if the diameter of the motorshaft is 10mm the length of the thread will be almost 2,5m with 80 turns. But that can be solved with more wheels, where the resistor thread could be zigzagging.



Title: Re: Multiple turn motor position control
Post by: marzetti on Oct 13, 2011, 08:43 pm
Quote
So how is a 10 turn pot going to help when the total travel of this motor is 70 turns???


Ooops! I missed that.  :smiley-red:
Title: Re: Multiple turn motor position control
Post by: zoomkat on Oct 13, 2011, 08:57 pm
Too much "hanger flying". The OP needs to clearly restate the goals of the project and clearly describe the mechanical requirements of his gizmo.
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 14, 2011, 01:15 am

Too much "hanger flying". The OP needs to clearly restate the goals of the project and clearly describe the mechanical requirements of his gizmo.


Sorry guys for being late to the discussion. I was thinking the same thing, clearly stating requirements just as for any project.

Problem description: Capacitor shaft turns 70 times between lowest and highest capacitance. It is coupled to a copper pipe loop for use as a transmitting antenna. Voltages/current developed are as high as 4kV and 32A and antenna is extremely sensitive to ohmic losses. Cap shaft has a hard stop at one end and pushing beyond the limit at the other end may knock the shaft lose from internal plate couplings. Also, the capacitor is expensive - USD 200-300 - so tolerance to cap damage is very low. Capacitor range is from 7.5 to 350 pF - roughly 4.9pF per rotation. The antenna is sensitive to 1pF changes in capacitance.

Requirements:
1. Remotely rotate the capacitor shaft.
2. Stop the capacitor from hitting ends on either side to prevent capacitor damage. If #3 is accurate/reliable enough, we may rely on the operator (yours truly) to not turn the shaft beyond predetermined turn numbers.
3. Remote visual tracking of shaft absolute position - both - the turn number and angle (0-360) to allow the operator to figure out which direction to turn the shaft in for matching to a certain frequency.
4. Turn the shaft to allow for 1pF capacitance changes, that is, assuming ~5pF / rotation, comes to a minimum of 72 degree stepping. For safety, lets say 60 degrees.
5. Weather-proof the components since the antenna is to be placed outdoors.
6. No computer (as in a laptop/desktop) control since the antenna is expected to be portable.
7. Cap shaft control mechanism should not connect to the antenna/capacitor electrically in anyway to avoid changing antenna characteristics.

Did I miss anything? Hope not. I suggestion I got was connect identical motors to the same driver. Couple the cap shaft to one via appropriate gear to allow for 1pF stepping and couple the other motor with the exact same gear to a mechanical counter. Identify the lowest and highest counter readings for cap shaft's 70 turns. Is it practical?

Thanks! Really appreciate all the responses to the thread.
Title: Re: Multiple turn motor position control
Post by: zoomkat on Oct 14, 2011, 01:35 am
How much force is required to turn the shaft (can you turn it with two fingers)? Might be possible to use a servo to turn the shaft so you would have simple position control. Couple of ways using gearing and such that might work.

http://www.servocity.com/html/gears___sprockets.html
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 14, 2011, 08:26 am

How much force is required to turn the shaft (can you turn it with two fingers)? Might be possible to use a servo to turn the shaft so you would have simple position control. Couple of ways using gearing and such that might work.

http://www.servocity.com/html/gears___sprockets.html


Yes, I can easily turn the shaft with two fingers or index finger and thumb. Not sure how to measure required force.
Title: Re: Multiple turn motor position control
Post by: Grumpy_Mike on Oct 14, 2011, 05:01 pm
I would still suggest a stepping motor, this will give you the precision you need and as the load is light there should not be any worry about needing positional feedback, you can just use dead reckoning.

The only difficulty is in determining a reference position for this system. There have been many suggestions for this, however as you have the physical system then you can determine what would be the easiest way to do this.
It could be an optical slot switch, a micro switch or even a proximity switch sensing something about the thrust of the capacitor core.

The only thing you omitted is the speed you want to change this tuning at. However, I suspect this is slow given the application.
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 15, 2011, 07:43 am

I would still suggest a stepping motor, this will give you the precision you need and as the load is light there should not be any worry about needing positional feedback, you can just use dead reckoning.

The only difficulty is in determining a reference position for this system. There have been many suggestions for this, however as you have the physical system then you can determine what would be the easiest way to do this.
It could be an optical slot switch, a micro switch or even a proximity switch sensing something about the thrust of the capacitor core.

The only thing you omitted is the speed you want to change this tuning at. However, I suspect this is slow given the application.


After looking at quite a few options, I am leaning towards stepper motors now. As you said, it gives the right control over motion.

Here is what I am thinking, please correct me if I am wrong. A controller like this:
http://www.electronickits.com/kit/complete/motor/CANUK1130.htm

Seems to give control over stepping size with variable frequency. Along with that, any stepper motor with sufficient torque should do. Can I connect two motors in parallel to the signal from this controller? One inside the shack connected to some sort of counter and the other outside that drives the capacitor.

Also, how do I dial the number of steps I want the motor to make in one go?
Title: Re: Multiple turn motor position control
Post by: marzetti on Oct 15, 2011, 08:53 am
The controller you linked to is for a brushed DC motor. You would need a stepper driver such as this:
http://www.sparkfun.com/products/10267 (http://www.sparkfun.com/products/10267). It works by using step and direction signals generated by the Arduino. Check the Playground wiki for more info. This is also a good tutorial: http://danthompsonsblog.blogspot.com/2008/09/easydriver-v31-tutorial.html (http://danthompsonsblog.blogspot.com/2008/09/easydriver-v31-tutorial.html).
The second motor is really not necessary. Most stepper motors are 200 steps per revolution so full travel on your capacitor would be 14,000 steps.
A good input device would be a rotary encoder with a display of some sort (LCD, 7-segment LED?) to indicate position. Once you had everything calibrated it may even be possible to use "presets" to move it to a predetermined frequency using a keypad.
Title: Re: Multiple turn motor position control
Post by: dc42 on Oct 15, 2011, 10:20 am
Quote
Cap shaft has a hard stop at one end and pushing beyond the limit at the other end may knock the shaft lose from internal plate couplings.


Surely you can choose the stepper motor current so that its torque is sufficient to rotate the shaft but not enough to damage anything when it reaches the hard stop? Then you can get the reference point by moving it to that end. To speed up the process, attach a perforated disk to the shaft and use an opto sensor to detect when it is rotating, or a magnet and Hall sensor. Even simpler, have a manual calibration button, which turns the capacitor towards the hard stop (perhaps at reduced current), then when you see it isn't moving any more, you release the button.

Once you know the hard stop has been reached, you can count steps to keep track of the position, and save the current position in EEPROM when appropriate.
Title: Re: Multiple turn motor position control
Post by: MarkT on Oct 16, 2011, 11:34 am
Quote
Have you thought about using the changing value of the capacitor as the means to measure its position?


I read this as a joke ;)   But then I know what a vacuum variable capacitor is for...
Title: Re: Multiple turn motor position control
Post by: sandhuatard on Oct 17, 2011, 11:17 pm
Thanks @Yankee. Good info there.

@dc42 - The issue with this particular capacitor is that one end has a hard stop but the other end does not. At the other end, the cap shaft feels as if it has come lose from sort of internal coupling. Not a good feeling and since it is a Russian made capacitor, I don't have a manufacturer who can give me more info about the cap internal mechanics.

Thanks all for the responses. I think once I am done testing/tweaking the antenna, I will pursue the stepper motor + Arduino + rotary encoder with a LCD display idea. Hopefully, I will replace the current capacitor with a smaller/lighter capacitor. The current one has a glass shell and weighs almost 4.6 pounds. I can do with lower voltage rating and that should get me a capacitor that is smaller and more manageable :)

Title: Re: Multiple turn motor position control
Post by: marzetti on Oct 18, 2011, 05:05 am
I also meant to mention Grumpy_Mike's excellent tutorials on rotary encoders and stepper motors (and a lot of other useful stuff): http://www.thebox.myzen.co.uk/Workshop/Introduction.html (http://www.thebox.myzen.co.uk/Workshop/Introduction.html).
Once you get everything working come back and show us some pics. That capacitor sounds awesome!
Title: Re: Multiple turn motor position control
Post by: Grumpy_Mike on Oct 18, 2011, 11:50 am
Quote
I will pursue the stepper motor + Arduino + rotary encoder with a LCD display idea.

I can't see what the rotary encoder brings to the party, there are just incremental devices and you have the same problem you have when just counting stepping motor pulses. That is there is no absolute point of reference.

The only way to use one would be to gear the motor down say 80 to 1, so that the whole of the capacitor movement is condensed into one revolution.  Then use an absolute position rotary encoder, but be warned these are eye wateringley expensive.
Title: Re: Multiple turn motor position control
Post by: marzetti on Oct 19, 2011, 08:18 am
I believe he is talking about using a rotary encoder as an input device not position feedback.
Title: Re: Multiple turn motor position control
Post by: dc42 on Oct 19, 2011, 10:36 am

@dc42 - The issue with this particular capacitor is that one end has a hard stop but the other end does not. At the other end, the cap shaft feels as if it has come lose from sort of internal coupling. Not a good feeling and since it is a Russian made capacitor, I don't have a manufacturer who can give me more info about the cap internal mechanics.


I was proposing that you drive the motor to the end with the hard stop to establish an end point, then count stepper pulses from there to track the position after that. This will allow you to avoid turning the shaft too far the other way, provided that your mechanism for counting stepper pulses is reliable, and that the stepper always moves when pulsed if it is not at the end stop.

I suppose there is nothing you can see through the glass envelope when the cap is near the other end of its travel, that would allow you to provide optical detection of appropaching the other end point?
Title: Re: Multiple turn motor position control
Post by: Flywheel on Oct 19, 2011, 10:54 am
To find out the exact number of turns you could use a Hall type of magnetic sensor. A small magnet is attached to the shaft and the sensor detects everytime it passes.

The challenge is to somehow permanently save it's position, I'd prefer some way of initialising the position to a 'start' setting at reboot/power loss instead of using the memory. I'd prefer some mechanical way to initialise it's start position. My guess is the hard stop on one end is the way to go, you can turn always towards the hard stop, then start counting from there.