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

QDEC example with nRF Connect SDK v1.4.0

Hello, sorry if this seems to be a basic or already asked question, but how could I have an example of QDEC usage with the nrf52840 (ideally the dongle) ?
I would like to plug a simple mechanical rotary encoder, and I found some posts telling there is an example in the SDK, but after having installed nRF Connect SDK v1.4.0 (on Windows and Linux), I don't find such example.
Maybe I should use a previous version ? Or maybe someone could point me to an old version of the example that would still be compatible with the more recent version ? (I found some posted links related to that but always targetting pages that don't exist anymore)

Thank you :)

Parents
  • Hi,

    There are no QDEC samples in nRF Connect SDK at the moment. You need to enable it with remember to enable CONFIG_QDEC_NRFX in prj.conf. You can refer to the nrfx API if you want to use it directly. You can also refer to how it is done in the wheel module (nrf\applications\nrf_desktop\src\hw_interface\wheel.c). Here the Zephyr Sensor API is used, which is an abstraction on top of the nrfx QDEC driver in this case.

  • Thank your for pointing me to this.

    When I enable CONFIG_QDEC_NRFX, and anslo CONFIG_SENSOR as this seems to be a required dependency, then my build fails, the first error being:

    [78/185] Building C object zephyr/drivers/sensor/qdec_nrfx/CMakeFiles/drivers__sensor__qdec_nrfx.dir/qdec_nrfx.c.obj

    FAILED: zephyr/drivers/sensor/qdec_nrfx/CMakeFiles/drivers__sensor__qdec_nrfx.dir/qdec_nrfx.c.obj
    ...

    In file included from D:/ncs/v1.4.0/zephyr/include/arch/arm/aarch32/arch.h:20,
                     from D:/ncs/v1.4.0/zephyr/include/arch/cpu.h:19,
                     from D:/ncs/v1.4.0/zephyr/include/kernel_includes.h:38,
                     from D:/ncs/v1.4.0/zephyr/include/kernel.h:17,
                     from D:/ncs/v1.4.0/zephyr/include/init.h:11,
                     from D:/ncs/v1.4.0/zephyr/include/device.h:22,
                     from D:/ncs/v1.4.0/zephyr/include/drivers/sensor.h:23,
                     from D:/ncs/v1.4.0/zephyr/drivers/sensor/qdec_nrfx/qdec_nrfx.c:7:
    D:/ncs/v1.4.0/zephyr/drivers/sensor/qdec_nrfx/qdec_nrfx.c: In function 'qdec_nrfx_channel_get':
    zephyr/include/generated/devicetree_unfixed.h:1717:37: error: 'DT_N_S_soc_S_qdec_40012000_P_steps' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_qdec_40012000_P_status'?
     1717 | #define DT_N_INST_0_nordic_nrf_qdec DT_N_S_soc_S_qdec_40012000

    Of course I will search more on my side, but I just tell this in case the solution is not so obvious...

    Thank you

Reply
  • Thank your for pointing me to this.

    When I enable CONFIG_QDEC_NRFX, and anslo CONFIG_SENSOR as this seems to be a required dependency, then my build fails, the first error being:

    [78/185] Building C object zephyr/drivers/sensor/qdec_nrfx/CMakeFiles/drivers__sensor__qdec_nrfx.dir/qdec_nrfx.c.obj

    FAILED: zephyr/drivers/sensor/qdec_nrfx/CMakeFiles/drivers__sensor__qdec_nrfx.dir/qdec_nrfx.c.obj
    ...

    In file included from D:/ncs/v1.4.0/zephyr/include/arch/arm/aarch32/arch.h:20,
                     from D:/ncs/v1.4.0/zephyr/include/arch/cpu.h:19,
                     from D:/ncs/v1.4.0/zephyr/include/kernel_includes.h:38,
                     from D:/ncs/v1.4.0/zephyr/include/kernel.h:17,
                     from D:/ncs/v1.4.0/zephyr/include/init.h:11,
                     from D:/ncs/v1.4.0/zephyr/include/device.h:22,
                     from D:/ncs/v1.4.0/zephyr/include/drivers/sensor.h:23,
                     from D:/ncs/v1.4.0/zephyr/drivers/sensor/qdec_nrfx/qdec_nrfx.c:7:
    D:/ncs/v1.4.0/zephyr/drivers/sensor/qdec_nrfx/qdec_nrfx.c: In function 'qdec_nrfx_channel_get':
    zephyr/include/generated/devicetree_unfixed.h:1717:37: error: 'DT_N_S_soc_S_qdec_40012000_P_steps' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_qdec_40012000_P_status'?
     1717 | #define DT_N_INST_0_nordic_nrf_qdec DT_N_S_soc_S_qdec_40012000

    Of course I will search more on my side, but I just tell this in case the solution is not so obvious...

    Thank you

Children
  • Hi,

    Coco cinelle said:
    When I enable CONFIG_QDEC_NRFX, and anslo CONFIG_SENSOR as this seems to be a required dependency

    There is a dependency on nrfx if you want to use sensor, but not the other way around if you only want to use nrfx directly.

    Coco cinelle said:
    then my build fails

    The error is because the zephyr drivers (like sensor) requires that pins etc. ar defined in the device tree file (or overlay file). So you can fix this by adding the qdec configuration to the device tree, either (quick and dirty) by putting it into zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts if you ar using that target board, or by putting it in your own boar definition or in an overlay file: 

    &qdec {
    	status = "okay";
    	a-pin = <3>;
    	b-pin = <28>;
    	enable-pin = <30>;
    	led-pin = <0xFFFFFFFF>;
    	led-pre = <0>;
    	steps = <24>;
    };

  • Hi, I created a .overlay file with this content and there is no more error, thanks!

    About CONFIG_SENSOR, it is because I have this warning:

    warning: QDEC_NRFX (defined at drivers/sensor/qdec_nrfx/Kconfig:4) was assigned the value 'y' but
    got the value 'n'. Check these unsatisfied dependencies: SENSOR (=n)

    But for the moment I don't have any code that uses qdec, I just made a copy of a small sample project to begin...
    Going into the real stuff now :)

  • Hi, to be sure I don't make mistakes, what is the purpose of the "enable-pin" here? Removing the line triggers build errors, but I don't see the documentation of an "enable pin" for the QDEC device in the nrf product specification.

    Also, I suppose low frequency GPIOs would be ok for a-pin and b-pin, so I plan to use for eg. P1.10 and P1.13 (As I saw somewhere in a forum : "0-31 correspond to 0.x and 32-63 correspond to 1.x").

    Thanks

  • Hi,

    Coco cinelle said:
    Hi, to be sure I don't make mistakes, what is the purpose of the "enable-pin" here? Removing the line triggers build errors, but I don't see the documentation of an "enable pin" for the QDEC device in the nrf product specification.

    The enable-pin is a concept of the zephyr sensor driver API, and not part of the QDEC peripheral nor nrfx driver. Essentially it is just a pin that is asserted while the QDEC is active. You can see how it is set and cleared by calls to qdec_nrfx_gpio_ctrl() in the implementation in <NCS>/zephyr/drivers/sensor/qdec_nrfx/qdec_nrfx.c.

    Coco cinelle said:
    Also, I suppose low frequency GPIOs would be ok for a-pin and b-pin, so I plan to use for eg. P1.10 and P1.13 (As I saw somewhere in a forum : "0-31 correspond to 0.x and 32-63 correspond to 1.x").

    Yes, that should be fine (and your understanding that P1 numbering is correct).

  • Ok, thank you.
    So I try to mimic what is done in wheel.c . I also want to enter system OFF mode after some inactivity delay, like it seems to be done in wheel.c, but it seems the dongle wakes up directly after reaching the OFF state...
    Could it be caused by the fact that I'm plugged in USB and the only way to stay in system OFF mode would be to enable external power ?
    Thank you

Related