Controlling stepper motor with atteched encoder


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2013
    Posts
    8

    Default Controlling stepper motor with atteched encoder

    Hi, I just tried, and failed, to post my first thread. Apparently I got logged out (maybe because I took 1.5 hrs to compile the message, kids, life, etc)

    Here is it, but shorter version:

    Hello, I am a newbie, trying to drive a stepper using encoder, need to be 100% sure where motor is at all times. I have steppers. . .lots of them, so really want to use what I have. . . .lot's of them :-)

    AVAGO HEDS-5545 encoders on Vexta 6 wire Stepper, driving as Bipolar
    I have been able to get the stepper moving just fine. . .slow, no speed ramping , but working just the same

    I am using the standard amazon driver "
    L298N Stepper Motor Driver Controller Board Module", happy to get something else if i need

    (http://www.amazon.com/gp/product/B00...0?ie=UTF8&psc=)

    To the chase, I am looking for a point in the right direction, I don't seem to be able to find any Pic-Basic code that shows the driving of a stepper, with encoder feedback. I am also looking to display the encoder info to a LCD (Jameco #618003 DISPLAY,LCD,PARALLEL,16X2)

    Here is a dump of my software/Hardware:
    Micro-code Studio Version 4.0.0.0
    MeLabs Programmer Version 4.50
    (Lab X-1 not that i am using it here, I just have it)
    I Have these MCU's:
    Pic16f877a
    Pic 18f452
    Pic18f458

    If anyone can point me in the right direction (if it's anything like my medicine cabinet when I need a band-aid. . .it's probably right under my nose. . .my wife says men can't find anything) I would really appreciate it. BTW, my coding skills are very aged, use to write stuff 20 yrs ago, 5 kids and 80 hr work weeks later . . . not so much).

    I truly appreciate any pointers, direction to look or otherwise, that I get from you fine folks. I also want to pre-thank people for not pouncing on me if in fact i am guilty of bad search engine skills, not lazy, just frustrated

    All the best
    John aka "Camcompco"

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Hi John, welcome to the forum!

    How do you plan to feed the position value? By a keypad or via serial com.

    I have written a code for driving stepper motor (that was few years ago) and position was fed via serial com. The code didn't use close loop but I will be happy to modify it for reading the encoder and turn it from open loop to close loop system

    Let me know how many pulses per turn is your optical encoder and a little more on your project.

    Cheers

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Feb 2013
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Hi Arrati (Al)
    first off, thanks for the quick comments.

    Well, i happen to have an idea for something that will have to move a given predefined distance in a pattern, not unlike out CNC friends, but my motions will be fixed from a given starting point, for example:

    Move (by rotating a acme lead screw) a table to the right (x-axis) 100mm, then forward vie a different stepper/encoder (y-axis) 25mm, stay there for 5 seconds, reverse the y-axis direction 25mm, go further right (x-axis) 50mm, repeat the y-axis movement as before, do this a few more steps (further x and y movements) then return to home, wait until something happens elsewhere (mechanical trigger from other event) and repeat entire process over and over.

    I plan on introducing sensors to actually trigger when the y-axis movements stop (they won't be 25mm always, they may be a function of a sensor (contact) being triggered, but the x axis movements will be constant.

    This has to be an independent system, no "PC" interface allowed. In essence, it has to be a self contained unit that contains MCU, motors and the ability to know if a step was missed to keep going to "predefined" location. I will also have to introduce contacts so the movement can stop when the appropriate y-axis movement has taken place. The encoder has 400cpr.

    thanks again!!!

    Also, thanks for the kind welcome!!

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Hi John, I am posting a working snippet for moving a stepper controlled by an optical encoder. The encoder is fed to Timer1 which act as a 16 bits counter and using DT interrupt on overflow it will stop the motor when position is reached. I have commented the code but if something is not clear please just ask!.

    Hope you will find the code usefull as a base to start building your own.

    Cheers

    Al.
    Attached Files Attached Files
    All progress began with an idea

  5. #5
    Join Date
    Feb 2013
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Thanks for this. . .very excited to get home and give it a good look!!!
    simply great that you take the time out to help a chap thousands of miles away. . . . .

    I can't help but imagine that there are many others that will gain from this dialogue as well

    Again, thanks!!!!

    John (Camcompco)


  6. #6
    Join Date
    Feb 2013
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Sorry Al, maybe a dumb question here, but will I need to see these "include" files to understand things fully, just asking in the hopes that is the answer is yes you can attach them so when I get home i will better be able to look at things.

    INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

    thanks again!

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Those two include files can be downloaded from Darrel site @ http://www.darreltaylor.com/DT_INTS-14/intro.html
    Place both in the PBP folder.

    Cheers

    Al.
    All progress began with an idea

  8. #8
    Join Date
    Feb 2013
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Hello Al,

    I just wanted to say that i am still working on this, didn't want to come of as rude for not following up. As it turns out I really needed to re-re-re read the picbasic pro manual, i was relying on the basic i learned back when i used Lotus 123, much has changed :-)

    I am experimenting (trying) on the 18f4431, it has built in Quadrature feedback, sounds like it would be good for my app??? thoughts??

    any who, will make sure to follow up soon,

    All the best
    John

  9. #9
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Hi John, yes PBP manual is of great help.
    As far as QUI is concerned, this technique increases by a factor of four the resolution of your encoder, so an encoder with 500 pulses per turn will result in a 2000 pulses per turn. This at a first glance could seems great but using a stepper could create some problem. Let me give you a numeric example.

    You have a stepper with a resolution of 200 steps per turn, using half step driving you will obtain 400 steps per turn. An encoder of 100 pulses per turn will be your choise, using quadrature, otherwise compensating for lost steps could be a serious problem since the step movement of your motor is a fraction of the encoder quadrature count. (In case of an encoder of 500 pulses per turn your motor step will generate 5 encoder counts per motor step)
    Just bear in mind this complication in choosing the encoder if you will use the quadrature.

    PS. Is your stepper motor 200 steps per turn or higher?

    Cheers

    Al.
    Last edited by aratti; - 3rd March 2013 at 12:38.
    All progress began with an idea

  10. #10
    Join Date
    Feb 2013
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Hi Al,
    yes, i have a boatload of new stepper motors, and they are all 200 steps or higher. Most of my encoders are 400 cpr.

    I have many steppers that are gear reduced giving actual 0.18 degree per step translation at the shaft. My applications require relatively low speed on the steppers,60-100 rpm range , it's more a matter of being accurate, than fast.

    I do not need the accuracy of 2000 pulse per turn, i just thought (without really knowing what the heck i am talking about ;-) that the PIC18f4431 QUI features would make hardware more straight forward as the functionality would be handles at the chip "hardware" level rather than at the motor controller level.

    Again, total newbie here, just trying to figure this out so I can actually build a prototype.

    At the end of the day, all i need it to get this darn thing up and running, as it turns out I then have to spend untold hours trying to just understand that I can do before I can actually do anything

    i have been trying to get the combination of :
    • Program in PBP
    • schematic using parts I have So i understand how to actually connect things on a breadboard
    • using motors and encoders that I have (almost exclusively HEDS-5545 or HEDS-5645 on double shaft VEXTA steppers)
    So far, a simple, totally newbie, easy to understand without tons of research, etc. . . .has eluded me

    Your fine assistance is well appreciated but was a little less than "turn-key" LOL and is still being worked on by yours truly :-)

    thanks again for the continued help . . .man do I need it.


    Lost in New Jersey

    John

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Controlling stepper motor with atteched encoder

    Hi,
    The QEI module in the 18F4431 is great. It can be set to decode in 2x or 4x mode so your 400 cycles per revolution encoder will give a count of either 800 or 1600. I don't see that as a problem even if you're running the motor in full step mode. More resolution is almost never a bad thing :-) In theory it should allow you to measure how much the shaft is actually lagging the commanded position and allow you to slow down when the lag start aproaching 2 full steps. Because the instant the lag equals 2 fullsteps the rotor desynchronizes and position is lost.

    /Henrik.

Similar Threads

  1. Motor Stepper Example
    By Melanie in forum Code Examples
    Replies: 134
    Last Post: - 3rd January 2015, 17:58
  2. Replies: 1
    Last Post: - 15th December 2010, 14:30
  3. Controlling stepper motor with PIC
    By The Master in forum Off Topic
    Replies: 3
    Last Post: - 1st July 2008, 10:21
  4. Stepper Motor Program
    By kiwipiper in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th November 2007, 02:56
  5. Stepper Motor troubles
    By Fryin in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st March 2007, 01:56

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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