<?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 Driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74578/pwm-driver</link><description>Hello, 
 I want to use the PWM driver to change the output voltage with respect to analog input voltage. If I call the simple_playback_sequence from the SAADC event handler, the voltage only raises for that time but if I call the same function from the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 May 2021 13:02:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74578/pwm-driver" /><item><title>RE: PWM Driver</title><link>https://devzone.nordicsemi.com/thread/310758?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 13:02:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cc3e9cb-3be1-41e6-a372-d24a37648ef9</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;&lt;span&gt;seq_values is still not static,&amp;nbsp;and making the count variable that you copy from static does not help in that regard.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please insert code using Insert -&amp;gt; Code in the future, as that makes it much more readable.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Driver</title><link>https://devzone.nordicsemi.com/thread/310731?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 12:15:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb3710f7-dc36-42b5-b451-64e9a83ca7f9</guid><dc:creator>Charan</dc:creator><description>&lt;p&gt;Still not working.&lt;/p&gt;
&lt;p&gt;Updated code.&lt;/p&gt;
&lt;p&gt;static uint16_t count = 0;&lt;/p&gt;
&lt;p&gt;void timer_handler()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;count+= 1;&lt;/p&gt;
&lt;p&gt;pwm_change();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void pwm_change()&lt;br /&gt;{&lt;br /&gt; nrf_pwm_values_common_t seq_values[] = {&lt;span&gt;count&lt;/span&gt;};&lt;br /&gt; nrf_pwm_sequence_t const seq =&lt;br /&gt; {&lt;br /&gt; .values.p_common = seq_values,&lt;br /&gt; .length = NRF_PWM_VALUES_LENGTH(seq_values),&lt;br /&gt; .repeats = 0,&lt;br /&gt; .end_delay = 0&lt;br /&gt; }; &lt;br /&gt; nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1, NRF_DRV_PWM_FLAG_LOOP);&lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Driver</title><link>https://devzone.nordicsemi.com/thread/310703?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 10:58:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c9b55a5-6fa9-4fa5-8251-147c012f6640</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Your variables are located on the stack, and that is explicitly not supported. Make them static (write &lt;code&gt;static&lt;/code&gt; before the type when you declare them) to ensure that they are not on the stack and remains valid after the function returns.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Driver</title><link>https://devzone.nordicsemi.com/thread/310611?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 06:39:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95c09b00-5c01-494b-a00a-61957e3701df</guid><dc:creator>Charan</dc:creator><description>&lt;p&gt;Hello, Sorry for this extremely late reply.&lt;/p&gt;
&lt;p&gt;I did make the &lt;em&gt;variable count&amp;nbsp;&lt;/em&gt;as static in the second code and it still does not work.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/74578/pwm-driver/308231#308231"] You should make them static instead.[/quote]
&lt;p&gt;Could you please explain what you meant by this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Driver</title><link>https://devzone.nordicsemi.com/thread/308231?ContentTypeID=1</link><pubDate>Tue, 04 May 2021 14:50:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc828e66-2875-4c06-ba47-9c033280edf7</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I do not see any specific issue with setting the PWM from an event handler, but that probably just happens to trigger another issue in your code. I notice that you have the PWM values on the stack, and that will typically cause them to get corrupted as the memory needs to be valid for as long as they are used. You should make them static instead. (API doc states this: &amp;quot;&lt;em&gt;The array containing the duty cycle values for the specified sequence must be in RAM and cannot be allocated on the stack.&lt;/em&gt;&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Driver</title><link>https://devzone.nordicsemi.com/thread/308217?ContentTypeID=1</link><pubDate>Tue, 04 May 2021 13:51:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d181b73d-28c8-440e-925f-32c22dec7e16</guid><dc:creator>Charan</dc:creator><description>&lt;p&gt;Sorry for the late reply, consider timer_handler as a function I call using app_timer library and pwm_change as a function I want to change the PWM value. count is a global variable&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code that Works :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;void timer_handler()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;count+= 1;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void pwm_change()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;nrf_pwm_values_common_t seq_values[] = {&lt;span&gt;count&lt;/span&gt;};&lt;br /&gt; nrf_pwm_sequence_t const seq =&lt;br /&gt; {&lt;br /&gt; .values.p_common = seq_values,&lt;br /&gt; .length = NRF_PWM_VALUES_LENGTH(seq_values),&lt;br /&gt; .repeats = 0,&lt;br /&gt; .end_delay = 0&lt;br /&gt; };&lt;/p&gt;
&lt;p&gt;nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1, NRF_DRV_PWM_FLAG_LOOP);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;int main()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;// Initialise peripherals...&lt;/p&gt;
&lt;p&gt;while(1)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;idle_state_handle();&lt;/p&gt;
&lt;p&gt;pwm_change();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Code that does not Work :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;void timer_handler()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;count+= 1;&lt;/p&gt;
&lt;p&gt;pwm_change();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void pwm_change()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;nrf_pwm_values_common_t seq_values[] = {&lt;span&gt;count&lt;/span&gt;};&lt;br /&gt;nrf_pwm_sequence_t const seq =&lt;br /&gt;{&lt;br /&gt;.values.p_common = seq_values,&lt;br /&gt;.length = NRF_PWM_VALUES_LENGTH(seq_values),&lt;br /&gt;.repeats = 0,&lt;br /&gt;.end_delay = 0&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1, NRF_DRV_PWM_FLAG_LOOP);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;int main()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;// Initialise peripherals...&lt;/p&gt;
&lt;p&gt;while(1)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;idle_state_handle();&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The place where I call pwm_change is what&amp;#39;s changed between the codes. If i call from main(), it functions well but if I call from any event handler, the PWM breaks continuously.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Driver</title><link>https://devzone.nordicsemi.com/thread/307428?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 10:58:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2504a9ea-bdf7-4b3e-b8a0-6ab6d95d9e58</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This does not immediately make sense to me. Can you explain in more detail, and show with code what you do?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>