Motor position control

Discussion in 'The Projects Forum' started by bia, Sep 26, 2013.

  1. bia

    Thread Starter New Member

    Sep 26, 2013
    11
    0
    Has anyone been able to successfully position a brushed DC motor using a motor controller and quadrature encoder with a microcontroller? By sucessfully position, I mean have the motor stop within 4 or less pulses of the desired encoder position and be able to repeat the process hundreds of time with approximately a 4-pulse (1 cycle) precision. Not interested in what a microcontroller can theoretically do. Practical experience doing this only, please. Thanks.
     
  2. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266
    Done it with a PIC18F chip- PID and PWM- two motors at once.
     
  3. bia

    Thread Starter New Member

    Sep 26, 2013
    11
    0
    Nice. Thanks, Sensacell. Can you tell me what speed the motors were turning and what encoder resolution. I don't know much about PIC MCUs but I'm guessing this was in assembly language? Also, what clock speed? I seem to be getting conflicting infornation on that with google.
     
  4. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266
    I used an external quadrature counter chip:

    http://www.lsicsi.com/encoders.htm

    Encoder counts and RPM are almost irrelevant when you have a hardware counter for the encoder. The important factor is the time constant of the motor and mechanical system as it relates to the PID loop update rate.

    PIC running at 10 MIPS (40 Mhz clock)
    Code in assembly.
     
    strantor likes this.
  5. Experimentonomen

    Member

    Feb 16, 2011
    331
    46
    Except sensors encoders included are becoming obsolete. Its all done sensorless nowdays.
     
  6. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266

    Hmm? Not for precision motion control applications.

    Sensorless motors are great for prime movers, but how do you position a rotor +- 0.5 degrees without a precision feedback mechanism i.e an encoder or resolver?
     
  7. bia

    Thread Starter New Member

    Sep 26, 2013
    11
    0
    A quadrature decoder chip is a definite possibility. At this point I am trying to ascertain whether anyone has successfully done this using a microcontroller to count quad encoder pulses.

    Sensacell, I echo your question about sensorless positioning. Care to elaborate on that, Experimentonomen?
     
  8. Experimentonomen

    Member

    Feb 16, 2011
    331
    46
    I can swear i was once told that someone had made some 100% sensorless motor positioning using nothing but the motors bemf signals, and was atleast as accurate as encoder based systems.

    And if im not mistaken it was on one of those robots used in like car production lines for welding and such.
     
  9. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266
    Counting encoder pulses in SW is a bandwidth eater- not recommended.

    Using the peripheral counters is an option, but not without it's limitations.
     
  10. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Yes, I have done it on a number of projects.

    Motors are relatively slow, so it does not take too much timeslice to read the encoder. I do it in a timer interrupt, on a PIC 18F 40Mhz (10MHz ticks) you can run an interrupt at 256 ticks; (10M / 256 = 39kHz).

    As long as your encoder will not change faster than 39kHz that will work fine. A 500 count encoder at 39kHz maxes out at 78 RPS which is 4680 RPM. Encoders with less counts per rev would obviously have a higher max RPM.

    Here is the interrupt code for the full quadrature recoder to an absolute position (variable mpos), it is very fast;
    Code ( (Unknown Language)):
    1.  
    2. void interrupt()
    3. {
    4.   //-------------------------------------------------------
    5.   // This is TMR0 int at approx 39kHz (40MHz PIC 18F)
    6.   //-------------------------------------------------------
    7.   // clear int flag straight away to give max safe time
    8.   INTCON.T0IF = 0;
    9.  
    10.   //  update encoder to see if motor has moved, records it position
    11.   enc_new = (PORTA & 0b00000011);   // get the 2 encoder bits
    12.   if(enc_new != enc_last)
    13.   {
    14.     if(enc_new.F1 != enc_last.F0) mpos++;   // record new motor position
    15.     else                          mpos--;
    16.     enc_last = enc_new;
    17.   }
    18. }
    19.  
    There is a simple project below that might give you some ideas, it is a "novelty" project to turn a DC motor at very slow precise average speed but might give you some ideas for encoder decoding etc;
    http://www.romanblack.com/onesec/DCmotor_xtal.htm
     
    Last edited by a moderator: Sep 26, 2013
  11. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    (note to admin/moderators)

    Code tags and html links seem to have both stopped working? They worked for me yesterday.
     
  12. bia

    Thread Starter New Member

    Sep 26, 2013
    11
    0
    Thanks, THE_RB. Besides counting pulses, were you able to properly control deceleration, overshoot, etc.?

    The end goal is to do PID control on two motors concurrently, as Sensacell has previously stated that he has done.
     
  13. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    In the High speed servo world, some BLDC or AC sinusoidal motors will do a brief exercise of the motor and calculate rotor - stator position and from then on use the encoder to provide the right commutation for the 3 winding stator. instead of using hall effect devices or equivalent tracks on the encoder disk.
    Automotive welding typically uses robots and these without almost no exception use absolute encoders, not quadrature.
    Max.
     
  14. strantor

    AAC Fanatic!

    Oct 3, 2010
    4,302
    1,988
    I disagree.
     
  15. bia

    Thread Starter New Member

    Sep 26, 2013
    11
    0
    Just to clarify, did you use a quad decoder or quad counter, such as the LS7166?
     
  16. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I was. But good position AND power control is quite a difficult task if you don't have much experience. You are basically talking about building a complete servo driver using one chip, actually worse as now you are talking about making TWO complete servo drivers on the one chip?

    The short answer is that if the motor is slow and things change slowly etc it's not too hard. If you need fast response and high stability, and/or if you have wild load behaviour etc than everything needs to perform very well in real time and it is not a job for a beginner.

    So if this is for a little robot with two slow DC gearmotors, and is for robot locating/positioning, then yes it should not be too hard. If it is for a high performance servo positioning application then you should just buy proper servo drivers. :)
     
  17. bia

    Thread Starter New Member

    Sep 26, 2013
    11
    0
    Thanks, THE_RB. I suspected it would be very difficult. But, having read how easy it is by all the armchair programmers on the web who have never done it but can tell you exactly how, I though I would pose the question.

    The problem with servos is I haven't found one that will produce 80 in-lb torque in a NEMA-17 frame. If you know of one, I would sure like to hear about it. If you have used a closed-loop brushed DC motor controller that will handle continuous current of 15+amps, I would love to hear your experience.

    BTW, not exactly a beginner. I've been at this 30 years with a CS degree. Just never ran into a situation where I needed to make my own wheel (at least not this wheel) before.
     
    Last edited: Sep 27, 2013
  18. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    As a rule the only way to get a higher than average torque size in a given NEMA frame is to extend the motor length, Baldor used to make DC servo's in this manner, but they always seemed inordinately long!
    Max.
     
  19. bia

    Thread Starter New Member

    Sep 26, 2013
    11
    0
    I don't think anyone is making those anymore which is why I'm stuck with brushed DC.
     
  20. KaguraHime

    New Member

    Sep 25, 2013
    7
    0
    Novice here.

    If you need a motor to stop at precisely a position, it sounds like an electromagnetic brake is needed.

    If you need the motor to stop at the same places every time, it sounds like limit switches will do.

    If you're using a stepper motor, then encoders usually aren't required. Though this type of motor doesn't have much torque and it'd miss steps if the load's too much.
     
Loading...