By continuing to use this site, you agree to our use of cookies. Find out more
Forum sponsored by:
Forum sponsored by Forum House Ad Zone

Arduino project with stepper motors

All Topics | Latest Posts

Search for:  in Thread Title in  
martin perman21/11/2014 18:21:16
avatar
2095 forum posts
75 photos

Gentlemen,

As I explained recently I'm currently off work with a poorly right foot, I decided to broaden my mind and was captivated by the Arduino thread and I've treated myself to a UNO R3 and a few bits and pieces to teach myself programming and understanding electronics "Basics".

I've been reading a lot about the subject on the Arduino Website and various other sites regarding unipolar and bipolar stepper motors. There is a basic circuit on how to run a stepper using the R3 with a potentiometer but I wish to modify this by driving the motor to a specific position using a number of steps, if I'm correct the motor is driven by pulses so am I correct in thinking that if I send ten pulses it will move ten pulses.

I also wish to count the pulses to make sure it can be checked but I need to know two points a) can I use the pulse as a signal source for the count and b) can the UNO R3 run two programs at the same time i.e one program driving the motor and the other checking where it is, the programs I've looked at so far are sequential so move check, move check etc if two programs run independently you can drive the motor and at the same time check its position and use a register to stop when a position is reached, are my thought running in the right direction.

Thank you,

 

Martin P

 

Edited By martin perman on 21/11/2014 18:23:12

John Haine21/11/2014 18:38:04
5563 forum posts
322 photos

Processors can run two programmes "at the same time", but I suggest you don't worry about the complexities of multi threading and interrupts just now! If you really want to check the right number of pulses are being generated it would be easier to either generate them very slowly, make them drive an LED, and just count; or use a second Arduino as a counter.

i suggest you get a modern bipolar stepper motor and driver, you can be sure that one pulse in will move it one step.

martin perman21/11/2014 19:05:39
avatar
2095 forum posts
75 photos

John,

Thank you for your response, I should have been more specific, I work with Siemens S7 PLC's so do know that you can run several programs at the same time, my problem is that I cant see how I can do it with the Arduino UNO R3, the example I wish to modify is on their web site and doesnt use a driver as such but I would need the appropriate chip identified in the example.

Martin P

jason udall21/11/2014 20:22:06
2032 forum posts
41 photos
As I understand your request

1 most of the stepper examples use a "delay" between steps determined by comparing the milli counter with the time of the last step...
Thus having calculated the number of milliseconds between steps it twiddles its thumbs until the next one is due. ..
Thus other functions can be done during this time...
As long as they complete before the next step is due.

As to "counting" the steps emitted...well you are emitting them . Surely you know how many you have sent...
But I think some of the I/o pins are real time counters so connecting to these would allow you to count pulses even while the programmes attention is elsewhere
Neil Wyatt21/11/2014 20:45:29
avatar
19226 forum posts
749 photos
86 articles

Hi Martin,

Google 'Arduino simulator' you should be able to find something that will run your code and you can watch the state of pins change on your computer screen.

I use Atmel's AVR debugger/simulators in the same way.

Professionals would use an in-circuit emulator and JTAG to 'stop' a real chip in its tracks and read the state of the pins!

Neil

jaCK Hobson22/11/2014 17:57:02
383 forum posts
101 photos

Is the intention just to learn about low level control of steppers, or is it to achieve practical applications of steppers?

If you are really after the latter, then I would suggest getting a stepper motor driver board and use the arduino as a controller for the board. All the arduino has to do is pulse a pin for each step, and set another pin for direction. I want to get this: https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/overview. I have an earlyer version.

If you are worried about how to do multiple things at once on the arduino then again, go for the separate controller.

The arduino UNO pretty much just does one thing at a time, so if you need to do two things then you have to keep switching between them. This can get wasteful in available processing power if you constantly have to check if something needs doing. The UNO does provide you with 2 external interrupts which you can attach code that gets called only when the interrupt occurs.

I haven't see any great tutorials on how to design your code to do many things at once. You could read this thread: http://forum.arduino.cc/index.php?topic=41460.0 (i.e. search for multi-tasking or multi-threaded)

martin perman22/11/2014 18:19:33
avatar
2095 forum posts
75 photos

Jack,

Thank you for your answer, at the moment it, just to learn about the control and use, as I've said I have experience of Siemens S7 controllers and was curious if the Arduino can do multi tasking, as its difficult to determine its limitations from scratch, I assume I can do nesting of programs which will do what I require.

Once I have some idea of whats a foot I then would like to build a project for myself.

Martin P

Neil Wyatt22/11/2014 21:50:00
avatar
19226 forum posts
749 photos
86 articles

Arduinos use Atmel AVR microcontrollers. These are able to use a myriad of interrupts and timers so they are very good at multi-tasking. There is even an open-source real-time multi-thread operating system available for them. Much better to use interrupts than to nest things, and not that hard once you get the basics; you can end up with a programme that in BASIC would read something like:

REM set up interrupts & I/O here

100 GOTO 100

REM interrupt service routines here.

(if only it really was that simple!)

Neil

Roger Hart23/11/2014 09:00:58
157 forum posts
31 photos

Normally you don't bother with 'move-check' with stepper motors. If the pulse drive levels are right and the timeouts correct the stepper will 'definitely' move the right number of steps - no need to check. Usually you make the step drive routine a subroutine with a parameter - a number in a register - that says 'go this number of steps and CW or CCW'. As is said the usual way to check is with a simulator or run it slowly at first. Getting the phasing right is the usual cause of trouble.

The only excuse for checking is if lots of money or lives depend on the stepper doing its thing. For finding a definite position then some sort of sensor and a 'homing routine' is needed because steppers by themselves have no idea where they are.

Without using interrupts the timer routine can tie up the processor twiddling its thumbs, but timer routines can be designed to 'drop through' and the rest of the system designed to return control to the timer. This can work but makes precise timing difficult but probably good enough for steppers, this technique can also result in a horrible tangled program but OK for a simple job.

Start simple and work up.

KWIL23/11/2014 12:04:22
3681 forum posts
70 photos

If the stepper will "definately" move the right number of steps why are best CNC machine tools run in closed loop for positional accuracy? I am aware many are servo motor run, but not all.

Edited By KWIL on 23/11/2014 12:05:59

Neil Wyatt23/11/2014 13:38:30
avatar
19226 forum posts
749 photos
86 articles

Good point KWIL You can push servo systems harder and faster, because you don't have to worry about missed steps.- its the difference between top end kit and what mere mortals can afford.

Roger Hart23/11/2014 14:08:13
157 forum posts
31 photos

Re 'definitely', a very big question, which is why I said 'definitely' and not definitely. I could be wrong but I thought the context was a simple stepper for a hobby application in 'open-loop' ie no feedback encoders or the like.

As I am sure you know steppers have tolerances and micro-steps vary according to position and load, they are not always monotonic and steps can get lost if you push your luck. When you add in leadscrew variability and backlash some sort of position encoder and feedback loop is needed for the highest accuracy and consistency which makes for a servo system, but it costs. Whether the drive motor is a stepper or a dc motor or an ac motor is not important, what matters is that when the CNC controller says 'x step 0.001mm' the servo controller does its best to deliver 0.001mm, usually by delivering several steps to the drive motor, sometimes a few more and sometimes a few less, whatever it takes to get feedback that means 0.001mm plus or minus tolerance. The ins and outs of fast and accurate servo systems provide many engineers with hours and hours of happy fun and many very thick books. Oh, and even a servo system can only be pushed so far.

martin perman23/11/2014 15:16:16
avatar
2095 forum posts
75 photos

Gentlemen,

Thanks for your thoughts this is for me a very interesting thread.

Martin P

ian slaney16/07/2015 18:58:03
5 forum posts

Hi Martin

I have been working on a version of a electronic gear feed on a ml7, using a 2000 per rev encoder (8000 in quad mode) and Nema23 Stepper motors. Based on Russian code , using an arduino nano (£5)

www.youtube.com/watch?v=BaBK9teKUaA

but now I have added English comments and fixed interupt code to count full quadrature. Would be happy to share code. You put in data like type of encoder, lead screw pitch , timing belt ratio, it works out all division of encoder req.

Basically does away with all gear wheels and you select thread or feed rate from lcd screen, can do TPI or metric.

Cheers ian

Edited By JasonB on 16/07/2015 19:31:31

ian slaney16/07/2015 19:09:57
5 forum posts

...Also not a great fan of emulators, esp when working with interupts Just start with some basic code and debug with serial link at run time, although will not work within the interupt routine (ISR). If you have even a limited background in programming you should pick up basic arduino quickly. HOWEVER Interupts and associated register manipulation is getting a bit more adventurous , but a must when using encoders, noting else will be fast enough.

cheers ian

Alex Collins16/07/2015 19:47:30
avatar
147 forum posts
38 photos

Sending a command to the stepper Driver results in the stepper motor doing what it's told.
If it doesn't do what it's told you are telling it wrong !
Garbage in, Garbage Out...

Counting the steps you send is of little value if the motor is driven to fast or stalls and misses steps. If your requirement is to /know/ how many steps it's actually moved you will need a rotary encoder. You can read the encoder with the same arduino, and maybe even correct errors with some programming.
I'd however advise (as others have) that you use 2 separate devices.

An Other16/07/2015 20:01:44
327 forum posts
1 photos

Alex beat me to it - the motor (if it is not 'stalled' somehow, will do as it is told. The software/driver will just produce pulses at regular intervals (unless interrupted) - it cannot suddenly decide to miss a pulse, or produce extra pulses. If it does, there is more likely to be a programming error!

Then if you need to check what the motor has actually done, you will need an encoder of some sort to send a return signal to the software. (and digital encoders of any accuracy tend to cost slightly more than the earth!)

As a general rule, stepper motor systems are 'open loop' systems - any commanded movement is assumed to have been completed successfully and is usually assured by using a motor with sufficient power to make the movement, and to hold its position after moving (i.e not slip forwards or back)

Servo systems, using an AC or DC motor with a feedback system as described by Roger Hart, are usually known as 'closed loop' systems, and many factors determine the eventual accuracy of movement.

What Martin seems to be describing is somewhat of a hybrid system, using a stepper motor with feedback in a closed loop configuration. Its possible, but maybe he can tell us what he will eventually apply this to - or is it just a learning exercise?

Ajohnw16/07/2015 20:35:51
3631 forum posts
160 photos

I think it would pay the OP to spend some time looking around here

**LINK**

There are specific stepping motor drivers that are easy to interface with that are also cheap and easy to obtain. There is also a lot of library code available including driving stepping motors and all sorts of other bits and pieces.

Interesting that some one has worked on replacing a lathe gearbox. Personally I would be looking at a geared down stepping motor to obtain lots of torque from a relatively small motor. Also thinking what the rotary encoder pulse counts meant in linear distances on thread pitches.

There is a yahoo electronic lead screw group that initially started from some work a German did that just used logic chips. Not sure what processor it uses now. I do know from following that some time ago that some people were effectively using servo motors to drive the lathe to get rapid speed control when the cut started and the motor speed dropped a little. I've never looked at the code so don't know if the problem is down to that or the software approach. Could be that some people just want to cut threads very very quickly so run at high speeds.

Must admit I became rather excited when stepping motors first appeared commercially thinking a rotary table / divider etc but once the detail is looked at things aren't so simple. The step tolerance can even be a problem. However they are a lot cheaper now.

John

-

Edited By John W1 on 16/07/2015 20:36:57

martin perman16/07/2015 20:40:49
avatar
2095 forum posts
75 photos

Gentlemen,

I do not intend to apply my questions to anything it was and still is something to keep my mind busy while I spent eight months off work with a condition which caused the bones in my right foot to break, I'm now a month back at work so my playing is currently on a back burner, I work with industrial robots and PLC's as my daily job and just wanted to see if I could produce a closed loop system to play with.

Martin P

Muzzer16/07/2015 20:41:19
avatar
2904 forum posts
448 photos

As ANO says, many systems are open loop. The Tormach PCNC milling machines are good examples and there is a lot of info about them on their website - they are quite open about their design process. Check out their "white papers".

There are stepper motors with inbuilt encoders such as the Leadshine Easy Steppers. If they stall or miss a step for any reason, they can generate an error signal.

There are also the likes of DMM Tech's servo motors. They are AC servos with a step/dir mode, so you can drive them as a stepper but as they are really closed loop servos with inbuilt encoders, they are even more capable of maintaining position than a closed lop stepper - and letting you know if they lose position. They are a bit of a small company but appear to be reasonable quality and their pricing is pretty much the same as a stepper motor solution. Unlike a stepper motor, a servo system tends to have a fairly broad speed range.

Steppers start out with back busting stall torque but this drops off very rapidly, limiting their usable speed range. Most DIY CNCers like to boast about the headline (stall) torque figures but that overlooks the shape of the torque curve which is essentially a constant power characteristic.

I'd forget about "multi threading". You can run multiple processes in real time if you design the software appropriately without multi threading but that's like trying to win a triathlon before you've learnt to walk. This is described as a learning exercise, so it's a bit off track right now.

Murray

All Topics | Latest Posts

Please login to post a reply.

Magazine Locator

Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!

Find Model Engineer & Model Engineers' Workshop

Sign up to our Newsletter

Sign up to our newsletter and get a free digital issue.

You can unsubscribe at anytime. View our privacy policy at www.mortons.co.uk/privacy

Latest Forum Posts
Support Our Partners
cowells
Sarik
MERIDIENNE EXHIBITIONS LTD
Subscription Offer

Latest "For Sale" Ads
Latest "Wanted" Ads
Get In Touch!

Do you want to contact the Model Engineer and Model Engineers' Workshop team?

You can contact us by phone, mail or email about the magazines including becoming a contributor, submitting reader's letters or making queries about articles. You can also get in touch about this website, advertising or other general issues.

Click THIS LINK for full contact details.

For subscription issues please see THIS LINK.

Digital Back Issues

Social Media online

'Like' us on Facebook
Follow us on Facebook

Follow us on Twitter
 Twitter Logo

Pin us on Pinterest

 

Donate

donate