Author Topic: Stepper Motor Control  (Read 12109 times)

Offline catceefer

  • Jr. Member
  • **
  • Posts: 23
Stepper Motor Control
« on: April 21, 2015, 03:31:52 AM »
I wonder whether anyone can help? I have never had anything to do with stepper motors and would appreciate some basic guidance or link to an idiot's guide. I have been looking at the motors on e-bay and see that some come with a control board, others do not. My questions are:

- do I need a board?
- if I use a board, how do I programme it?
- if I use a Raspberry Pi or Arduino, do I need the board still?

To put the question into context, I wish to use the motor to move a lever forwards and backwards a set amount every minute.

All really basic questions, I know, but I need to start somewhere.

Thank you.

James.

Offline Will_D

  • Hero Member
  • *****
  • Posts: 668
  • Country: ie
    • National Homebrew Club of Ireland
Re: Stepper Motor Control
« Reply #1 on: April 21, 2015, 04:00:23 AM »
Stepper motors usually need to separate boards (Ok they can be built as one)

The first board is the motor driver board. It drives the motor's coils "as required" (see next point) . It requires a high capacity power source like 12v at 2amps all the way up for very big (48V at 10 amps) steppers. It contains some large semi conductors that may need heat sinks.

The second board supplies the "As required" information. This supplies the driver board with digital (usually 5v) signals: Pulse, Direction, Enable. These signals are generated either by a simple board (like a simple speed controller (pot) and direction (switch)).

However most boards are some form of process control computer like the Arduino or some other PIC/PLC set-up.

Then you "just" write the software to do what you want. 
Engineer and Chemist to the NHC.ie
http://www.nationalhomebrewclub.ie/forum/

Offline vtsteam

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6466
  • Country: us
  • Republic of Vermont
Re: Stepper Motor Control
« Reply #2 on: April 21, 2015, 07:56:50 AM »
I 'm sure you can look up "stepper motor" on the internet and get a better and more in depth definition than we can provide here. What it seems you are asking is what do you need for gear to fit a specific application. As in any practical engineering question, the specifics of what you want to do will decide what you need to achieve it.

A lever moving back and forth a set amount every minute is so vague that there is no answer. How much force is required? How much distance must it move? Is the movement periodic, uninterrupted, and independent of circumstance?

The answer could easily be that you don't need a stepper motor and computer and drive circuitry at all, you need a motor and a timer, or a solenoid and a timer, or even just a synchronous motor and linkage. Any of the above could be the size of a few gram pager motor, or weigh hundreds of kg. depending on what lever you're talking about.

In other words, it's important to have clear in mind what you want to do first in specifics, before researching the means to do it. If you start out just choosing a means, you'll make finding a good solution hard for yourself. The great attraction of the internet is an exposure to advances in affordable cutting edge digital technology. The big problem is thinking therefore that it is the the only way, or even the best way to achieve a simple result.

If you said for instance,I'd like to wave the wing of a copper garden dragon weighing 2 pounds about 3 inches once a minute, somebody here might say, try this timer and this windshield wiper motor and this speed reducer, etc... :beer:
I love it when a Plan B comes together!
Steve
https://www.youtube.com/watch?v=4sDubB0-REg

Offline catceefer

  • Jr. Member
  • **
  • Posts: 23
Re: Stepper Motor Control
« Reply #3 on: April 21, 2015, 05:52:51 PM »
Looking back, it was a badly phrased question: I should not have rushed it.

A little more detail. I am very much at the planning stage, but am doing some drawings for a clock with some animated figures. Rather than using springs or weights to drive the clock mechanism, I am looking at a version of this lever-operated escapement https://www.youtube.com/watch?v=hnko9fZRO-w.  I plan to modify it a little by adding a long bar and having a figure pull the lever to drive the clock.

The design as shown uses a solenoid, but this will give a very abrubt movement. I want something a little more controlled so that the figure can be seen moving. I have considered a number of ways to do this, but felt that a stepper motor would be the most controllable. However, I can see how a radio control-type servo may work. Any suggestions would be welcome.

The copper dragon is still ongoing, the clock being planned for its completion. I have made the parts for an oxy-propane torch, as raised in an earlier post, but as waiting for my brazing kit to be returned from a loan so that I can assemble it.

Regards,

James.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Stepper Motor Control
« Reply #4 on: April 21, 2015, 06:28:01 PM »
Catceefer - I've done a few projects with steppers and Arduinos now so can hopefully help a little. In a basic sense, the stepper motor driver (or board as you call it) detects pulses along the pulse line and steps the motor by a certain rotation each pulse. There is also a direction line, pull this line high to rotate the stepper one way and low the other.

You would need your Arduino to pulse high and low and high and low for the direction and still need a driver to detect the pulses and run the motor. You can build drivers but for the cheap price of something like a tb6540(?? Forgot the number??) I never thought it was worth the hassle.


You could get it running with very little code. In lay code..

If buttonDirection   #So keep direction button pressed to go one way, release for the other way
Pin 1 = 1
Else             /pin 1 connected to direction. High one way, low the other way
Pin 1 = o

While (step button pressed) #start moving!!
Loop 10 times #this isn't code, you'd need to do a count
Pin 2 = 1
Delay (10)    #pin 2 is connected to the pulse on the driver and just goes high low ten times - motor moved 10 steps
Pin 2 = 0


That's just a load of nonsense code but you get the idea. Best to out the steps in an interrupt but the delay works, for definate, because I have done it.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Stepper Motor Control
« Reply #5 on: April 21, 2015, 06:30:08 PM »
...and just to add my two penneth to the functionality of the concept -. It won't keep time at all!! :-) I made a binary clock many years ago using a pic with a crystal 32768hz oscillator, even my code was causing the time to go out badly with no moving parts, just Leds! Good luck and hope you prove me wrong. It'll certainly look smart.

Offline vtsteam

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6466
  • Country: us
  • Republic of Vermont
Re: Stepper Motor Control
« Reply #6 on: April 21, 2015, 07:24:36 PM »
Well that's a little easier to talk about, but still no specifics........

"The copper dragon is still ongoing, the clock being planned for its completion. "

still doesn't say how big this clock (or dragon -if it is being moved by the clock) -- is.

An R/C servo (and I've used alot of them) might not last very long under continuous use in a clock. They've got tiny potentiometers in them, and 100 hours flight time per year would be heavy usefor them.

As one possibility, If you're going with a motor anyway, why not consider a synchronous motor? You do have to reset the clock if the power goes out, but otherwise they will keep good time because the power line is adjusted in frequency to do just that. They were actually used in electric clocks and clock radios. Those were meant for continuous use over long periods of time.

You could use a cam to provide some pretty complex movements for your figure -- and easily adjustable timing fairly simply. Think of the amazing cam drives on automatons that were traditionally used. This would be very simple compared to those. And it is a mechanism in sync with the history of clockwork.
I love it when a Plan B comes together!
Steve
https://www.youtube.com/watch?v=4sDubB0-REg

Offline catceefer

  • Jr. Member
  • **
  • Posts: 23
Re: Stepper Motor Control
« Reply #7 on: April 22, 2015, 02:31:22 AM »
Thank you all for the advice, which has given me plenty of food for thought.

Raynerd: thank you for the sample code, which makes perfect sense. I shall have to have a little think, though, if your experience showed that it is difficult to get it to keep time.

Vtstream: a little more context. The dragon, which is about 6' long and 3' 6" tall, is a totally separate, static project. I am nowhere near a final decision, but I envisage this clock to be a large wall clock for indoor use in a house. Even though I only wish to pulse the mechanism once per minute, it does sound like a servo could give up the ghost after a month or so of use. I shall have a think about synchronous motors or, perhaps, traditional clockwork after all.

Regards,

James.

Offline vtsteam

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6466
  • Country: us
  • Republic of Vermont
Re: Stepper Motor Control
« Reply #8 on: April 22, 2015, 10:05:56 AM »
Just a mention re. single board computers keeping good time.....  For this kind of task there's usually a Real Time Clock (RTC) circuit in more complex boards, or in a peripheral. A small computer board could function as a clock movement controller, but it may take special interrupt programming and possibly off-loading tasks to specialized components rather than having a single processor try to do everything.

I think the physical bulk of what's needed to do it, besides the programming and electronic issues would argue in favor of a synchronous motor and cam. On the one hand you have just a mains suitable motor, on the other, a stepper motor, a stepper driver, a stepper power supply, a single board computer and any auxiliary controls (buttons, display, etc.) you think necessary, plus lots of wiring.

However, there's one great argument for a computer/stepper version: if you want to dig into digital electronics and programming to learn more about it. Or if it just simply appeals to you! If that's part of the equation, sounds like it would be an instructive and interesting project.  :thumbup:
I love it when a Plan B comes together!
Steve
https://www.youtube.com/watch?v=4sDubB0-REg

Offline philf

  • Hero Member
  • *****
  • Posts: 1107
  • Country: gb
Re: Stepper Motor Control
« Reply #9 on: April 22, 2015, 11:12:07 AM »
I think a single board computer and stepper drivers is overkill for this application.

The video you linked shows the clock working very much like a slave clock for a master clock. These are nearly always driven by a solenoid which as you point out is abrupt and noisy.

I agree with Steve that the simplest solution would be to use a 1 rpm synchronous motor and design a cam to give the required movement over a fraction of one revolution.

The mains frequency is fairly tightly controlled and I believe over a 24 hour period is very good.

One of my master clocks always keeps the main spring permanently wound up by a cam on a 2 rpm synchronous motor.

Cheers.

Phil.

Phil Fern
Location: Marple, Cheshire

Offline vtsteam

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6466
  • Country: us
  • Republic of Vermont
Re: Stepper Motor Control
« Reply #10 on: April 22, 2015, 01:09:12 PM »
Yes Phil, I think traditionally here at least the mains cycle count for the day was tweaked at night by the utility with small adjustments to frequency so clocks and other synchronous devices would stay on time. Not sure of that -- just some information remembered from long, long ago, source unknown. Could be non-urban legend.  :)

Easy to do if you have a standard clock (or clock signal) and a synchronous clock on the generator line. Just alter the line frequency (gen speed) until they match up again each night at say 2 A.M. local. That's in the olde days....now I imagine computers handle it in real time.
I love it when a Plan B comes together!
Steve
https://www.youtube.com/watch?v=4sDubB0-REg

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Stepper Motor Control
« Reply #11 on: April 22, 2015, 01:51:03 PM »
Here in the UK  the number of cycles in a day in monitored and it is one grid parameter that is closely controlled, as you say, over 24 hours. I had a suite of Ferranti Argus 500 computers that I was responsible for at Park Street National Grid Control in London back in the '80's and '90's, that compared cycle count with a radio clock synchronised to a Swiss standard. I expect that they are long gone now - they moved control to Winersh in Berkshire, but will have something similar in whatever control system they are using nowadays.
Andrew Mawson
East Sussex

Offline John Hill

  • The Artful Bodger
  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2016
  • Country: nz
Re: Stepper Motor Control
« Reply #12 on: April 23, 2015, 02:19:02 AM »
Hi James, your enquiry has reminded me of a long forgotten project which never got past the pondering stage!

In my scheme which was for a clock to put on the top of the house (like the one on the local Post Office)  I considered using a windscreen wiper motor geared 60:1 to the minute hand of the clock face and of course a further 12:1 for the hour hand.

As you probably know a typical windscreen wiper motor has a worm driven wheel which carries a circular contact with a short break in it.  The motor is wired to run when the dashboard switch is 'on' in which position the motor will run regardless of the position of the circular contact but when the switch is turned 'off' the motor continues until the break in the contact ring is encountered (i.e. 'parks' the wipers).

In my scheme software on a PC would raise one of the modem control lines on a serial port once per minute for a fraction of a second,  the modem control line would control a 'solid state switch' which would take the place of the dashboard switch in the wiper motor circuit.

Not clever, no real electronics involved, but I did think it was a robust way of making a clock big enough to impress neighbours driving down the street.

Of course my software would check an on-line reference clock at intervals and one a year stop for a whole hour or go double speed to 'skip' an hour according to the requirements of daylight saving time.

Regarding solenoids, here is a thread where I experimented with an idea to make a 'long stroke' solenoid with power throughout the stroke rather than having all the force appearing near the end of the travel..

http://madmodder.net/index.php/topic,6119.msg65462/topicseen.html#msg65462

John
From the den of The Artful Bodger

Offline catceefer

  • Jr. Member
  • **
  • Posts: 23
Re: Stepper Motor Control
« Reply #13 on: April 23, 2015, 02:45:21 AM »
Thank you for all of your very helpful replies, which have given me plenty of food for thought. One thing that I had not realised before posting this question was just how much power would be required by the Arduino itself and the stepper motors. In my ignorance, I had envisaged a few AA batteries at the most.

John: I shall have a read of your solenoid thread. Years ago, I used to work on Strowger telephone equipment where we used slugged relays to delay either the activation or the release of the mechanism. The trouble is: it is thirty years ago now and I have forgotten most of what I learnt there. I could, though, put a small capacitor across the solenoid to give a slow release: that would at least take out some of the abrubtness of a solenoid-operated device.

Now to find a darkened corner in which to ponder and think.............

Thank you.

James.

Offline John Hill

  • The Artful Bodger
  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2016
  • Country: nz
Re: Stepper Motor Control
« Reply #14 on: April 23, 2015, 02:48:38 AM »
James, the principle of my long stroke relay was to produce a magnet with a N pole at each end and a S pole in the middle!

The magnet is longer than the solenoid coil and the action is really the S pole moving back and forth within the coil being alternately attracted and repulsed by each end of the solenoid.

John
From the den of The Artful Bodger

Offline vtsteam

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6466
  • Country: us
  • Republic of Vermont
Re: Stepper Motor Control
« Reply #15 on: April 23, 2015, 10:31:21 AM »
Ahhh, okay so we have an additional engineering specification -- battery powered. And the original spec said conventional solenoids were out because of jerky movement. This is getting tough!

I'm going to say you need very low mass for the moving figure, a crystal oscllator, divider, and an output component to drive the motor (jfet?) --- and a very low power low speed brushless motor, maybe something even that you wind yourself. I imagine a slow rotary solenoid or semi-motor with a stop and a spring/elastic return might even be the deal.

I wouldn't use a computer, since the oscillator and divider circuit it would need to have (or have added) are sufficient in themselves to do the job if chosen properly.
I love it when a Plan B comes together!
Steve
https://www.youtube.com/watch?v=4sDubB0-REg

Offline catceefer

  • Jr. Member
  • **
  • Posts: 23
Re: Stepper Motor Control
« Reply #16 on: April 23, 2015, 06:06:26 PM »
"I'm going to say you need very low mass for the moving figure, a crystal oscllator, divider, and an output component to drive the motor (jfet?) "

"I wouldn't use a computer, since the oscillator and divider circuit it would need to have (or have added) are sufficient in themselves to do the job if chosen properly."


This is largely the route down which I am now heading. I contacted the constructor of the clock in the video and he kindly sent me the details of the solenoid control and coding. Essentially, it uses a microprocesser that is programmed via a deleloper board. The processor is built into a circuit that uses a separate crystal chip and the relevant circuitry to supply the power. The coidng includes steps that effectively increase and decrease the power to the solenoid so that it operates and releases more smoothly and sedately. This element of the coding is not used in the clock in the video, though.

I have just ordered a developer board so that I can make a start on learning the relevant coding. I have done programming before, but in VBA and VB4, some years ago, and I have mostly forgotten it all.

Regards,

James.

Offline picclock

  • Hero Member
  • *****
  • Posts: 613
  • Country: gb
Re: Stepper Motor Control
« Reply #17 on: May 01, 2015, 03:19:20 AM »
Hi

A thought occurred to me whilst I was reading this interesting thread. It would be possible to take a standard clock/watch movement and take the actuator coil output and use it with a driver circuit to power your solenoid system. It would be relatively easy to cause the driver current to ramp up and down slowly by using a capacitor in an integrating configuration. This would be simple, cheap, and use minimal power.

Might be worth a thought

Best Regards

picclock

 
Engaged in the art of turning large pieces of useful material into ever smaller pieces of (s)crap. (Ferndown, Dorset)

Offline catceefer

  • Jr. Member
  • **
  • Posts: 23
Re: Stepper Motor Control
« Reply #18 on: May 04, 2015, 05:55:35 PM »
Piccloc,

That idea is worth a thought, I agree. I did find a thread somewhere online where someone used an old quartz clock innards to run a different clock. I have now purchased a TI Launchpad to try and programme a microprocessor chip to use in a control curcuit. If I am successful, I shall try and make the chip operate at times other than just one minute to add other features to the clock. If I fail, I shall look into your suggestion further.

Regards,

James.

Offline picclock

  • Hero Member
  • *****
  • Posts: 613
  • Country: gb
Re: Stepper Motor Control
« Reply #19 on: May 12, 2015, 02:29:47 AM »
Hi

In order to get reasonable accuracy from a small microcontroller its best to use one which has a timer/counter. This is a register which counts in response to various events, one of which is normally the cpu clock or a divided version of this. When the the timer over/under flows this then sets a flag or changes a status word which can then be cleared by your program and the appropriate action taken, like output a signal. Because the timer/counter continues counting regardless of the code running it maintains the same accuracy as the clock, which if its a 32768 Hz crystal will divide nicely into 1 second chunks.

If you try to make a timer using a timing loop in the code itself it is difficult to maintain accuracy because of the different time taken for the various code branches. Although these can be padded with nop's its unlikely to produce a good result. Also, controllers use more than one clock cycle per instruction so working out how many clocks your loop will take can be a challenging issue. For instance a conditional jump instruction could take 1-3 clock cycles depending on whether the condition was met and how far in memory the jump was.

Good luck with your programming endeavours

Best Regards

picclock



 
Engaged in the art of turning large pieces of useful material into ever smaller pieces of (s)crap. (Ferndown, Dorset)

Offline vtsteam

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6466
  • Country: us
  • Republic of Vermont
Re: Stepper Motor Control
« Reply #20 on: May 12, 2015, 09:44:08 AM »
I love it when a Plan B comes together!
Steve
https://www.youtube.com/watch?v=4sDubB0-REg

Offline kd8wdave

  • Newbie
  • *
  • Posts: 2
Re: Stepper Motor Control
« Reply #21 on: June 23, 2015, 12:32:18 PM »
I wonder whether anyone can help? I have never had anything to do with stepper motors and would appreciate some basic guidance or link to an idiot's guide. I have been looking at the motors on e-bay and see that some come with a control board, others do not. My questions are:

- do I need a board?
- if I use a board, how do I programme it?
- if I use a Raspberry Pi or Arduino, do I need the board still?

To put the question into context, I wish to use the motor to move a lever forwards and backwards a set amount every minute.

All really basic questions, I know, but I need to start somewhere.

Thank you.

James.

Hi,
Here's a pic of my Z-axis stepper controller and dual-h-bridge for driving a bi-polar stepper
either forwards or backwards. The step/dir in my case come from an Arduino UNO board
which has 'g-code' passed to it via USB port from a desktop.  My controller is a PIC based
'628A' 18 pin processor written in assembler. While my code doesn't need it, you can generate
a clock pulse from a rectifer from the 60hz line which is a precise 60 pulses/sec.

cheers

Offline DavidA

  • Hero Member
  • *****
  • Posts: 1219
  • Country: gb
Re: Stepper Motor Control
« Reply #22 on: June 23, 2015, 01:15:00 PM »
No one has mentioned creating a flow chart first to set out on paper just what is supposed to happen and when.

Or do programmers not do that these days ?

Dave.

Offline John Rudd

  • Hero Member
  • *****
  • Posts: 2525
  • Country: gb
Re: Stepper Motor Control
« Reply #23 on: June 23, 2015, 02:22:47 PM »


My controller is a PIC based
'628A' 18 pin processor written in assembler. While my code doesn't need it, you can generate
a clock pulse from a rectifer from the 60hz line which is a precise 60 pulses/sec.

cheers

Great idea.... But here in the UK, mains is 50 hz.....separate osc ? Or generate in s/w?

eccentric millionaire financed by 'er indoors
Location:  Backworth Newcastle

Skype: chippiejnr