<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81790/setting-qdec-sampleper-value-via-driver-api</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 16 Jan 2022 21:57:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81790/setting-qdec-sampleper-value-via-driver-api" /><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/347889?ContentTypeID=1</link><pubDate>Sun, 16 Jan 2022 21:57:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f788666-0495-45db-87ab-6a05e0f07d04</guid><dc:creator>TS01</dc:creator><description>&lt;p&gt;@someMake, if you don&amp;#39;t mind posting your code, I&amp;#39;d appreciate it. The transition from SDK to Zephyr has been a little hard to wrap my head around.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/346296?ContentTypeID=1</link><pubDate>Wed, 05 Jan 2022 17:23:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbdb810a-6ea1-4c3a-a771-f6d607f46893</guid><dc:creator>someMaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for the suggestions. I have located the source of the problem. The issue was caused by the nrfx_qdec_accumulators_read(&amp;amp;acc, &amp;amp;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...&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;And if your original question &amp;quot;Setting QDEC sampleper value via driver API.&amp;quot;i s still not resolved, I can also provide a suggestion on how it could be done...&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/346082?ContentTypeID=1</link><pubDate>Wed, 05 Jan 2022 09:36:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90ffea7a-2a82-45be-a4b0-1e43947a4598</guid><dc:creator>Grzesiak_Lu</dc:creator><description>&lt;p&gt;Hi!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/345996?ContentTypeID=1</link><pubDate>Tue, 04 Jan 2022 21:26:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31bd8dca-e2f2-49b1-ade6-763c7957f9a5</guid><dc:creator>someMaker</dc:creator><description>&lt;p&gt;Hello all, I am not sure if this question is relevant here...&lt;/p&gt;
&lt;p&gt;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.&lt;br /&gt;&lt;br /&gt;But now I am&amp;nbsp; struggling to get the example to work properly: i.e. I do get non-zero values from the acc and accdbl registers, &lt;strong&gt;if and only if&lt;/strong&gt; the&amp;nbsp;&lt;strong&gt;printk(&amp;quot;Enetered qdec_nrfx_event_handler \n&amp;quot;);&lt;/strong&gt; statement at line 3 of the the&amp;nbsp;qdec_nrfx_event_handler is &lt;strong&gt;present&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;As soon as I comment this line out, the acc and accdbl values will always be zero. Changing the sampleper and reportper values doesn&amp;#39;t help to resolve this. &lt;/p&gt;
&lt;p&gt;I have no clue, what is causing this. What am I missing? Any hints suggestions are welcome...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/340306?ContentTypeID=1</link><pubDate>Tue, 23 Nov 2021 11:04:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3eeb6e78-9577-4485-baa5-34664bee6be5</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What if you remove the device_get_binding call?&lt;/p&gt;
&lt;p&gt;Could you show me your project configuration file?&lt;/p&gt;
&lt;p&gt;When using the nrfx driver directly you should not use the standard Zephyr driver. You have to use one or the other.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/340013?ContentTypeID=1</link><pubDate>Mon, 22 Nov 2021 10:44:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39ff081e-a89f-41b6-aee3-2ad4a7013a06</guid><dc:creator>Grzesiak_Lu</dc:creator><description>&lt;p&gt;&lt;span&gt;Since the nrfx_qdec_init() requires a qdec_nrfx_event_handler&amp;nbsp; I have written a short switch case handler that only printsout some values. I also see that the init function does enable the qdec via nrfx_qdec_enable call, but I added said call nonetheless to my init function.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I also created the manual_isr_setup() function to enable interrupt as was suggested by your newest reply.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;I&amp;#39;m currently unable to figure out why my IRQ setup results in &amp;quot;Spurious Interrupt&amp;quot; behaviour. The code used is shown below:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void StepperControl::init()
{
    qdec_device_ = device_get_binding(DT_LABEL(DT_NODELABEL(qdec)));
    if (!qdec_device_) {
        asm(&amp;quot;nop&amp;quot;);
    }

    static nrfx_qdec_config_t config0 =
    {
        .reportper          = NRF_QDEC_REPORTPER_40,
        .sampleper          = NRF_QDEC_SAMPLEPER_2048us,
        .psela              = DT_PROP(DT_NODELABEL(qdec),a_pin),
        .pselb              = DT_PROP(DT_NODELABEL(qdec),b_pin),
        .pselled            = 0xFFFFFFFF,
        .ledpre             = 500,
        .ledpol             = NRF_QDEC_LEPOL_ACTIVE_HIGH,
        .dbfen              = NRF_QDEC_DBFEN_DISABLE,
        .sample_inten       = false,
        .interrupt_priority = NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY
    };
 
    nrfx_qdec_init(&amp;amp;config0, qdec_nrfx_event_handler);
    nrfx_qdec_enable();
    manual_isr_setup();

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void qdec_nrfx_event_handler(nrfx_qdec_event_t event)
{
    printk(&amp;quot;Enetered qdec_nrfx_event_handler \n&amp;quot;);
	switch (event.type) {
    case NRF_QDEC_EVENT_SAMPLERDY:
        
       
        printk(&amp;quot;SAMPLERDY interrupt \n&amp;quot;);
        break;

	case NRF_QDEC_EVENT_REPORTRDY:
      
        accumulate(&amp;amp;qdec_nrfx_data, event.data.report.acc);
        printk(&amp;quot;REPORTRDY event handled&amp;quot;);
        break;
    default:
      
        printk(&amp;quot;unhandled event (0x%x) \n&amp;quot;, event.type);
        break;
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void manual_isr_setup(void){
    IRQ_DIRECT_CONNECT(QDEC_IRQn,0,
                nrfx_qdec_irq_handler,0);
    
	irq_enable(QDEC_IRQn);

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/339787?ContentTypeID=1</link><pubDate>Fri, 19 Nov 2021 09:59:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50220145-8d8b-4c17-89b8-96a54f28760e</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Lukasz&lt;/p&gt;
&lt;p&gt;Setting up interrupts in Zephyr is a bit different than in the old days, and when using nrfx drivers some manual setup is needed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One of my colleagues made an example showing how to use the nrfx_rtc driver, and he includes the interrupt setup &lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/nrfx/rtc/src/main.c#L59"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It should be possible to do it in a similar way for the nrfx_qspi driver.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/339656?ContentTypeID=1</link><pubDate>Thu, 18 Nov 2021 13:26:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:619fa63a-a208-448f-9679-3627e0aa6940</guid><dc:creator>Grzesiak_Lu</dc:creator><description>&lt;p&gt;Again thank you for your reply.&lt;br /&gt;The issue I ran into now is the fact that nrfx_qdec.c expects me to provide a nrfx_qdec_event_handler_t handler. I have written simple switch case handler but I doesn&amp;#39;t seem to be invoked. When I flash my board i receive following error message.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:00:00.191,406] &amp;lt;err&amp;gt; os: ***** Reserved Exception ( -16) *****
[00:00:00.191,436] &amp;lt;err&amp;gt; os: r0/a1:  0x200138f0  r1/a2:  0x000105b5  r2/a3:  0x000455f7
[00:00:00.191,436] &amp;lt;err&amp;gt; os: r3/a4:  0x00010619 r12/ip:  0x00010619 r14/lr:  0x00010619
[00:00:00.191,467] &amp;lt;err&amp;gt; os:  xpsr:  0x00000000
[00:00:00.191,467] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00010619
[00:00:00.191,467] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
[00:00:00.191,497] &amp;lt;err&amp;gt; os: Current thread: 0x200025d0 (main)
[00:00:00.738,433] &amp;lt;err&amp;gt; fatal_error: Resetting system&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;-16 means a spurious interrupt error. I assume the error means that even tho the board can detect an interrupt has been raised it doesn&amp;#39;t understand its source and neither does it understand which handler to run after detecting said interrupt.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Could you please shed some light on how to register an interrupt to a specific qdec device and how to assign correct handler to it?&lt;br /&gt;&lt;br /&gt;Best regards.&lt;br /&gt;Lukasz&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/339549?ContentTypeID=1</link><pubDate>Thu, 18 Nov 2021 07:15:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b472c842-2aad-4e3e-9c40-b06e340c154f</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes to both.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You have to set CONFIG_NRFX_QDEC=y in your project configuration,&amp;nbsp;include &amp;lt;nrfx_qdec.h&amp;gt; in your project, and use the functions defined in nrfx_qdec.h directly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For reference I made a small example using the nrfx_pwm driver recently, and the principle is more or less the same:&lt;br /&gt;&lt;a href="https://github.com/too1/ncs-nrfx-pwm-simple-example"&gt;https://github.com/too1/ncs-nrfx-pwm-simple-example&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/339419?ContentTypeID=1</link><pubDate>Wed, 17 Nov 2021 12:18:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7075b2c9-98dc-4a83-8306-27111f6a8634</guid><dc:creator>Grzesiak_Lu</dc:creator><description>&lt;p&gt;Thanks for the reply!&lt;br /&gt;Is there a KConfig option I should set or unset in order to chose which qdec driver implementation I am using?&lt;br /&gt;Alternatively should I in my application code make dircet calls to functions defined in nrfx_qdec.c file?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting QDEC sampleper value via driver API.</title><link>https://devzone.nordicsemi.com/thread/339412?ContentTypeID=1</link><pubDate>Wed, 17 Nov 2021 11:56:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a817faa3-3b2c-4915-99b8-14a7cc7a27aa</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Lukasz&lt;/p&gt;
&lt;p&gt;As a general rule when using Nordic peripherals in a Zephyr (or nRF Connect SDK) project you can choose between using the nrfx API, or use the Zephyr driver if one exists.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Using the nrfx API will usually expose more Nordic specific functionality, and allow you to use older software based on the nRF5 SDK, while using the Zephyr driver allows you to write code more aligned to other Zephyr examples.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In this case, if using the qdec_nrfx.c driver does not allow you to set the sample period in a streamlined way I would suggest using the nrfx_qdec driver directly.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>