<?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>PWM event generation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68568/pwm-event-generation</link><description>I am working with the PWM driver to drive a stepper motor and I have a couple of doubts about when all the events are generated. My doubts are related to events: 
 
 NRF_PWM_EVENT_SEQEND0 &amp;amp;&amp;amp; NRF_PWM_EVENT_SEQEND1 
 NRF_PWM_EVENT_LOOPSDONE 
 NRF_PWM_EVENT_PWMPERIODEND</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 25 Nov 2020 09:59:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68568/pwm-event-generation" /><item><title>RE: PWM event generation</title><link>https://devzone.nordicsemi.com/thread/281745?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2020 09:59:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a0496d1-7d69-47ce-be96-13418c266153</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Enrique&lt;/p&gt;
&lt;p&gt;I use the GPIOTE and PPI peripherals to connect the PWM events to pins, allowing me to track them on an oscilloscope.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to do the same you can use the following code to set it up:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    NRF_GPIOTE-&amp;gt;CONFIG[0] = GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                            GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                            (32 + 10) &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
    NRF_GPIOTE-&amp;gt;CONFIG[1] = GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                            GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                            (32 + 11) &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
    NRF_GPIOTE-&amp;gt;CONFIG[2] = GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                            GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                            (32 + 12) &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
    NRF_GPIOTE-&amp;gt;CONFIG[3] = GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                            GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                            (32 + 13) &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;

    NRF_PPI-&amp;gt;CH[0].EEP = (uint32_t)&amp;amp;NRF_PWM0-&amp;gt;EVENTS_PWMPERIODEND;
    NRF_PPI-&amp;gt;CH[0].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[0];
    NRF_PPI-&amp;gt;CH[1].EEP = (uint32_t)&amp;amp;NRF_PWM0-&amp;gt;EVENTS_LOOPSDONE;
    NRF_PPI-&amp;gt;CH[1].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[1];
    NRF_PPI-&amp;gt;CH[2].EEP = (uint32_t)&amp;amp;NRF_PWM0-&amp;gt;EVENTS_SEQEND[0];
    NRF_PPI-&amp;gt;CH[2].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[2];
    NRF_PPI-&amp;gt;CH[3].EEP = (uint32_t)&amp;amp;NRF_PWM0-&amp;gt;EVENTS_SEQEND[1];
    NRF_PPI-&amp;gt;CH[3].TEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[3];
    NRF_PPI-&amp;gt;CHENSET = 0xF;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The GPIO&amp;#39;s used in this case is P1.10-P1.13, mapped to PWMPERIODEND, LOOPSDONE, SEQEND[0] and SEQEND[1] respectively.&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: PWM event generation</title><link>https://devzone.nordicsemi.com/thread/281658?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2020 17:27:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:655cb0af-22d6-4e46-8c37-0b6d56b43cca</guid><dc:creator>spw</dc:creator><description>&lt;p&gt;I am curious about:&lt;br /&gt;- What is the frequency you used to the PWM? &lt;br /&gt;I used a &lt;strong&gt;1 MHZ&lt;/strong&gt; frequency with a &lt;strong&gt;top_count&lt;/strong&gt; of 500.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;- How did you count the number of events?&amp;nbsp;&lt;br /&gt;I used a timer counter with a PPI trigger interaction. Did you use the same or other approach?&lt;br /&gt;&lt;br /&gt;I will review the code on my end, maybe there is something&amp;nbsp;I missed or I can provide further info about it.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;&lt;br /&gt;Enrique.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM event generation</title><link>https://devzone.nordicsemi.com/thread/281649?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2020 16:31:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad807a55-e46a-4339-8e3a-c51e3cbf7006</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried running the complex playback function, and the results seem to be as expected:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrf_drv_pwm_complex_playback(&amp;amp;m_pwm0, &amp;amp;seq0, &amp;amp;seq1, 4, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Since I run the loop four times I see the SEQEND0 and SEQEND1 events happening 4 times one after the other, followed by the LOOPSDONE event happening once at the very end.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The PWMPERIODEND event happens at a much higher rate, as it follow the PWM frequency.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If I run the&amp;nbsp;nrfx_pwm_simple_playback(..) function, more similar to your example, I see that the SEQEND1 and LOOPSDONE events occur repeatedly at the same rate, while the PERIODEND event occurs&amp;nbsp;X times as often, where X is the length of the sequence.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So I am a bit unsure how you got the results you listed earlier. In particular it seems odd that the PERIODEND event would happen less frequent than the SEQEND0 and SEQEND1 events. This shouldn&amp;#39;t really be possible...&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: PWM event generation</title><link>https://devzone.nordicsemi.com/thread/281405?ContentTypeID=1</link><pubDate>Mon, 23 Nov 2020 18:39:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a2ed01c-2e8d-448b-8fae-e0c3819d576a</guid><dc:creator>spw</dc:creator><description>&lt;p&gt;Yes, I have seen that figure. It&amp;#39;s the one I used to assume when the&amp;nbsp;&lt;span&gt;events&amp;nbsp;was supposed to be generated. Thanks for confirming that my assumptions were correct, I was a bit worry to have misunderstood the figure.&lt;br /&gt;&lt;br /&gt;I know the SEQEND events are generated at reading of the last byte, that makes sense. It seemed to me that&amp;nbsp;such detail would not affect to the question, since that should not affect the amount of events generated.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Thanks for taking a look to it.&lt;br /&gt;&lt;br /&gt;regards,&lt;br /&gt;&lt;/span&gt;&lt;span&gt;spw&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM event generation</title><link>https://devzone.nordicsemi.com/thread/281271?ContentTypeID=1</link><pubDate>Mon, 23 Nov 2020 09:49:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e52952c1-a834-4755-b421-03c627b3aab1</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you checked figure 6 in the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/pwm.html?cp=4_0_0_5_16"&gt;PWM peripheral documentation&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;Essentially the SEQEND events are generated when the last byte is read from the corresponding sequence registers, which happens before the playback is completed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This&amp;nbsp;allows you to safely rewrite the data stored in the sequence buffer, knowing that the PWM peripheral is done reading from it.&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;ul&gt;&lt;li&gt;NRF_PWM_EVENT_LOOPSDONE&lt;br /&gt;&lt;br /&gt;Generated when both sequences (0 and 1) have being finished the number specified by playback_count.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;NRF_PWM_EVENT_PWMPERIODEND&lt;br /&gt;&lt;br /&gt;Generated each time &lt;strong&gt;top_count&lt;/strong&gt; is reached.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;[/quote]
&lt;p&gt;Yes, that sounds correct.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regarding the number of events you see I think I will need to reproduce this myself. I will do some tests tomorrow when I have access to the necessary tools.&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></channel></rss>