Stepper Motor Controls

Advert

Stepper Motor Controls

Home Forums Electronics in the Workshop Stepper Motor Controls

Viewing 12 posts - 26 through 37 (of 37 total)
  • Author
    Posts
  • #396813
    David George 1
    Participant
      @davidgeorge1

      Hi on my z axis I have controlled it with the motor driver two switches and a pulse generator with adjustable speed. One switch to to start wired to enable one switch wired to direction and the pulse generator wired to pulse. I switch on set direction and turn pulse until required speed is set very simple and no programming is required, only my head is there any thing wrong with this setup.

      David

      Advert
      #396814
      John Haine
      Participant
        @johnhaine32865

        Absolutely nothing, a good approach. But is you use a processor you can get more flexibility, for example being able to repeat a given move at the touch of a button.

        #396820
        SillyOldDuffer
        Moderator
          @sillyoldduffer
          Posted by David George 1 on 18/02/2019 08:21:19:

          Hi on my z axis I have controlled it with the motor driver two switches and a pulse generator with adjustable speed. One switch to to start wired to enable one switch wired to direction and the pulse generator wired to pulse. I switch on set direction and turn pulse until required speed is set very simple and no programming is required, only my head is there any thing wrong with this setup.

          David

          Nothing wrong with that at all. I'd even argue that the simplest solution that does the job is the best!

          The only downside is the major redesign needed if more control of the z-axis is required. John gives one example, moving the head automatically to a given height is another. As is, David's pulse generator gives his mill a motorised head (and jolly useful that is!), but he still has to put it at the right height himself. A micro-controller could get close to a wanted position simply by counting steps, and excellent accuracy is achievable by having it read a DRO. But it may not be worth the extra trouble.

          In my workshop, doing what I do, there's little advantage in fitting machines right left and centre with steppers and clever controllers. The only exception so far is cutting gears on a rotary table. The manual set-up for stepping a rotary table is cumbersome, the maths difficult, and I'm not good at keeping count while cranking round the index plates, even assuming I've fitted the right one! An automated rotary table is much easier to use and it doesn't make stupid mistakes!

          Dave

          Edited By SillyOldDuffer on 18/02/2019 09:54:41

          #396836
          SillyOldDuffer
          Moderator
            @sillyoldduffer

            More on Arduinos…

            Computers work with numbers stored in base 2, binary. All modern machines work with 8-bit numbers called bytes. An 8 bit computer processes single bytes, a 32-bit computer processes 4 bytes at a time, and a 64-bit computer works on blocks of 8-bytes. But under the bonnet TRUE, FALSE, integers, characters, floating point, inputs, outputs, instructions, flags, dates, times, internet addresses and everything else are all represented by bytes, either singly or in groups. The only difference between types of data is the way they are encoded, and the way they are manipulated by the programmer.

            Working with data at hardware level is outrageously difficult. As a result huge effort has been put into developing tools allowing ordinary humans to cope. Software tools allow problems to be expressed in human-friendly ways, then translated them into a form understood by a computer, and then loaded into the computer. Even though much of computing is about hiding detail and complexity, there is still a lot to learn. The Arduino is designed to get people started relatively painlessly and the software used to program it is free. It runs on Windows, MAC, or Linux. Also, if you don't want to download and install more software on your computer a Web based version is also available.

            All Arduino programs start with this default template:

            ard_template.jpg

            Bottom right shows an Arduino Uno plugged in to my computer has been recognised.

            Believe it or not the empty template is a valid program. Pressing the ✓button compiles the instructions in the template (ie translates) into code that can be downloaded into an Arduino, and which works. It creates two functions: setup() is called once when the Uno is powered up; then loop() is called afresh every time it finishes, forever.

             

            ard_empty_compile.jpg

            The lower pane (in black and white) shows no errors, and tells me how much space my program will consume on the Arduino, which being a tiny computer makes it necessary to keep an eye on this. (Note: normally the Arduino IDE is set to minimise detail in the lower pane, but it can be set to tell all, which is occasionally useful when debugging.

            Pressing the right-arrow button downloads the compiled program into the Arduino where it is installed and starts running. Success or failure messages appear in the lower pane again:

            ard_uploading.jpg

            At this point I have an Arduino Uno busy executing a program that does absolutely nothing! Next post will put instructions into setup() and loop() capable of driving a stepper motor driver in the most basic way.

            Dave

             

            Edited By SillyOldDuffer on 18/02/2019 13:14:51

            #396867
            dcosta
            Participant
              @dcosta

              Hello ChrisH!
              Hello Brian!

              I have been away from home and just today I was able to prepare myself to begin the work of drawing the links between the Arduino tb6560 driver and the power supplies.
              Thankfully I read the news in the forum first.
              Dave's very well-done work (SillyOldDuffer) far surpasses everything I could do. What's more, it uses a driver (tb6600) which seems to me to be more complete and sturdier than what I use (tb6560).
              I'm really tempted to get a tb6600 driver and follow Dave's instructions for assembly.
              If, after all, I can be of service to you, please let me know.

              Greetings
              Dias Costa

              #396876
              SillyOldDuffer
              Moderator
                @sillyoldduffer
                Posted by dcosta on 18/02/2019 15:55:44:

                If, after all, I can be of service to you, please let me know.

                Greetings
                Dias Costa

                Too kind Dias! Please shout if anything isn't clear. I'm aiming for a 'get you started' tutorial and am happy to explain more if anyone gets stuck.

                Next post coming shortly…

                Dave

                #396879
                Martin Connelly
                Participant
                  @martinconnelly55370

                  The main reason for using the microprocessor with a shaper (as I see it) is to synchronised the movement to the shaper stroke. I imagine there will need to be a sensor to detect when the cutting stroke is complete and only move the workpiece on the return stroke. It may be possible to use a simple interupt on the enable signal of the simple system using a pulse generator but the variable number of steps per stroke that could result may marr the finish.

                  Martin C

                  #396880
                  SillyOldDuffer
                  Moderator
                    @sillyoldduffer

                    Before plunging into code, it's worth setting up the Arduino so we can see if it's working. Not necessary to connect it to a driver, motor and power supply at this stage, building them can be left until later. All we need do is test the signals output on pins A0, A1 and A2 are as planned.

                    The outputs can be tested with a multimeter, or an oscilloscope, but LEDs and a few resistors on a solderless breadboard will do the same job. These provide lines of connector strips into which components can be plugged to make temporary circuits.

                    dsc05937.jpg

                    All that's needed to test the Arduino program (or 'Sketch' in their jargon), is three small LEDs, with resistors arranged to drop 5V output by the Arduino to roughly1.5V on the LED. Any value between 220 ohms and 1000ohms should do the job. Boards and resistors available from ebay / amazon etc. Don't mess about sourcing three resistors – buy a selection box. Other values may be useful later. Ditto LEDs, get a small selection.

                    Plugged into the board and connected to the Arduino:

                    dsc05938.jpg

                    Not very clear in the photo but the Black jumper goes to a socket on the Uno marked GND, and the Yellow jumper goes to A0.

                    The pink LED connected to A0 (ie ENA+) is lit. This was achieved with these instructions:

                    ard_enable.jpg

                    Lines starting // are comments. Not used by the Arduino but helpful reminders for the programmer.

                    I could have used A0 in the raw, but instead "#define ENABLE_PIN A0" creates a meaningful alias. Not necessary In a small obvious program but a useful trick for complicated code, especially if you wrote it 5 years ago and can't remember how it works. It's easier to remember what ENABLE_PIN is than what A0 is connected to.

                    In setup() the program starts with a pin_mode() command that declares ENABLE_PIN (that is A0) to be an OUTPUT to be used later. This happens in the next statement: digitalWrite() is set HIGH, and 5V appears on the socket marked A0. It causes the LED to light, and it would enable a stepper motor controller when one's connected later.

                    Next, motor direction is set by adding similar instructions for pin A1:

                    ard_dir.jpg

                    I used #define to create meaningful aliases for CLOCKWISE and ANTICLOCKWISE rather than remember HIGH means clockwise. And if I get these the wrong way round and the motor runs in reverse, the problem is fixed at the #define – I wouldn't have to check every HIGH scattered throughout the code to see if was setting direction or doing something else.

                    As expected compiling and installing this causes the red LED to come on as well.

                    dsc05939.jpg

                    Coming next, the instructions needed to output pulses on A2, aka PULSE_PIN, and eventually to be wired to PUL+ on the stepper driver.

                    Dave

                     

                    Edited By SillyOldDuffer on 18/02/2019 17:48:30

                    #396977
                    Andy Carruthers
                    Participant
                      @andycarruthers33275

                      Good work Dave – appreciated!

                      #396992
                      SillyOldDuffer
                      Moderator
                        @sillyoldduffer

                        The program so far just allocates two pins as outputs and switches them on. As this is only one once, it's convenient to put the instructions into setup().

                        Sending pulses to the motor driver is a repeated operation and it makes sense to put the code into loop(). loop() is called automatically when setup() finishes, and it is called again each time loop() finishes. The instructions in loop() will be applied over and over again until the power is turned off. The logic in loop() typically does something like:

                        IF something_happened THEN
                        do this_function()
                        ELSE
                        do another_function()

                        To send a stream of pulses all that's necessary is to set an output pin to HIGH and follow that with another instruction to set the pin LOW. Each time loop() is run, it sends HIGH LOW to the motor driver.ard_pulsefast.jpg

                        Checking message pane shows the program has used a trivial amount of resources – there's plenty of room for expansion. (790 bytes used of 32256 available)

                        Now all three of the test LEDs on the breadboard are lit:

                        dsc05940.jpg

                        Not obvious in the photo but the Green LED connected to PULSE_PIN is dimmer than the other two. That's because it's ON for half the time and OFF for the remainder. The pulses are far too fast to see individually, but an oscilloscope reveals all:

                        ard_oscillo.jpg

                        The oscilloscope shows each pulse lasts 6.87 microseconds, and there are about 145000 pulses per second, each one of which would step the motor once. Assuming the motor, power supply and stepper driver could physically cope with that, a motor set to 200 steps per revolution would spin at 43500 rpm, and the same motor set to 6400 micro-steps would spin at 1359 rpm. In the real world, the electronics in the stepper driver might only be up to 50000 pulses per second, and – especially if accurate high torque stepping is wanted – a stepper motor should be run much slower than that. Voltage is important to the speed at which a stepper motor will turn reliably, as is the time a PSU takes to deliver a current pulse. (A supply designed to deliver 4A continuous might not be so good at 4A bursts.)

                        For those reasons, the pulse rate has to be slowed down. And because, the motor power supply combination was chosen for convenience rather than selected to a careful design specification, it pays to find the best speed/reliability rate for a particular motor and power supply by experiment. The pulse rate is set by putting a delay between digitalWrite(PULSE_PIN, HIGH); and digitalWrite(PULSE_PIN, LOW);

                        More on that in the next post.

                        Dave

                         

                         

                        Edited By SillyOldDuffer on 19/02/2019 13:19:23

                        Edited By SillyOldDuffer on 19/02/2019 13:22:44

                        #397019
                        SillyOldDuffer
                        Moderator
                          @sillyoldduffer

                          A slower pulse rate is achieved by ordering the Arduino to wait for a short time between HIGH and LOW. Changes inside Red boxes.

                          avr_slowpulse.jpg

                          To provide flexibility, the delay is stored in a variable. That used, called 'pulseDelay' , is declared as a signed integer, which on the Arduino is ±32768. I set it to 50 and note they are going to be microseconds. Further down the code, the variable is used in a new function called 'delayMicroseconds()'. Given a number, this instruction waits for a time. The time delay could be hard coded into the program, but using a variable makes changing the pulse rate easy. For example to provide speed control.

                          Functions like digitalWrite(), delayMicroseconds() and many others are provided with the Arduino. They are fully described in the online documentation, with examples. There are also many tutorials available. The Arduino is programmed in 'C' (actually a variant of C++), and most of the standard C and C++ functions are also available, organised into 'libraries'. Functions can be written by the user, and there many user provided libraries as well. With luck someone else will have done most of the hard work for you already. There is a simple built-in stepper library worth looking at and a much more sophisticated library here. It adds features like acceleration which is needed to get the very best out of a motor. Not needed on a rotary table or head lifter, but a CNC application would benefit.

                          Arduino can also exchange messages with the host PC. These are useful for debugging because they allow your code to report the values it's working with, and you can check they're right. Next example adds a Serial link back to the PC and uses it to show that a switch INPUT has been detected.

                          ard_serial_in.jpg

                          Apologies for the first red box – it should be around the declaration below.  My mistake.

                          Second red box – this code adds the instruction 'Serial.begin( 9600 ). It opens a USB serial connection with the PC running at 9600 bits per second. Opening the Arduino IDE's built in terminal will connect to the Uno and the two can exchange data. There's no obligation to use the connection.

                          Also added is an unsigned long integer called 'pulseCount' set to zero. On an Arduino Uno, unsigned long can hold an integer between 0 and 4,294,967,296 In the next red box one is added to pulseCount every time a pulse is sent to the stepper driver.

                          The program also allocates A3, aka DEBUG_PIN, as an INPUT_PULLUP. INPUT_PULLUP makes the pin HIGH by default, and a switch wired to ground the pin can thus be detected. The state of the input is tested with digitalRead(). If the read is equal to LOW, the value of pulseCount is printed to the Serial line, and sent to the PC. Serial.print() doesn't throw a new-line on the remote terminal, Serial.println() does.  Beginner booby trap, '=' is an assignment, the equality test is '=='.  Don't mix them up!

                          If A3 is connected to ground, a stream of numbers appears on the terminal. Otherwise the program doesn't bother. Note that the time taken to communicate with the PC adds more delay and reduces the pulse rate slightly. Example terminal screen, yes it soon gets up to 2 million:

                          ard_console.jpg

                          Dave

                           

                          Edited By SillyOldDuffer on 19/02/2019 16:29:22

                          #397022
                          donkey
                          Participant
                            @donkey

                            thanks all.I now have to assemble everything and give it a go..

                            brian

                          Viewing 12 posts - 26 through 37 (of 37 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

                          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