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

I am looking for simple example of HW driver of QDEC for nrf5340.

Hi.
I am looking for simple example of using QDEC for nrf5340.
I want to use the Segger Embedded Studio.


Where can I find the example of some guide for HW driver for nrf5340pdk?
When I compile the project “blinky_pwm” I get the error “Unsupported board: pwm-led0 devicetree alias is not defined”. How can I define the correspond HW?

Parents
  • Hi,

    I am looking for simple example of using QDEC for nrf5340.

     Seems like we are missing some nRF5340 DTS, board and SoC defines for QDEC in NCS and Zephyr, but I will look into creating a simple example for you.

    Where can I find the example of some guide for HW driver for nrf5340pdk?

     We have this guide for working with the nRF5340, https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_nrf5340.html

    When I compile the project “blinky_pwm” I get the error “Unsupported board: pwm-led0 devicetree alias is not defined”. How can I define the correspond HW?

     Seem to be missing this dts define for the nRF5340 PDK and DK. If you add this overlay file in the blink_pwm folder, it should work:

    The overlays can be found in this .zip file:

    blinky_pwm overlays.zip

    The overlay looks like this:

    / {
    	aliases {
    		pwm-led0 = &pwm_led0;
    	};
    };
    
    / {
    pwmleds {
    	compatible = "pwm-leds";
    	pwm_led0: pwm_led_0 {
    		pwms = < &pwm0 0x1c >;
    	};
    };
    };

  • Hi.
    It still doesn't work. I new in Zephyr. Correct me what I am doing wrong.


    I add these 2 files from zip (unpacked) in folder "v1.4.2\zephyr\samples\basic\blinky_pwm". I see the "nrf5340pdk_nrf5340_cpuapp.overlay" in the project space, in "dts files" . But it is still the same error (Unsupported board: pwm-led0...)

    I also tried: remove the second, "nrf5340dk_nrf5340_cpuapp.overlay" from the folder, remove the last curly bracket (it seems without some without opening). I also tried to edit "nrf5340pdk_nrf5340_cpuapp.dts" and add pwm-led0 to the file.
    How can I know what is included in the compilation? For example, in c file I add #error directive to get indication that this part included in compilation.

  • I changed the file 
    "v1.4.2\zephyr\boards\arm\nrf5340dk_nrf5340\nrf5340_cpuapp_common.dts"

    I added the correspond lines form "nrf5340pdk_nrf5340_cpuapp.overlay" to it: added pwmleds in devices node and correspond line in aliases node.

    Now, project is working. Please, correct me if I did something wrong or if there is better way.

  • VadymS said:
    It still doesn't work. I new in Zephyr. Correct me what I am doing wrong.

    Some theories, (1) You might need to open/import the project again for the overlay to take effect. (2) Might need to check the "Clean Build Directory" when you open the project. or (3) Maybe you used the wrong board name, and therefore the overlay was not applied.

    VadymS said:
    Now, project is working. Please, correct me if I did something wrong or if there is better way.

     Great! The way you did it is the best way. It should have been in that file from the start, i.e. similar to how its done in e.g. boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts

  • Update regarding QDEC,

    Zephyr and devicetree support for QDEC on nRF5340 is being added as part of this PR: https://github.com/zephyrproject-rtos/zephyr/pull/32273

    Files modified: https://github.com/zephyrproject-rtos/zephyr/pull/32273/files

    With this added, you can use the qdec_nrfx sensor driver: https://github.com/zephyrproject-rtos/zephyr/tree/master/drivers/sensor/qdec_nrfx

    We use this driver in e.g. nrf_desktop's wheel.c

    https://github.com/nrfconnect/sdk-nrf/blob/v1.4-branch/applications/nrf_desktop/src/hw_interface/wheel.c

    If you are still having issues with QDEC after taking a look at this, then I can create a simple sample that uses the QDEC for you.

  • Hi Sigurd, could you explain how to use this using the callback handler?

    I have it set up for the NRF52840 using CONFIG_QDEC_NRFX (and CONFIG_SENSOR although I guess I rather use it wihout).

    The pins etc are all setup in an overlay file.

    &qdec {
        status = "okay";
        a-pin = <42>;
        b-pin = <43>;
        enable-pin = <30>;
        led-pin = <0xFFFFFFFF>;
        led-pre = <0>;
        steps = <12>;
    };

    When I call this:

     

           int ret = nrfx_qdec_init(conf, rotaryHandler);

    The rotaryHandler is never called, what am I missing?

    I have added a simple read function in a while loop that actually works, but not in the way I want. at least it tells me the hardware setup seems ok.

          void readRotary(){
              int *acc;
              int *accd;
              nrfx_qdec_accumulators_read(&acc, &accd);
              if (acc != prevacc)  printf("acc: %d, Acc double: %d\n", acc, accd);
              prevacc = acc;
              prevaccd = accd;
          }

    running that code show this:

    turning one side: 

    acc: 0, Acc double: 0
    acc: 1, Acc double: 0
    acc: 0, Acc double: 0
    acc: 1, Acc double: 0

    other side:

    acc: 65535, Acc double: 0
    acc: 0, Acc double: 0
    acc: 65535, Acc double: 0

Reply
  • Hi Sigurd, could you explain how to use this using the callback handler?

    I have it set up for the NRF52840 using CONFIG_QDEC_NRFX (and CONFIG_SENSOR although I guess I rather use it wihout).

    The pins etc are all setup in an overlay file.

    &qdec {
        status = "okay";
        a-pin = <42>;
        b-pin = <43>;
        enable-pin = <30>;
        led-pin = <0xFFFFFFFF>;
        led-pre = <0>;
        steps = <12>;
    };

    When I call this:

     

           int ret = nrfx_qdec_init(conf, rotaryHandler);

    The rotaryHandler is never called, what am I missing?

    I have added a simple read function in a while loop that actually works, but not in the way I want. at least it tells me the hardware setup seems ok.

          void readRotary(){
              int *acc;
              int *accd;
              nrfx_qdec_accumulators_read(&acc, &accd);
              if (acc != prevacc)  printf("acc: %d, Acc double: %d\n", acc, accd);
              prevacc = acc;
              prevaccd = accd;
          }

    running that code show this:

    turning one side: 

    acc: 0, Acc double: 0
    acc: 1, Acc double: 0
    acc: 0, Acc double: 0
    acc: 1, Acc double: 0

    other side:

    acc: 65535, Acc double: 0
    acc: 0, Acc double: 0
    acc: 65535, Acc double: 0

Children
Related