Arduino project with stepper motors

Advert

Arduino project with stepper motors

Home Forums General Questions Arduino project with stepper motors

Viewing 25 posts - 1 through 25 (of 33 total)
  • Author
    Posts
  • #23591
    martin perman 1
    Participant
      @martinperman1
      Advert
      #170291
      martin perman 1
      Participant
        @martinperman1

        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

        #170294
        John Haine
        Participant
          @johnhaine32865

          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.

          #170297
          martin perman 1
          Participant
            @martinperman1

            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

            #170304
            jason udall
            Participant
              @jasonudall57142

              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

              #170310
              Neil Wyatt
              Moderator
                @neilwyatt

                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

                #170381
                jaCK Hobson
                Participant
                  @jackhobson50760

                  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)

                  #170385
                  martin perman 1
                  Participant
                    @martinperman1

                    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

                    #170398
                    Neil Wyatt
                    Moderator
                      @neilwyatt

                      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

                      #170416
                      Roger Hart
                      Participant
                        @rogerhart88496

                        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.

                        #170436
                        KWIL
                        Participant
                          @kwil

                          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

                          #170447
                          Neil Wyatt
                          Moderator
                            @neilwyatt

                            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.

                            #170450
                            Roger Hart
                            Participant
                              @rogerhart88496

                              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.

                              #170454
                              martin perman 1
                              Participant
                                @martinperman1

                                Gentlemen,

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

                                Martin P

                                #196949
                                ian slaney
                                Participant
                                  @ianslaney37890

                                  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)

                                  http://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

                                  #196950
                                  ian slaney
                                  Participant
                                    @ianslaney37890

                                    …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

                                    #196954
                                    Alex Collins
                                    Participant
                                      @alexcollins55045

                                      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.

                                      #196956
                                      An Other
                                      Participant
                                        @another21905

                                        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?

                                        #196960
                                        Ajohnw
                                        Participant
                                          @ajohnw51620

                                          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

                                          #196961
                                          martin perman 1
                                          Participant
                                            @martinperman1

                                            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

                                            #196962
                                            Muzzer
                                            Participant
                                              @muzzer

                                              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

                                              #197066
                                              Michael Gilligan
                                              Participant
                                                @michaelgilligan61133
                                                Posted by ian slaney on 16/07/2015 18:58:03:

                                                Would be happy to share code. …

                                                .

                                                Ian,

                                                Please check your messages; when you have a moment.

                                                MichaelG.

                                                #197077
                                                Neil Wyatt
                                                Moderator
                                                  @neilwyatt

                                                  For small steppers the 'Polulu' board (developed for repraps is excellent and easy to control.

                                                  Neil

                                                  #197081
                                                  ian slaney
                                                  Participant
                                                    @ianslaney37890

                                                    Hi Neil , they are ok for the small reprap nema14 motors but not for nema23 motors which would be needed on a lathe or mill , i use the nema23 on my repScrap which started as a reprap and is now evolved into a full metal constructed cnc engraver, I use the cheap chinese driver board as it uses the toshiba td656070 (4a@50v rated) on a huge heat sink. Only down side on reprap was they got a bad press as they need a much longer step pulse duration of 30ns than the pololu 5ns and most people could not get them to work on stock reprap, one oscilloscope and little pulse stretch and they are fine.

                                                    cheers ian

                                                    #197084
                                                    John Haine
                                                    Participant
                                                      @johnhaine32865

                                                      I don't think you mean ns! Microseconds perhaps…

                                                    Viewing 25 posts - 1 through 25 (of 33 total)
                                                    • Please log in to reply to this topic. Registering is free and easy using the links on the menu at the top of this page.

                                                    Advert

                                                    Latest Replies

                                                    Home Forums General Questions Topics

                                                    Viewing 25 topics - 1 through 25 (of 25 total)
                                                    Viewing 25 topics - 1 through 25 (of 25 total)

                                                    View full reply list.

                                                    Advert

                                                    Newsletter Sign-up