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.

AM625: EQEP

Part Number: AM625

Several weeks ago I posted a question on e2e asking for EQEP support from T.I.

I am using rotary encoders with Am62x EQEP counters for audio volume control.  I added ti_eqep.c to the Linux kernel and added the EQEPs to the device tree.  I got the EQEP counters working but have a couple of questions.

  1. Can the counters be set up to generate interrupts when they change? If so, which flags should I use?  The technical reference manual is not clear to me.
  2. Can I set the counters so they do not wrap around when they count to Zero or Max Position? If so, how?

I would prefer not to continuously poll the counters if there is a better way.

Thanks in advance

  • Hello Gene,

    First off, glad to hear that you have gotten EQEP counters working on your side! FYI, our developers are working on getting EQEP running on AM62x in parallel. You can see the latest updates on the CICD branch: git.ti.com/.../

    Please give me another day to look into the questions about generating interrupts, and whether we can prevent the counters from wrapping around. I'll provide another response by end of day Friday.

    Regards,

    Nick

  • Hello Gene,

    Our EQEP developer wanted to let you know that the code on our side is still being tested, so please let us know if you find any bugs or have any ways that the series of patches can be improved further.

    From the developer: "the counter can now generate interrupts based on direction change, overflow, underflow, and timer timeout. The driver will set the appropriate registers based on events. More info here: https://docs.kernel.org/driver-api/generic-counter.html#counter-events. User-space app can then configure counter events and interrupts will be generated based on direction change, etc... as is explained here: https://docs.kernel.org/driver-api/generic-counter.html#userspace"

    When I read further up on the page, it does look like the generic-counter API allows for a Synapse action of "Both edges", so I would expect that you could set up an interrupt to look for any change in the counter value, either increasing or decreasing https://docs.kernel.org/driver-api/generic-counter.html#synapse 

    In terms of setting the counters so they do not wrap around, I am not sure off the top of my head about the functionality in the new code I linked above. However, this patch set from 2019 for the same driver does explicitly mention "setting the min/max value" of the counter. Perhaps it would be helpful to you? https://lore.kernel.org/lkml/20190902150245.GE1445@ulmo/T/

    Regards,

    Nick

  • Hi Nick

    I would like to run poll() to only read the rotary encoders when the count changes.  This works with GPIO and UART interrputs but my encoder count files do not seem to generate any events.  Can you suggest how to fix this?

    count file =/sys/devices/platform/bus@f0000/23200000.qep/counter0/count0/count

    Read your reply from 11/10.  Could you be a little more specific - which files would need to be changed and what changes to make.  I am still a little clumsy in Linux.

  • Hello Gene,

    On the discussion of setting it so that the EQEP counter does not wrap around:

    In hardware, that is not supported. The minimum counter value is 0, the max counter value is user-programmed (we'll call it MAX). When the EQEP receives an up-count when the counter is already at MAX, then the EQEP will overflow and wrap around to 0. A similar thing happens if the counter is at 0, and the EQEP receives a down count.

    You could potentially work around this by setting interrupts for overflow and underflow. If Linux received an overflow interrupt, it could manually set the EQEP counter value back to MAX. Similarly, if Linux received an underflow interrupt, it could manually set the EQEP counter value back to 0.

    On the question of whether an interrupt can be generated when the EQEP counter value changes 

    From a hardware side, no.

    The developer told me that the EQEP peripheral can only generate interrupts for the things listed in this register in the TRM: QEINT_TYPE1
    (search for it in chapter 14, Registers). The interrupt events that the developer mentioned in my previous response are all listed here: direction change, overflow, underflow, and timer timeout. However, there isn't anything listed for a change in counter value.

    I was hoping that maybe the index event could be used, but it looks like that is used to establish a known position (e.g., where a printer head is located in the printer) rather than setting some arbitrary number that we could at least get an interrupt for when it happens.

    I wonder if a very small MAX value could be programmed, and then you could just use an overflow interrupt as an "up count" and the underflow interrupt as a "down count"?

    Regards,

    Nick