<?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>Quadrature decoder settings for motor encoder</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77632/quadrature-decoder-settings-for-motor-encoder</link><description>Hello community, I tried to read my motor encoders with the QDEC and capture the position of my motor. Hardware: nRF52840 DK, 2 Hal motor encoders on pin 0.13 and 0.14 which are supplied with an external voltage of 3.3V. Unfortunately, in my test setups</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 Jul 2021 08:35:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77632/quadrature-decoder-settings-for-motor-encoder" /><item><title>RE: Quadrature decoder settings for motor encoder</title><link>https://devzone.nordicsemi.com/thread/321977?ContentTypeID=1</link><pubDate>Tue, 27 Jul 2021 08:35:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f268c8b4-153d-482b-9c25-5de79a03d97d</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I see you have based your code on the SDK example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To be honest I am not sure exactly what the SDK example is trying to show, so I made my own modified example instead:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/273524_5F00_qdec_5F00_simple.zip"&gt;devzone.nordicsemi.com/.../273524_5F00_qdec_5F00_simple.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This example sets up a simulated QDEC signal on pins 3 and 4, and configures the QDEC peripheral to use inputs 29 and 30.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Every time a new report is ready it simply prints the status of that report to the log, and lets the QDEC run continuously.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you give this example a go and see if it works better?&lt;/p&gt;
&lt;p&gt;If you connect the simulated pins to the input it should report a frequency of ~200Hz, as set by the call to&amp;nbsp;qdec_simulator_set(200); in main.c&lt;/p&gt;
&lt;p&gt;If you connect your own input it should hopefully show the speed of your motor.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I moved all the QDEC parameters into the main function to make it more obvious how the QDEC is configured.&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: Quadrature decoder settings for motor encoder</title><link>https://devzone.nordicsemi.com/thread/321680?ContentTypeID=1</link><pubDate>Mon, 26 Jul 2021 04:31:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afa2e932-e66d-4e59-84c5-824e55dfacac</guid><dc:creator>Mechatroniker</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;includes.h&amp;quot;


APP_PWM_INSTANCE(motor_pwm, PWM_TIMER);


int main(void)
{

    while(1)
    {
          if(flag == 0b00000000)
          {
              initialisierung_aller_komponenten();
              initialisierung_pwm(&amp;amp;motor_pwm);
          }

          if(nrf_gpio_pin_read(BUTTON_CUSTOM_1) == 0 &amp;amp;&amp;amp; flag == 0b00000001)
          {

              while (MOTOR_STELLUNG &amp;lt;= 1000)
              {
                  for (number_of_pulses=min_number_of_pulses; number_of_pulses&amp;lt;= max_number_of_pulses; number_of_pulses++ )
                  {
                        pulses = number_of_pulses; 
                        nrf_drv_qdec_enable();                  
                        m_report_ready_flag = false;
                        if(nrf_qdec_sample_get() == 1)
                        {
                              MOTOR_STELLUNG = MOTOR_STELLUNG + 1;
                        }
                        else if(nrf_qdec_sample_get() == (-1))
                        {
                              MOTOR_STELLUNG = MOTOR_STELLUNG - 1;
                        }
                        NRF_QDEC-&amp;gt;TASKS_READCLRACC;
                  }
                  min_number_of_pulses  = 1;       
                  NRF_LOG_RAW_INFO(&amp;quot;MOTOR_STELLUNG: %d \r\n&amp;quot;, MOTOR_STELLUNG);
                  NRF_LOG_FLUSH();
              }
          }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is my main.c.&lt;/p&gt;
&lt;p&gt;In the function initialisierung_aller_komponenten() are only a few settings for my other pins and the button.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;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();
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is my functions_qdec.c.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Quadrature decoder settings for motor encoder</title><link>https://devzone.nordicsemi.com/thread/321589?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 13:56:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:217ad972-7a29-4d6a-b257-b50e7b2e18d0</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you able to share your code with me, showing how you initialize the QDEC and how the interrupts are handled?&lt;/p&gt;
&lt;p&gt;I can make the case private if you don&amp;#39;t want to share your code in a public case.&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: Quadrature decoder settings for motor encoder</title><link>https://devzone.nordicsemi.com/thread/321464?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 06:09:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be56b1c3-d967-45e1-9b2e-62233ba8c425</guid><dc:creator>Mechatroniker</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;yes it is an encoder with two phases which are offset by approx. 90&amp;deg;.&lt;br /&gt;&lt;br /&gt;My current solution is with interrupts, I trigger the interrupt and decide in it with the help of a variable and the old encoder values in which direction the motor turns.&lt;/p&gt;
&lt;p&gt;So it already works, I just wanted to get some more basic information about the QDEC&amp;#39;s setting options for such an application.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Quadrature decoder settings for motor encoder</title><link>https://devzone.nordicsemi.com/thread/321111?ContentTypeID=1</link><pubDate>Wed, 21 Jul 2021 11:56:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:835bd599-b530-4b78-b928-838ea5b62027</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For clarity, when you say &amp;#39;two motor encoders&amp;#39; it sounds like you mean two separate encoders that are independent of each other. I assume that is not the case?&lt;/p&gt;
&lt;p&gt;The QDEC only supports one encoder that outputs two phases.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is possible to connect these signals to GPIO interrupts instead of the QDEC, if you want to process them immediately.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is also possible to connect the signals to a timer through the PPI controller, allowing you to measure the length of each pulse with an accuracy of 62.5ns (16MHz base timing).&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: Quadrature decoder settings for motor encoder</title><link>https://devzone.nordicsemi.com/thread/320797?ContentTypeID=1</link><pubDate>Tue, 20 Jul 2021 05:21:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3038d6a6-9c21-4eb5-8fc2-10b4afa1ab02</guid><dc:creator>Mechatroniker</dc:creator><description>&lt;p&gt;Hi Torbjorn,&lt;/p&gt;
&lt;p&gt;I have two motor encoders each with a max frequency of about 470 Hz. Because I drive the motor with a PWM this frequency changes constantly.&lt;br /&gt;&lt;br /&gt;In the SAMPLEPER register I have currently set 1024us, but here I have also tried all other values. (with moderate success)&lt;br /&gt;&lt;br /&gt;I have activated the debounce filter.&lt;br /&gt;&lt;br /&gt;Is there a possibility to let the QDEC trigger not on the SAMPLEPER register but on the toggling of the inputs?&lt;br /&gt;&lt;br /&gt;Best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Quadrature decoder settings for motor encoder</title><link>https://devzone.nordicsemi.com/thread/320745?ContentTypeID=1</link><pubDate>Mon, 19 Jul 2021 14:16:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6be8be1d-dbbe-4e4b-97ba-06aa7361a507</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Do you know what&amp;nbsp;the maximum frequency of your decoder signal will be?&lt;/p&gt;
&lt;p&gt;What is the value of the SAMPLEPER register in the QDEC, which sets the sampling rate of the QDEC?&lt;/p&gt;
&lt;p&gt;Have you tried to enable the debounce filter in order to handle glitches on the inputs?&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>