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

  • 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

  • Hi,

    I do not see that wheel.c has any code to enter system OFF mode, but it would probably not belong there anyway. What is it i you refer to? Could it be that you mean system ON low power mode (which is the normal sleep mode)?

    Generally, there are only a few possible wakeup sources from system OFF (GPIO, NFC or LPCOMP), and then if triggered, the device will wake up. There are no clocks running in system off mode, so any wakeup must be externally triggered.

  • Ok I was not sure of that. Because of the fact that in wheel.c the QDEC device is put in DEVICE_PM_SUSPEND_STATE after some inactivity delay I was thinking the device could even reach the system OFF state if there was no other activity... But indeed it is certainly system ON low power mode that I reach in my case, and I guess this behaviour is automatic since I don't call code to explicitely go into this state.

    But my aim in the end is to go to system OFF mode to consume as less power as possible, with qdec pins being able to wake up the device, registering GPIO interrupts for that.
    So if I understand correctly your answer, the simple fact that the dongle is powered through USB should not theoretically block the possibility to remain in sleep mode or system OFF mode? I wanted a confirmation especially because I read that "When in System OFF mode, the device can be woken up through one of the following signals" ... "4. Detecting a valid USB voltage on the VBUS pin (VBUS,DETECT)."  here infocenter.nordicsemi.com/index.jsp

    Thanks

  • Hi,

    Sorry, I forgot to comment on system off and USB. I do not believe it is possible for the device to stay in system off mode while supplied via USB. I do not think that has been considered a realistic scenario, as also in system ON mode current consumption is very low, and typically anything with a USB host is not so low power.

    May I ask a bit about your product, as this is something you see a need for?

  • Ok thank you for the precision !
    In fact I just want to do have a rotary encoder that triggers BLE advertisements when rotated, and that then goes to the lowest possible power consumption mode. Rotating it again should wake it up, and so on. I may add some basic buttons too, that would send different BLE advertisement data.
    This is a remote command device for a device I made.
    So in the end I want to power the device with a cell coin, and I won't need USB at all :)

    I was asking before soldering SB1 and cutting SB2 to switch to another power source because powering through USB is more convenient at the current stage of my prototyping...
    So it seems I am obliged to switch to an external power source if I want to do real testing.

    Thanks

Reply
  • Ok thank you for the precision !
    In fact I just want to do have a rotary encoder that triggers BLE advertisements when rotated, and that then goes to the lowest possible power consumption mode. Rotating it again should wake it up, and so on. I may add some basic buttons too, that would send different BLE advertisement data.
    This is a remote command device for a device I made.
    So in the end I want to power the device with a cell coin, and I won't need USB at all :)

    I was asking before soldering SB1 and cutting SB2 to switch to another power source because powering through USB is more convenient at the current stage of my prototyping...
    So it seems I am obliged to switch to an external power source if I want to do real testing.

    Thanks

Children
No Data
Related