EMC2 and a rotary encoder


Results 1 to 20 of 20

Thread: EMC2 and a rotary encoder

  1. #1
    Registered
    Join Date
    Jun 2005
    Location
    Indianapolis, IN, USA
    Posts
    91
    Downloads
    0
    Uploads
    0

    Default EMC2 and a rotary encoder

    I am building a CNC tube bender as a senior project for my BS in MET. I am using EMC2 on Ubuntu 8.04. I am using a breakout and relay board to control a 120V Vickers directional control valve. I have a 500 PPR rotary encoder. It is my wish to use the rotary encoder to track die position (0-100ish degrees). I hooked the required ports (A,B,Ground and +Vdc) to the breakout board. I would like to have a small DRO on the screen that tells me angular position in degrees. I have searched online but found nothing. I have sent EMC2 to look for pins 12 and 13 as spindle position A and spindle position B. Pins 1 and 14 are outputs that are set as Spindle CC and Spindle CCW. I have absolutely no clue what to do next. Please guide me as I am a new user to EMC2. Check out my build here if you are interested:

    http://cnczone.com/forums/showthread...796#post531796

    Similar Threads:


  2. #2
    Registered
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    2
    Downloads
    0
    Uploads
    0

    Default

    Hi!
    You may take a look at Parallel-port Two-axis PWM servo controller for Etch CNC
    It uses two simple DC-Servo connected to a PWM bridge and encoders. All connected directly to the parallel port.
    You did not write anything about home or reference switches (and limit switches...)? Hope your design has one (at least).
    Without any real knowledge about tube benders (except they bend tubes...) i would mount a reference or home switch at a (slightly) negative angle (-5°) to leave some space when inserting the tubes...

    EDIT: The config files are there, too. So you can have a look at them.

    Jürgen

    Last edited by juergen; 11-27-2008 at 06:38 PM.


  3. #3
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    24220
    Downloads
    0
    Uploads
    0

    Default

    AFAIK EMC like Mach does not input an encoder into the parallel port, you might look at wether EMC does interface a Manul Pulse Hand Wheel, this is typically a 100p/turn encoder for manual motion and adapt this routine.
    EMC also has the option of add-on cards for servo operation.
    Otherwise you would have to use the A & B pulses and write an algorithm that detects one pulse as counts and the other for direction. You may run into a timing issue, depending on how fast the parallel port was read and the encoder speed.
    You may not necessarily need home or limit switches as the hydraulics could simply bottom out on a stop.
    For home registration, you could just bottom to a stop, and when motion was zero for so many seconds, make this zero reference.
    Al.

    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  4. #4
    Registered
    Join Date
    Sep 2004
    Location
    USA
    Posts
    149
    Downloads
    0
    Uploads
    0

    Default

    These links might help, they are related to using encoders with parallel ports in emc2:

    http://wiki.linuxcnc.org/cgi-bin/emc..._A_MPG_Pendant

    http://emergent.unpythonic.net/projects/01142347802

    http://wiki.linuxcnc.org/cgi-bin/emc..._With_Encoders

    http://www.members.shaw.ca/swstuff/spindle-encoder.html

    So I guess it can be done, in any number of ways. I haven't done it myself yet, but I want to try it too.


    Thanks,
    Dan



  5. #5
    Registered
    Join Date
    Jun 2005
    Location
    Indianapolis, IN, USA
    Posts
    91
    Downloads
    0
    Uploads
    0

    Default

    The first link with the MPG writeup seems like it will work well. I am going to try it when I get home. If I manage to get the rotary encoder hooked up, will EMC2 display a DRO displaying angular position in degrees?



  6. #6
    Gold Member acondit's Avatar
    Join Date
    Apr 2005
    Location
    USA
    Posts
    1778
    Downloads
    0
    Uploads
    0

    Default

    I built a rotary encoder for the spindle of my lathe and I am using the parallel port to read its inputs. I am only using the index and 100 count features, I never got the B channel hooked up and working. I am attaching the portion of my ".hal" file that has to do with the spindle encoder.

    Here is a link to my thread. The encoder starts at message 48 and continues (off and on) to message 85.

    Alan

    Attached Files Attached Files


  7. #7
    Registered
    Join Date
    Jun 2005
    Location
    Indianapolis, IN, USA
    Posts
    91
    Downloads
    0
    Uploads
    0

    Default

    Wow, thanks for your help Alan. I probably don't need the B channel either. My rotary encoder will never rotate more than 100 degrees because my tube bender can't move past 102ish degrees. My encoder is 500PPR, so it will only ever send out 130 pulses over 15 seconds, leading to 9 pulses per second (very minimal). Your file opens in Notepad as a paragraph; everything is smashed together. Hopefully Linux will open it differently.



  8. #8
    Gold Member acondit's Avatar
    Join Date
    Apr 2005
    Location
    USA
    Posts
    1778
    Downloads
    0
    Uploads
    0

    Default

    Linux uses LF (linefeeds) to denote the end of a line but windows/dos expects a CR/LF pair.

    Alan



  9. #9
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    24220
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by supahonkey View Post
    Wow, thanks for your help Alan. I probably don't need the B channel either. My rotary encoder will never rotate more than 100 degrees because my tube bender can't move past 102ish degrees.
    How will you indicate a bi-directional count with one channel, or do you intend to set it up un-directional count?
    Al.

    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  10. #10
    Gold Member acondit's Avatar
    Join Date
    Apr 2005
    Location
    USA
    Posts
    1778
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by Al_The_Man View Post
    How will you indicate a bi-directional count with one channel, or do you intend to set it up un-directional count?
    Al.
    Al,

    If he never rotates more than 100° he should be able to just use a direction signal and count. He might even be able to use the index to set up home.

    Alan



  11. #11
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    24220
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by acondit View Post
    Al,

    If he never rotates more than 100° he should be able to just use a direction signal and count. He might even be able to use the index to set up home.

    Alan
    I have not used EMC, but am not sure I see how he would get a count and a direction from just the A channel?
    The general premise for an encoder is one channel is the count and the other the direction pulse, no?
    Al.

    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  12. #12
    Gold Member acondit's Avatar
    Join Date
    Apr 2005
    Location
    USA
    Posts
    1778
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by supahonkey View Post
    Wow, thanks for your help Alan. I probably don't need the B channel either. My rotary encoder will never rotate more than 100 degrees because my tube bender can't move past 102ish degrees. My encoder is 500PPR, so it will only ever send out 130 pulses over 15 seconds, leading to 9 pulses per second (very minimal). Your file opens in Notepad as a paragraph; everything is smashed together. Hopefully Linux will open it differently.
    The only reason I never hooked up the B channel was because I couldn't seem to get the third optical switch positioned correctly. In the hal file I posted you should only need to change a couple things to hook up your B channel which would then give you (2000 cpr / (100/360))=555.56 counts for 100° or 555 counts for 99.9°.

    Alan



  13. #13
    Gold Member acondit's Avatar
    Join Date
    Apr 2005
    Location
    USA
    Posts
    1778
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by Al_The_Man View Post
    I have not used EMC, but am not sure I see how he would get a count and a direction from just the A channel?
    The general premise for an encoder is one channel is the count and the other the direction pulse, no?
    Al.
    Al,

    He couldn't. I meant that he can track when he has travelled X counts, then assert a direction change to retract.

    Without the channel B he wouldn't know for sure whether he dithered on the same point for X counts or moved in one direction for X counts.

    Alan



  14. #14
    Registered
    Join Date
    Jun 2005
    Location
    Indianapolis, IN, USA
    Posts
    91
    Downloads
    0
    Uploads
    0

    Default

    Forgive me for my ignorance. This is the first time I have never messed aroudn with anything CNC related. I thought the purpose of the B channel was to offer a second square wave that is 90 degrees off from the first square wave. I will hook up both if I can. Alan, once I modify your HAL file, how will I know it is working? Is there a onscreen DRO that EMC displays or do I have to show a command?

    EMC is rather confusing. I learned a little bit about Mach3 in the two weeks that I got into it. It seems there is some documentation about EMC, it is just scattered every where. Mach3 has a lot of organized documentation. Is there a list of all the available commands for EMC? I have a hard time understanding what each line in the .ini and hal files does. I am devoted to using EMC2 and I don't mind the challenge. I just wish it were easier to find info about the software.



  15. #15
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    24220
    Downloads
    0
    Uploads
    0

    Default

    The basic premise behind the quadrature encoder configuration is that one pulse is the count pulse and the second to detect direction, if moving in one direction, When the A pulse goes high (count) , the B pulse will be low (count up), when the direction reverses, the trailing edge of the A pulse, now becomes the leading edge, (count) and the B pulse will be High (count dwn).
    This is the reason for the two pulses being 90deg apart, i.e. quadrature pulses.
    The subsequent hardware or firmware has the option of using 1 count edge, two leading edges or all four leading and trailing edges for a count of x1, x2 or x4.
    This gives different option to increase the resolution of the basic encoder count.
    Al.

    Last edited by Al_The_Man; 11-28-2008 at 12:49 PM.
    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  16. #16
    Gold Member acondit's Avatar
    Join Date
    Apr 2005
    Location
    USA
    Posts
    1778
    Downloads
    0
    Uploads
    0

    Default

    EMC has a feature called "halscope". It is like an oscilloscope that can monitor pins or signals. If you haven't done so already, download the "EMC2 Integrators Manual" pdf. It has an introduction to using hal scope. Suffice it to say for the moment that you will be able to look at the PPort pins that you have physically connected to the encoder signals and watch the signals change at the parallel port. Then you can change the scope settings and see that the hal signals are changing as the PPort pins change.

    Then you can use halmeter and watch the encoder counts change in the encoder module.

    Basically, I believe, you only need to uncomment the line that connects channel B to the parallel port pin and then add a line that puts the encoder in x4-mode.
    something like:
    setp encoder.0.x4-mode 1 (not exactly sure here but I will try to find out if no one else jumps in).

    Alan




  17. #17
    Registered
    Join Date
    Nov 2005
    Location
    Alabama - USA
    Posts
    256
    Downloads
    0
    Uploads
    0

    Default

    There's another very good reason to use both channels A and B for position feedback. If the encoder stops at the edge of a transition with only one channel whatever is looking at that single channel has no way of "knowing" whether the encoder is moving in one direction or jittering back and forth. You can disable the encoder maybe if it's not supposed to be moving, but that can create further errors. You really want both channels.



  18. #18
    Gold Member acondit's Avatar
    Join Date
    Apr 2005
    Location
    USA
    Posts
    1778
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by acondit View Post
    Basically, I believe, you only need to uncomment the line that connects channel B to the parallel port pin and then add a line that puts the encoder in x4-mode.
    something like:
    setp encoder.0.x4-mode 1 (not exactly sure here but I will try to find out if no one else jumps in).
    I found another sample hal file with a quadrature encoder and it used:

    setp encoder.0.x4-mode TRUE

    Alan



  19. #19
    Member
    Join Date
    Nov 2005
    Location
    Canada
    Posts
    496
    Downloads
    0
    Uploads
    0

    Default

    See this rather old page about a large DRO display using pyvcp (a GUI component).
    set the scale right to display degrees. (3600 pulses in one turn of encoder then divide pulses by 60 to get degrees). you need to use both A and B channels. Have you read the Integrators manual? Have you read the wiki? Also the EMC maillist is a good place to ask.



  20. #20
    Member jmelson's Avatar
    Join Date
    Mar 2004
    Posts
    369
    Downloads
    0
    Uploads
    0

    Default

    Quote Originally Posted by Al_The_Man View Post
    AFAIK EMC like Mach does not input an encoder into the parallel port, you might look at wether EMC does interface a Manul Pulse Hand Wheel, this is typically a 100p/turn encoder for manual motion and adapt this routine.
    Al.
    EMC most certainly CAN read an encoder through a parallel port. It may not be the best way to do it, but for relatively low-resolution encoders moving at modest rates, it will work fine. There is a HAL component called "encoder" and the A and B signals from the encoder can be piped into it through appropriate HAL pin assignments. This takes up two of the sparse input pins on the typical parallel port, as the main data bus pins can be either ALL inputs or ALL outputs, but not some of each. IIRC, there are 4 dedicated inputs and 5 outputs. (I may have that backwards.)

    Jon



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
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

EMC2 and a rotary encoder

EMC2 and a rotary encoder