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

  • Hello,


    Is there a reason for having this task Private? Is it OK for you that we convert to Open? This is so that others in the forum can both help you and that others with the same issue can see how to solve it.


    As I have never tried this example my self, I need to test it here at first. Are you using the nRF52840 DK? 

    Kind regards,
    Øyvind

  • I have sent you a message asking to convert the message, please confirm.

  • 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

  • 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. 

Related