<?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>How to make rotary encoder work with nrf52832</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/125008/how-to-make-rotary-encoder-work-with-nrf52832</link><description>My project uses the rotary encoder having pin A, B and Common with nrf52832. I connected them to pin 9 and 10 and GND. 
 I modified Qdec example to but it does not print the value of position. Please advice. I want to have a low power design too but I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Oct 2025 18:34:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/125008/how-to-make-rotary-encoder-work-with-nrf52832" /><item><title>RE: How to make rotary encoder work with nrf52832</title><link>https://devzone.nordicsemi.com/thread/552101?ContentTypeID=1</link><pubDate>Tue, 21 Oct 2025 18:34:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15f5c969-96d1-40b3-92bc-830867a30070</guid><dc:creator>jalan</dc:creator><description>&lt;p&gt;Per the information, I modified the location of &amp;quot;nrf_drv_qdec_enable();&amp;quot; in the while loop. It still doesn&amp;#39;t work. Please advise. Thanks.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_drv_qdec.h&amp;quot;
#include &amp;quot;nrf_error.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

static volatile bool m_report_ready_flag = false;
static volatile uint32_t m_accdblread;
static volatile int32_t m_accread;
static int32_t m_total_position = 0;

static nrf_drv_qdec_config_t m_qdec_config = {
    .reportper          = 0x00,  // Adjust as needed (e.g., 10 samples per report)
    .sampleper          = 0x06,  // e.g., 8192 us (adjust as needed; 0x00=128us to 0x06=16384us)
    .psela              = 9,   // Change to your rotary encoder A pin 
    .pselb              = 10,   // Change to your rotary encoder B pin 
    .pselled            = NRF_QDEC_LED_NOT_CONNECTED,  // No LED for mechanical encoder
    .ledpre             = 0,   // No LED pre-time
    .ledpol             = NRF_QDEC_LEPOL_ACTIVE_HIGH,
    .dbfen              = false,  // Enable debouncing filter for mechanical encoder
    .sample_inten       = false, // Use report interrupts, not sample
    .interrupt_priority = 6
};


static void qdec_event_handler(nrf_drv_qdec_event_t event)
{
    if (event.type == NRF_QDEC_EVENT_REPORTRDY)
    {
        m_accdblread        = event.data.report.accdbl;
        m_accread           = event.data.report.acc;
        m_report_ready_flag = true;
        nrf_drv_qdec_disable(); // Do not disable QDEC for continuous operation
    }
}

int main(void)
{
    uint32_t err_code;

    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();

    // Initialize hardware with custom config for real encoder
    err_code = nrf_drv_qdec_init(&amp;amp;m_qdec_config, qdec_event_handler);
    APP_ERROR_CHECK(err_code);


    //Configure pull-ups AFTER init (important for mechanical encoders without external pull-ups)
    nrf_gpio_cfg_input(9, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(10, NRF_GPIO_PIN_PULLUP);



    NRF_LOG_INFO(&amp;quot;pin A: %d&amp;quot;, m_qdec_config.psela);
    NRF_LOG_FLUSH();
    NRF_LOG_INFO(&amp;quot;pin B: %d&amp;quot;, m_qdec_config.pselb);
    NRF_LOG_FLUSH();
    NRF_LOG_INFO(&amp;quot;Sampling period: %d&amp;quot;, m_qdec_config.sampleper);
    NRF_LOG_FLUSH();
    NRF_LOG_INFO(&amp;quot;Report period: %d&amp;quot;, m_qdec_config.reportper);
    NRF_LOG_FLUSH();

    NRF_LOG_INFO(&amp;quot;QDEC with real rotary encoder started. Turn the encoder to see position updates.&amp;quot;);
    NRF_LOG_FLUSH();

    while (true)
    {
        nrf_drv_qdec_enable();
        // Wait for a report
        while (! m_report_ready_flag)
        {
            __WFE();
        }

        // Check for double accumulation (should be 0 unless double resolution enabled)
        if (m_accdblread != 0)
        {
            NRF_LOG_WARNING(&amp;quot;Double accumulation detected: %u&amp;quot;, m_accdblread);
        }

        // Accumulate position
        m_total_position += m_accread;

        NRF_LOG_INFO(&amp;quot;Report ready. Delta: %d, Total position: %d&amp;quot;, (int)m_accread, (int)m_total_position);
        NRF_LOG_FLUSH();

        m_report_ready_flag = false;

        
    }
}

/** @} */&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make rotary encoder work with nrf52832</title><link>https://devzone.nordicsemi.com/thread/551692?ContentTypeID=1</link><pubDate>Thu, 16 Oct 2025 11:22:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2318427b-784a-4324-9557-decf7b6506e2</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I suggest to take a step back and use the example as-is first:&lt;br /&gt;&lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/qdec_example.html"&gt;https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/qdec_example.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And it can always be a good idea to check the documentation on expected behavior:&lt;br /&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52832/page/qdec.html"&gt;https://docs.nordicsemi.com/bundle/ps_nrf52832/page/qdec.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Edit: For new development I would also suggest to check out the nRF54L15 and the nRF connect sdk bare metal option:&lt;br /&gt;&lt;a href="https://www.nordicsemi.com/Products/Development-software/nRF-Connect-SDK/Bare-Metal-option-for-nRF54L-Series"&gt;https://www.nordicsemi.com/Products/Development-software/nRF-Connect-SDK/Bare-Metal-option-for-nRF54L-Series&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>