Setting QDEC sampleper value via driver API.

Hi!
I am struggling with figuring out how to properly set the sampling frequency for the qdec device. I noticed that making changes directly to the members of config struct of zephyr/drivers/sensor/qdec_nrfx/qdec_nrfx.c seems to do the trick, but I would rather do the changes via device API. 
I noticed that the nrfx_qdec.c driver seem to use necessary API functions declared in nrf_qdec.h. However the function parameters in nrf_qdec_sampleper_set(). Have wrong types compared with nrfx driver. Is there a standardized way of changing the sampling frequency of the qdec device?

Thanks in advance.

Parents
  • Hello all, I am not sure if this question is relevant here...

    I am a novice in embedded development and I am trying to get a mechanical rotary encoder working with the nrf52840dk_nrf52840 board. The code snippets below gave me sufficient hints to get something working, based on the zephyr basic button sample.

    But now I am  struggling to get the example to work properly: i.e. I do get non-zero values from the acc and accdbl registers, if and only if the printk("Enetered qdec_nrfx_event_handler \n"); statement at line 3 of the the qdec_nrfx_event_handler is present.

    As soon as I comment this line out, the acc and accdbl values will always be zero. Changing the sampleper and reportper values doesn't help to resolve this.

    I have no clue, what is causing this. What am I missing? Any hints suggestions are welcome...

Reply
  • Hello all, I am not sure if this question is relevant here...

    I am a novice in embedded development and I am trying to get a mechanical rotary encoder working with the nrf52840dk_nrf52840 board. The code snippets below gave me sufficient hints to get something working, based on the zephyr basic button sample.

    But now I am  struggling to get the example to work properly: i.e. I do get non-zero values from the acc and accdbl registers, if and only if the printk("Enetered qdec_nrfx_event_handler \n"); statement at line 3 of the the qdec_nrfx_event_handler is present.

    As soon as I comment this line out, the acc and accdbl values will always be zero. Changing the sampleper and reportper values doesn't help to resolve this.

    I have no clue, what is causing this. What am I missing? Any hints suggestions are welcome...

Children
  • Hi! 

    When data-acquisition code works with additional printk statement and not without it, that usually means that you have a timing issue. It might be that in your code you are attempting to read the data from encoder registers too quickly, or too slowly. It might also be necessary to clear a DRDY (data ready) or DREAD (data read) flags (pin or or specific bit in a register) after reading the value from the registers depending on the encoder you are using.

    I would start by checking the frequency with which you are attempting to read data against maximum frequency with which the encoder can send new data to the microcontroller. This is usually specified in the datasheet for the encoder.

  • Hello,

    Thank you for the suggestions. I have located the source of the problem. The issue was caused by the nrfx_qdec_accumulators_read(&acc, &accdbl); that I thought I needed. As the data is already included in the event, this statement is not needed. the data is in the event.data.report...

    The code is now working as expected. If you are interested I am happy to post my version which is based on the snippets that you provided.

    And if your original question "Setting QDEC sampleper value via driver API."i s still not resolved, I can also provide a suggestion on how it could be done...

    Best regards,

    Jan

  • @someMake, if you don't mind posting your code, I'd appreciate it. The transition from SDK to Zephyr has been a little hard to wrap my head around.

Related