<?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>QDEC SAMPLEPER Register&amp;#39;Problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14377/qdec-sampleper-register-problem</link><description>Checking QDEC (Quadrature decoder) of nRF52832. 
 But, In a SAMPLEPER Register(0x508) when set to 128us(0) or 256us(1) does not occur SAMPLERDY Event. 
 On the other hand, Setting from 512us(2) to 131ms(10) and SAMPLERDY Event has occurred without problems</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 31 Mar 2019 10:35:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14377/qdec-sampleper-register-problem" /><item><title>RE: QDEC SAMPLEPER Register'Problem</title><link>https://devzone.nordicsemi.com/thread/179355?ContentTypeID=1</link><pubDate>Sun, 31 Mar 2019 10:35:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04f0cf4b-df3b-434e-aa68-398827749450</guid><dc:creator>ivnn</dc:creator><description>&lt;p&gt;same problem with 128us on sdk 15.3, pls help&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: QDEC SAMPLEPER Register'Problem</title><link>https://devzone.nordicsemi.com/thread/54887?ContentTypeID=1</link><pubDate>Wed, 07 Dec 2016 12:07:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec932197-bb21-46e2-88d8-96e0445a39b3</guid><dc:creator>Krzysztof Chruscinski</dc:creator><description>&lt;p&gt;It has been fixed in nRF5 SDK 12.2.0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: QDEC SAMPLEPER Register'Problem</title><link>https://devzone.nordicsemi.com/thread/54886?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2016 07:55:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df449b23-43b1-48e6-a3ea-c769eabe5ad6</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There is an error with the example when using it below 1024 µs, I will forward this information.&lt;/p&gt;
&lt;p&gt;Meanwhile you can use this code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf.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;

#define GPIO_INPUT_A    1
#define GPIO_INPUT_B    2
#define GPIO_INPUT_LED  0
#define GPIO_OUTPUT_LED 17

static void qdec_event_handler(nrf_drv_qdec_event_t event)
{

    if (event.type == NRF_QDEC_EVENT_REPORTRDY)
    {
        /* No implementation */ 
    }
    if (event.type == NRF_QDEC_EVENT_SAMPLERDY)
    {
        nrf_gpio_pin_toggle(GPIO_OUTPUT_LED);
    }
}

int main(void)
{
    uint32_t err_code;
    nrf_gpio_cfg_output(GPIO_OUTPUT_LED);                            
    
    nrf_drv_qdec_config_t qdec_cfg = 
    {
        .reportper = NRF_QDEC_REPORTPER_10,                     /**&amp;lt; Report period in samples. */
        .sampleper = NRF_QDEC_SAMPLEPER_128us,                  /**&amp;lt; Sampling period in microseconds. */
        .psela = GPIO_INPUT_A,                                  /**&amp;lt; Pin number for A input. */
        .pselb = GPIO_INPUT_B,                                  /**&amp;lt; Pin number for B input. */
        .pselled = GPIO_INPUT_LED,                              /**&amp;lt; Pin number for LED output. */
        .ledpre = 10,                                           /**&amp;lt; Time (in microseconds) how long LED is switched on before sampling. */
        .ledpol = 0,                                            /**&amp;lt; Active LED polarity. */
        .dbfen = false,                                         /**&amp;lt; State of debouncing filter. */
        .sample_inten = true,                                   /**&amp;lt; Enabling sample ready interrupt. */
        .interrupt_priority = 3,                                /**&amp;lt; QDEC interrupt priority. */
    };
    
    err_code = nrf_drv_qdec_init(&amp;amp;qdec_cfg, qdec_event_handler);
    APP_ERROR_CHECK(err_code);
    
    nrf_gpio_cfg_input(qdec_cfg.pselb,NRF_GPIO_PIN_PULLUP);     /**&amp;lt; Needed when you don&amp;#39;t have external pullups*/
    nrf_gpio_cfg_input(qdec_cfg.psela,NRF_GPIO_PIN_PULLUP);     /**&amp;lt; Needed when you don&amp;#39;t have external pullups*/
    
    nrf_drv_qdec_enable();
    while (true)
    {
        __WFI();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will change the state of pin 17 every time there is a sample ready. Oscilloscope screenshot for 128µs mode probed on pin 17 can be seen below (Since the pin is toggled every 128µs the total period will be 256µs).&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/QDEC.png" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>