This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

QDEC example simple code

Hi,

I want to interface two QENC with nrf52840, I saw QDEC example and it works as expected.

The problem I am facing is that QENC has four pins of which two are for power and two are ENCA and ENCB. Since I don't have QENC LED, I have to sample let's say 25 samples per second directly, how to do that?

Also I tried connecting my QENC pins to QDEC A (pin3) and QDEC B (pin4), connecting QDEC LED as it is and tried the software, it didn't work.

Is there a simple code not simulator where I can test my actual hardware and the direction whether it is in positive direction or negative direction?

How to add two QDEC in a project?

Regards

SDK 15.2, Keil, nRF52840 DK

Parents
  • Hello again, 

    I would recommend reading the QDEC chapter in the nRF852840 PS. Furthermore, have a look at the QDEC Peripheral Library in the SDK documentation. 

    The problem I am facing is that QENC has four pins of which two are for power and two are ENCA and ENCB. Since I don't have QENC LED, I have to sample let's say 25 samples per second directly, how to do that?

    For using off-chip mechanical encoders not requiring a LED, the LED output can be disabled by writing value 'Disconnected' to the CONNECT field of the PSEL.LED register. In this case, the QDEC will not acquire access to a LED output pin and the pin can be used for other purposes by the CPU.

    To set the sample rate, use the function:

    nrf_qdec_sampleper_set()

     

    Also I tried connecting my QENC pins to QDEC A (pin3) and QDEC B (pin4), connecting QDEC LED as it is and tried the software, it didn't work.

    See the answer above.  

    Is there a simple code not simulator where I can test my actual hardware and the direction whether it is in positive direction or negative direction?

     Unfortunately, we do not have any examples of this sort. I recommend using the example we have and customize it for your use. 

    Have a look at cases regarding QDEC herehere and here

    Kind regards,
    Øyvind

  • Hi

    Thank you for pointing out specific topics.

    I am able to read accdbl and acc values in NRF_QDEC_EVENT_REPORTRDY as you showed, I don't understand what they signify.

    In table Sampled value encoding I saw the description but they are based on sample register and how to interpret direction based on accdbl and acc as they .

    Can you please let me know how can I count pulses and time so that I can calculate speed with sign?

    I know the formula

    S = (C/CPR) / (T/60)

    where,

    C is no of pulses

    CPR is constant for encoder

    T is time in sec at which pulses were captured

Reply
  • Hi

    Thank you for pointing out specific topics.

    I am able to read accdbl and acc values in NRF_QDEC_EVENT_REPORTRDY as you showed, I don't understand what they signify.

    In table Sampled value encoding I saw the description but they are based on sample register and how to interpret direction based on accdbl and acc as they .

    Can you please let me know how can I count pulses and time so that I can calculate speed with sign?

    I know the formula

    S = (C/CPR) / (T/60)

    where,

    C is no of pulses

    CPR is constant for encoder

    T is time in sec at which pulses were captured

Children
  • Ali Rumane said:
    I don't understand what they signify.

     ACC = Register accumulating all valid samples (not double transition) read from the SAMPLE register

    ACCDBL = Register accumulating the number of detected double or illegal transitions

    Ali Rumane said:
    In table Sampled value encoding I saw the description but they are based on sample register and how to interpret direction based on accdbl and acc as they .

    Not sure what you mean, the link points to the QDEC chapter.  The Sample Value Register contains Last motion sample. The value is a 2's complement value, and the sign gives the direction of the motion. The value '2' indicates a double transition. 

    Ali Rumane said:
    Can you please let me know how can I count pulses and time so that I can calculate speed with sign?

    I'm sorry I don't know the formula. The Sampling and Decoding chapter explains how this works. 

  • Thank you for your help

    I am reading ACC registers but values seems completely incorrect.

    I used gpiote to count pulses and they seems to be fine.

    Do you know some common reasons why it isn't working as expected?

    I am planning to use gpiote and count risung edge pulses which seems okay for me as of now but still I think qdec should work somehow for my applcation.

    Regards

Related