This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Counting encoder pulses

Other Parts Discussed in Thread: TM4C123GH6PM

I'm using tm4c123gh6pm to create a counter to count the number of pulses of a magnetic encoder attached with a dc motor for speed PID control. The encoder pulses' width and number vary with the motor speed (applied input voltage to the motor), so the needed clock for the counter is external .. What are the options I could use to make the counter? timer ?and what are the required configurations needed? 

Regards,
Islam

  • Islam Elnady said:
    the needed clock for the counter is external

    My friend - firm/I have done pretty much the same as you describe - yet we've "not" found the need to employ a "counter" clock.   Does your magnetic encoder datasheet (clearly) state that such an (external) clocking IS required?

    If freed from that "external clocking" - might an MCU Timer - configured for "Edge Count" mode - very well, "meet your objectives?"

    Should you, "buy into" the above - a second Timer - this configured as "One Shot" can serve as a, "Gating Control" for the (earlier mentioned) Edge Counter.   The one-shot Timer (only) enables the Edge Counter for a (well determined) interval.   Upon the one-shot's "time out" - the Edge Counter is frozen (disabled) - its contents read & stored - and then processed to determine motor speed.   (i.e. Counts per unit time is directly proportional to motor speed)   And - if you (well) choose the one-shot's duration - your "Counts to RPM calculation" can be substantially simplified.

    Firm/I prefer the "One Shot" Timer mode to "Periodic" as it proves less "demanding" upon the Edge Counter's, "Read, store, speed calculate & display."   (note that we also display the motor's Actual Speed, Target Speed, Current draw, Advance/Retard settings (if any) & Torque etc.)   Only when completed do we (again) clear the Edge Counter & launch a new, "Count acquisition sequence."  (and that's why the "flexibility" & "accommodation" of the one-shot is our choice over the "too demanding" (inflexible) periodic.)

    It would be useful if you'd link to your magnetic encoder.   Firm/I employ some from "CUI" (and are unrewarded) for such mention...   (can that be fair?)

    It should be noted that "if" your encoder produces "Quadrature Pulse Output" AND if your MCU includes a QEI peripheral - that implementation may work well.   (and the quadrature method supplies "motor direction" - absent in the method I've (earlier) described...)

    That said - method presented (up top) serves as a, "Universal Solution" - able to succeed even w/"lesser" MCUs - and as it well complies w/KISS (via 2 part, individually managed design) it's faster, easier & more instructive than a QEI module - where (most) facts & methods are "hidden."

  • That was fair enough. Thank you!
  • Mon ami - (only) fair enough? (War & Peace manuscript was (only) slightly more detailed.)
    Merci - bon chance...
  • Hi cb1
    Would you please note down the steps of configurations for both edge count mode timer, and one shot mode timer ?
    - I couldn't take in the details in the datasheet very well.
  • OK my friend - please note today is (alleged) day of rest. (I've been a "bum" all day - but must visit the shop shortly) Can't promise a full answer today/tonight - but expect to have one by cob tomorrow.