<?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>Duty Cycle, Sequence Values, and Top Value Relationship to achieve 50% duty cycle</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65019/duty-cycle-sequence-values-and-top-value-relationship-to-achieve-50-duty-cycle</link><description>I&amp;#39;m using Ubuntu 20.04, SES 4.52c, SDK 16 nRF52840 DK board. 
 I&amp;#39;m going to need to use the PWM driver to supply clock pulses to an I2S microphone and the I2S peripheral running in slave mode. So I decided to practice a little with the PWM driver. I started</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 Aug 2020 11:19:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65019/duty-cycle-sequence-values-and-top-value-relationship-to-achieve-50-duty-cycle" /><item><title>RE: Duty Cycle, Sequence Values, and Top Value Relationship to achieve 50% duty cycle</title><link>https://devzone.nordicsemi.com/thread/265525?ContentTypeID=1</link><pubDate>Thu, 20 Aug 2020 11:19:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b550aeff-bc73-44ca-9dce-55ad81fb74f0</guid><dc:creator>matty</dc:creator><description>&lt;p&gt;Thank you haakonsh.&lt;/p&gt;
&lt;p&gt;Question 3 - I missed the Connector Interface section for the nRF52840 DK. I&amp;#39;ve got to open my eyes.&lt;/p&gt;
&lt;p&gt;Question 2 - I am working on your 2nd suggestion and think it will do the job. I&amp;#39;ll definitely check out your first suggestion.&lt;/p&gt;
&lt;p&gt;Question 1 - This all originated from Devzone case ID&amp;#39;s:&amp;nbsp;&lt;span&gt;115712, 114746,&amp;nbsp;112874,&amp;nbsp;235644, etc. I&amp;#39;m using the same Knowles microphone and need 24bit&amp;nbsp;data from a 1 to 4 MHz SCK. I think the only solution is to use the PWM Driver to supply the SCK and WS/LRCK to the I2S Peripheral setup in Slave Mode. Decoding the I2S Peripheral&amp;#39;s output will be another challenge.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot;You&amp;#39;ve measured a difference in time of two full periods, not a peak and a trough.&amp;nbsp;&amp;quot; That was a key observation for me, I didn&amp;#39;t understand that control of the PWM, (top value / sequence value), was an entire period for the PWM.&amp;nbsp;Putting these PWM outputs together produces a &amp;quot;square wave&amp;quot; with a given period. It is beginning to make sense to me now.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks again for your fast response.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duty Cycle, Sequence Values, and Top Value Relationship to achieve 50% duty cycle</title><link>https://devzone.nordicsemi.com/thread/265475?ContentTypeID=1</link><pubDate>Thu, 20 Aug 2020 08:11:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d0effe7-ef3b-4c19-b0a2-5d76aacf5e93</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Why can&amp;#39;t you generate the MCK with the I2S peripheral?&lt;br /&gt;&lt;br /&gt;I think you can use just one PWM for both your outputs if you intend to use the same PWM frequency for both outputs.&amp;nbsp;&lt;/p&gt;
[quote user=""]Question 1: How do you use .top_value and&amp;nbsp;nrf_pwm_values_common_t seq_values[] to produce a 50% duty cycle?&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;The&amp;nbsp;&lt;span&gt;nrf_pwm_values_common_t&amp;nbsp;is an array of uint16_t, so I think it&amp;#39;s just the raw&amp;nbsp;compare value of the timer. Ie. half your COUNTERTOP value for 50% duty-cycle.&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;[quote user=""][/quote]&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve figured out that for a 50% duty cycle, sequence has to be 1/2 of top value but when you look at these two screen shots you can see that the peak and the trough have different widths. Is that to be expected and is it unavoidable?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;That&amp;#39;s not what your scope show. You&amp;#39;ve measured a difference in time of two full periods, not a peak and a trough. What you have shown is that there is a variance in the PWM frequency, which could be due to either capacitive loading or an inaccurate clock. IF the HFCLK is running from the internal 64MHz RC oscillator then there is usually some jitter, but I think a more likely culprit is capacitive loading. The Saleae probes are ~10pF and the pin is 3pF, if there&amp;#39;s other stuff connected then the capacitance increases further. I suggest you start the HFXO and see if that helps, if it does not then it&amp;#39;s definitely due to capacitive loading.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]Question 2: Is there anyway of starting two separate&amp;nbsp;nrfx_pwm_config_t instances simultaneously?[/quote]
&lt;p&gt;&amp;nbsp;You can use the EGU to generate an event and connect it to the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/pwm.html?cp=4_0_0_5_16_4_1#register.TASKS_SEQSTART-0-1"&gt;TASKS_SEQSTART[n]&lt;/a&gt;&amp;nbsp;task of both PWM instances (you need to &amp;#39;fork&amp;#39; the event).&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]If I wanted my 2nd channel to have a duty cycle that was 32x&amp;#39;s larger than my first channel, how would I put the sequence array together?[/quote]
&lt;p&gt;&amp;nbsp;Do they still share the same PWM frequency (COUNTERTOP)? If so the sequence value must be 32x larger.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]Question 3: Is there any reason GPIO pins 0.00 through 0.10 wouldn&amp;#39;t be available for use by the PWM Driver?[/quote]
&lt;p&gt;&amp;nbsp;See&amp;nbsp;&lt;a title="Connector interface" href="https://infocenter.nordicsemi.com/topic/ug_nrf52840_dk/UG/nrf52840_DK/connector_if.html?cp=4_0_4_7_5"&gt;Connector interface&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>