527,928 active members*
2,568 visitors online*
Register for free
Login
IndustryArena Forum > CNC Electronics > Stepper Motors / Drives > Adding encoder to stepper motor
Results 1 to 10 of 10
  1. #1
    Registered
    Join Date
    Jun 2015
    Posts
    6

    Adding encoder to stepper motor

    Hi,

    I am thinking of putting encoder on stepper motormyself and getting a driver for it instead of buying a set of driver and stepper motorwith closed loop system.

    Question is would driver like this: DSP Stepper Drive HBS86H Nema34 Motor Hybrid Servo 30 100VDC 8A Leadshine | eBay
    work with motor like this: US EU Free Shipping Wantai 3pcs Nema34 Stepper Motor 1090oz in 5 6A 4LEADS 2PHS | eBay
    and encoder like this: Omron Rotary Encoder E6B2 CWZ6C E6B2CWZ6C 1000p R New in Box Y0K3 | eBay
    Would that stepper motorwith added encoder ant with that driver be as loud and hot as usually, or those problems be gone as well?

  2. #2
    Junior Member
    Join Date
    Mar 2016
    Posts
    18

    Re: Adding encoder to stepper motor

    Sorry to bring up an old thread.

    I am looking at doing something similar like this. I'm wondering if you got it working? Or if it's even possible. I am assuming as long as the signal pulses from the encoder are the same as what is on the ready made ones then it should work.

  3. #3
    Registered
    Join Date
    Oct 2017
    Posts
    11

    Re: Adding encoder to stepper motor

    I know this thread is a bit dated, but I'll explain how I have encoded a stepper motor. I have a DM542T driver running a dual shaft NEMA 24 stepper at about 1200 RPMs. The way I set mine up was to add an encoder to the back of the stepper. I used a rather crude optical encoder from a printer that has a resolution of 200 pulses per rev. I connected everything to the driver as normal EXCEPT the pulse pin. The pulse for the driver went to an arduino I had setup to read digitial IO. Another pin relayed the pulse going TO the driver.

    When the CNC controller sends a pulse (which normally went to the stepper driver) to the arduino, the arduino sent that corresponding pulse on to the stepper driver. If the arduino did not detect a movement from the encoder on the back of the stepper, it would pulse the driver again (at double the length of the first pulse) to get the stepper to move. If it failed to move again, the arduino would raise the voltage on an output pin, which was connected to the controller, which made the controller believe a stop had been hit. An LED would light on the back of the stepper so I would know which axis had a fault.

    It worked ok, but would be best if I had an encoder that had the same resolution as the micro step setting in the driver. That way one pulse = one micro step. I also wanted to let it buffer the pulses so if X missed a step I could hold Y and Z until the X was able to move. That was proving to be pretty complex though. re-driving one axis that missed a step while the others are moving would cause some erratic cuts to happen. (such as lumpy circles, or worse)

    Ultimately, adding the encoder was pretty simple, the hard part became, 'What do you do if a step gets missed?'. All the axis movements have to happen in concert with one another. Which is why I skipped on buying closed loop steppers, but still believe its a good idea, just needs better implementation than what I have seen so far.

  4. #4
    Junior Member
    Join Date
    Mar 2016
    Posts
    18

    Re: Adding encoder to stepper motor

    Hi,

    Very clever way of using the arduino to be the brains behind a closed loop system.

    I know it'll cost more but wouldn't just getting a hybrid driver which counts the pulses from the encoder to match the steps given from the driver be a lot easier and if the steps are bot done a fault signal is sent to your BOB.

  5. #5
    Registered
    Join Date
    Oct 2017
    Posts
    11

    Re: Adding encoder to stepper motor

    Quote Originally Posted by davemorl View Post
    Hi,

    Very clever way of using the arduino to be the brains behind a closed loop system.

    I know it'll cost more but wouldn't just getting a hybrid driver which counts the pulses from the encoder to match the steps given from the driver be a lot easier and if the steps are bot done a fault signal is sent to your BOB.
    Yes I completely agree it would be much easier. However a scenario like this is what I wanted to be able to handle:

    You are cutting a circle/angle/ (any movement that requires the coordination of 2 or more axis), X and Y are moving simultaneously.
    The Y axis has skipped a step, but the X did not.
    Y continues to miss steps and it cannot catch up.
    The machine may stop, but the mistake in the cut is already there because X continued to move and Y did not.

    Even in a closed loop system where it knows a step has been missed, it may be too late already to 'make up' the step because the other axis(s) have already moved.

    So my thought was, I can 'buffer' 1,2,3,4,5 axis inputs, and if Y misses one, hold the other axis' still until Y has actually proceeded. Then let the buffer run out.
    Because most off the shelf stand alone controllers I have seen assume X,Y,Z,A etc went to where they were told, they don't accept 'feedback' for confirmation. using the arduino as a middle man was the idea there.

    But it became quite complex in a hurry and eventually I settled on getting a driver and stepper system that was reliable. The closed loop system is great, but I didnt really want to just shut down because it missed a step. I wanted it to find the proper location and carry on. Would be nice if there was a controller (maybe there is one and I dont know about it) that you can tell it to stop running g-code for a moment so the axis can catch up.

  6. #6
    Junior Member
    Join Date
    Mar 2016
    Posts
    18

    Re: Adding encoder to stepper motor

    Yeah I can imagine it got pretty complicated pretty quick! You'd need the signals to have some sort of timing signal with it to make sure that they kept in sync or you'd find that the computer would keep sending the BOB pulses which would be passed to the arduino. Without a timing signal of some sort of what is supposed to be moving with what it might end up getting a bit out of sync. The encoder will be giving just positional and directional signals. So without a marker of some sort to say x y and z should be doing all of this now at the same time then it won't know if it's out of sync only that one axis has stopped so pause the others till it's working again?

    The only solution I can come up with is that the arduino notices that it's out of sync for say in the x axis and then pauses the y and z axis until it receives the feed back from the x. Once the x encoder has given a signal for the correct movement it then starts the other axis again? If the pause is for to long then it can give the BOB a signal to stop the program as there is a major alarm?

    Could I see your code that you've written so far? If be interested in messing about with this myself to be honest! I have some spare drivers and steppers and would like to add some encoders to the back of them and see if i can get some sort of accuracy.

  7. #7
    Registered
    Join Date
    Oct 2017
    Posts
    11

    Re: Adding encoder to stepper motor

    Quote Originally Posted by davemorl View Post
    Yeah I can imagine it got pretty complicated pretty quick! You'd need the signals to have some sort of timing signal with it to make sure that they kept in sync or you'd find that the computer would keep sending the BOB pulses which would be passed to the arduino. Without a timing signal of some sort of what is supposed to be moving with what it might end up getting a bit out of sync. The encoder will be giving just positional and directional signals. So without a marker of some sort to say x y and z should be doing all of this now at the same time then it won't know if it's out of sync only that one axis has stopped so pause the others till it's working again?
    Right.

    Quote Originally Posted by davemorl View Post
    The only solution I can come up with is that the arduino notices that it's out of sync for say in the x axis and then pauses the y and z axis until it receives the feed back from the x. Once the x encoder has given a signal for the correct movement it then starts the other axis again? If the pause is for to long then it can give the BOB a signal to stop the program as there is a major alarm?
    Also correct.

    Quote Originally Posted by davemorl View Post
    Could I see your code that you've written so far? If be interested in messing about with this myself to be honest! I have some spare drivers and steppers and would like to add some encoders to the back of them and see if i can get some sort of accuracy.
    You can certainly get accuracy out of it. And the version of the code I have below makes it reactive like a servo. If you move the stepper it will move back IF your encoder can tell you which direction it moved. If not it can still react, but it might react in the wrong direction.
    I dont have the 'original' original code, but I looked at it for so long I have it memorized for the most part.

    This is all from memory. This is to run an encoder on an arduino, give reactive feedback to the stepper and correct for missed steps on the stepper motor. Arduinos don't have a built in clock so there is not timing signal. The closest solution I can come up with is another processor that all axis feed into, and it controls and coordinates the pulses going to each stepper driver. Instead of having an independent control on each axis. The code only corrects UNDER travel, it does not correct OVERT RAVEL, which is very possible on a heavy axis, especially a Z. If you have an encoder that tells you the direction is moved when it wasnt supposed to, THAT will correct for over travels. But an over travel during a cut, is too late. On a G0, not such a big problem. And no complaints about bugs, I wrote this all from memory.

    unsigned long PulseInLength=0;
    unsigned long PulseOuLength=0;
    unsigned long MissedSteps=0;


    double PulseLength=2.5;


    int CommandPulsePin = 8;
    int DriverPulsePin = 12;
    int EncoderPin=9;
    int TryCount = 0;
    int AxisErrorPin = 13;
    int AxisStopPin = 11;
    int ShouldMove=0;


    setup()
    {
    pinMode(CommandPulsePin, INPUT);
    pinMode(EncoderPin, INPUT);
    pinMode(DriverPulsePin, OUTPUT);
    pinMode(AxisErrorPin, OUTPUT);
    pinMode(AxisStopPin, OUTPUT);
    }
    loop()
    {
    //Wait for a pulse input from the controler.
    ShouldMove = 0;
    while(digitalRead(CommandPulsePin) == 0)
    {
    digitalRead(EncoderPin); //If a movement is detected, and we haven't told it to move
    //it needs to react and move back to where it was. Like a
    //servo would.
    //Good plan to make it reactive, but we have to know which direction the motor was moved.
    //Disable this for now.
    //digitalWrite(1,HIGH);
    //PulseDriver();
    //digitalWrite(1,LOW);


    //Just smile and wave boys, nothing else to do here except wait.
    }
    ShouldMove = 1;
    //We must have had a digital pulse come in to break the while.
    //Relay that pulse on to the driver immediatley.
    PulseDriver();
    ReadEncoder();
    }
    void PulseDriver()
    {
    digitalWrite(DriverPulsePin, HIGH);
    delayMicroseconds(PulseLength); //Rising edge must stand for minimum 2.5 microseconds for a 542 driver
    digitalWrite(DriverPulsePin, LOW);
    delayMicroseconds(2.5); //Low edge must stand for minimum 2.5 microseconds for a 542 driver
    //This may need other changes. A DIR change pulse requires a longer delay (3us) in the pulse rate.
    }


    void ReadEncoder()
    {
    unsigned long StartTime= micros(); //See what time it is when we get here.
    unsigned long StopTime= StartTime+15; //Set an end time 15 microseconds ahead of when we got here


    int EncoderValue = 0;
    while (micros()<=StopTime)
    {
    EncoderValue = digitalRead(EncoderPin)
    if (EncoderValue == 1)
    break;
    }
    if (EncoderValue == 1) //We got a value, so just carry on like normal.
    {
    TryCount = 0;
    PulseLength = 2.5;
    return;
    }


    if (TryCount >0) //We already tried this once and still we didnt get feedback
    {
    digitalWrite(AxisErrorPin, HIGH); //Turn on the error led for this axis
    digitalWrite(AxisStopPin, LOW); //tell the dds we hit a stop switch so it fails.
    while (1=1) //Loop infinitley until the reset axis button is pressed which will start the program over again.
    {
    }
    }

    //We didnt get a value from the encoder, so we have missed a step.
    TryCount ++; //Add one to our trycount
    //Pulse the driver again!
    PulseLength = PulseLength * 2; //Pulse with a double length
    PulseDriver(); //Pulse once for the missed step.
    ReadEncoder();
    }

  8. #8
    Registered
    Join Date
    Sep 2005
    Posts
    28

    Re: Adding encoder to stepper motor

    Hello All and shooter64738,

    Thankyou everyone on the cnczone forums for the inspiring and helpful information.

    My question is for all but specifically to shooter64738, would your code for the arduino work with a small servo motor with an encoder
    (like this one -ebay item Sanyo Denki DC Servo Motor With Encoder L404-011E17 40W 24V 2.7A 3000RPM)
    and only 1 axis.

    Actually, I would like to convert an old dividing head into a 4th axis indexer utilizing a simple board like the arduino. Just indexing so I can cut some splines on shafts.
    I would like to be able to use this on a standard bridgeport as well as on my Haas TM1.


    Thanks again for all the great information.
    Robert Flores

  9. #9
    Registered
    Join Date
    Oct 2017
    Posts
    11

    Re: Adding encoder to stepper motor

    I don't know the specifics on how that servo needs to be driven but I would imagine it is similar to other servos requiring a driver, tach, direction, and so forth. I have some parker allen servo drives and some servos that I have toyed with at the shop, and yes I can drive those with an arduino or similar board. I have setup a simple indexer using a stepper motor (or you could use a server I suppose if we knew the driver signal) that will rotate an amount proportional to one of the other axis' by reading the pulse lines to the other axis, and duplicating the pulses at a pro-rated amount. I mounted a planetary gear 3 jaw chuck to a stepper and for every 1 pulse on the X axis, I drove the rotary axis 72 pulses so that they were in sync. Essentially 1 inch of X needed to be 1 degree of rotation for my purposes.
    If you have an arduino type board writing something to do that would be pretty simple. I have an expanded version of that software I have been playing with for some time that works with grbl to make axis's and spindles sync together with cobbled together controls and parts. If you connect it to a commercial machine though, locating the signal wire can be pretty challenging sometimes. Most of them may have an axis control, and an axis/amp card and its all kind of buried in there somewhere.
    Quote Originally Posted by MMTechi View Post
    Hello All and shooter64738,

    Thankyou everyone on the cnczone forums for the inspiring and helpful information.

    My question is for all but specifically to shooter64738, would your code for the arduino work with a small servo motor with an encoder
    (like this one -ebay item Sanyo Denki DC Servo Motor With Encoder L404-011E17 40W 24V 2.7A 3000RPM)
    and only 1 axis.

    Actually, I would like to convert an old dividing head into a 4th axis indexer utilizing a simple board like the arduino. Just indexing so I can cut some splines on shafts.
    I would like to be able to use this on a standard bridgeport as well as on my Haas TM1.


    Thanks again for all the great information.
    Robert Flores

  10. #10
    Registered
    Join Date
    Jan 2015
    Posts
    3

    Re: Adding encoder to stepper motor

    Hi,
    It's an old thread but it has to do with this. I have a bipolar nema 34 and a CS-D1008 driver, which is closed loop. Someone mention it should be easier that way. But not. I have tried to make it work with a 600 pulses per revolution encoder, and although it rotates as it should, it does not take torque, even though the phases consume current. I tried it many times, and on one occasion it did take torque. I think it has to do with the relative position of the encoder and the motor shaft. I also tried a hybrid motor, 1000 pulses, with the stepper motor and the encoder in all possible combinations. The result was always the same, it only takes torque with the hybrid engine. Does anyone know how to synchronize the encoder and the stepper axis? If the problem happens there.Thanks.
    https://www.cnczone.com/forums/image...AAAElFTkSuQmCC




























Similar Threads

  1. Adding encoder to stepper motor
    By VYTUX in forum Want To Buy...Need help!
    Replies: 0
    Last Post: 01-21-2016, 10:49 PM
  2. stepper motor without encoder
    By ReCar in forum Granite Devices
    Replies: 0
    Last Post: 05-18-2012, 07:55 PM
  3. encoder for stepper motor
    By 15mgtar in forum Stepper Motors / Drives
    Replies: 0
    Last Post: 09-22-2009, 04:47 PM
  4. encoder-stepper motor
    By granado in forum Stepper Motors / Drives
    Replies: 2
    Last Post: 11-29-2004, 11:38 AM
  5. Stepper motor with encoder?
    By buscht in forum Stepper Motors / Drives
    Replies: 3
    Last Post: 07-13-2004, 03:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •