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 :)
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
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
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.
Hi,I switched to external power, and now the dongle stays in sleep or OFF mode To enter Sytem OFF mode I call "nrf_power_system_off(NRF_POWER);" as I didn't succeed to call "sd_power_system_off();" (I can't include the proper header file)... But it seems to work and power consumption goes very low, around 1uA or less. But then I can't wake up the device with classic GPIO interrupts.So I figured out that to be able to wake up the dongle from sleep or OFF mode I have to use the "sense" API.So I call "nrf_gpio_cfg_sense_input" for the two pins of the QDEC device and it works: a rotation of the device wakes up the dongle.But with this call to "nrf_gpio_cfg_sense_input" the power consumption is then far higher in OFF mode : ~100uADo you know what could be the cause of that? I tried pull down instead of pull up... but it is the same.Maybe something must be deactivated ? I was wondering about RAM retention settings but I read that power usage should not be so different with or without RAM retention...So just adding this call makes the wake-up from OFF mode work, but increases a lot power consumption: nrf_gpio_cfg_sense_input( qdec_pin, GPIO_PIN_CNF_PULL_Disabled, // I have external pull up GPIO_PIN_CNF_SENSE_Low);Thank you
I restarted from the beginning, and enabling things one after the other led me to this : Before enabling or disabling the QDEC device I manually configured the QDEC pins as GPIO INPUT, and this seems to be the cause of a so high current consumption in System OFF mode.
Now I reach 8uA, that's far better :) But it seems to me that it is still too high for just sensing two pins for the potential wake up...So maybe now I should dig into tuning RAM retention, or something else? If you have any clue...Thanks
Sorry for the multiple messages...In fact 8uA of current consumption was due to USB still being plugged after programming the dongle. Without being plugged, my multimeter reports a consumption below 1uA :)
Good to hear. That is about what you should expect.