<?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>How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10478/how-to-control-two-channes-pwm-independently</link><description>Maybe I should post my all the code here. 
 I want to generate two kinds of PWM1 and PWM2,used by the code as follows:
static volatile bool ready_flag; 
 APP_PWM_INSTANCE(&amp;amp;PWM1,1);
APP_PWM_INSTANCE(&amp;amp;PWM2,2); 
 void pwm1_ready_callback(void)
{
ready_flag</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 27 Nov 2015 06:32:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10478/how-to-control-two-channes-pwm-independently" /><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38935?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 06:32:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d6b20d2-a4a4-4898-bf9b-70741398951e</guid><dc:creator>Milk</dc:creator><description>&lt;p&gt;Thank you very much,I succeed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38928?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 06:31:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a2073a7-e75d-4725-8382-d1764475e323</guid><dc:creator>Milk</dc:creator><description>&lt;p&gt;I have tried for several times since I had taken your advice.Thank you very much,I succeed.Thank you again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38927?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 03:44:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df8eaa3d-38e0-4c66-8e12-6c6fa13d3921</guid><dc:creator>Masa</dc:creator><description>&lt;p&gt;Which SDK version are you using? As Ole mentioned, If you are not using SDK 10.0.0, bring app_pwm.c and app_pwm.h from SDK 10.0.0 which fix higher power consumption. Then you don&amp;#39;t need to use &lt;code&gt;app_pwm_uninit&lt;/code&gt;. &lt;code&gt;app_pwm_disable&lt;/code&gt; should be enough to get minimum power consumption.&lt;/p&gt;
&lt;p&gt;And also you don&amp;#39;t need to call gpiote functions because app_pwm handles them.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38939?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 03:44:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03e0548e-d8b2-45ee-80ae-9871c0f4bc78</guid><dc:creator>Milk</dc:creator><description>&lt;p&gt;I have posted my all code above,would you find what goes wrong？&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38938?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 03:24:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a263daa5-4d5f-4c84-8f30-83ca618398ed</guid><dc:creator>Masa</dc:creator><description>&lt;p&gt;About &lt;code&gt;APP_PWM_INSTANCE&lt;/code&gt;, see app_pwm.h. It just makes instances such as nrf_drv_timer, app_pwm_cb_t and so on for PWM.&lt;/p&gt;
&lt;p&gt;Regarding &lt;code&gt;APP_PWM_DEFAULT_CONFIG_2CH&lt;/code&gt;, I think there is no magic to reduce power consumption from HFCLK while at least one of the channel is active but if you disable both channles with &lt;code&gt;app_pwm_disable&lt;/code&gt;, then you shouldn&amp;#39;t see any additional power consumption from app_pwm. But I haven&amp;#39;t tested it by myself since I don&amp;#39;t use &lt;code&gt;APP_PWM_DEFAULT_CONFIG_2CH&lt;/code&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38937?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 03:05:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a166b02f-0c06-403d-a5bc-a6cfe39ce88c</guid><dc:creator>Milk</dc:creator><description>&lt;p&gt;The &lt;strong&gt;APP_PWM_INSTANCE&lt;/strong&gt; macro you mentioned,I do not  understand,would you please explain it detailedly.&lt;/p&gt;
&lt;p&gt;And you said &lt;strong&gt;APP_PWM_DEFAULT_CONFIG_2CH&lt;/strong&gt;,I have tried,but it brings the high power consumption,you can test it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38936?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 02:48:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bda126df-f24d-4ce6-972c-0fd8c73bf861</guid><dc:creator>Masa</dc:creator><description>&lt;p&gt;I might find a solution. If you want to use two PWM and they are not same frequency(I had problem on this situation), simply make two instances and initialize them by using two timers.&lt;/p&gt;
&lt;p&gt;But if you don&amp;#39;t use &lt;code&gt;APP_PWM_INSTANCE&lt;/code&gt; macro, make sure that they don&amp;#39;t share same &lt;code&gt;app_pwm_cb_t&lt;/code&gt; instance. I didn&amp;#39;t use the macro and lazily shared the same &lt;code&gt;app_pwm_cb_t&lt;/code&gt; instance by two &lt;code&gt;app_pwm_t&lt;/code&gt; instances and that was causing strange behavior.&lt;/p&gt;
&lt;p&gt;And if you want to use two PWM with same frequency, use &lt;code&gt;APP_PWM_DEFAULT_CONFIG_2CH&lt;/code&gt; as Ole mentioned and only use &lt;code&gt;app_pwm_disable&lt;/code&gt; if you want to disable both channels. If one of the channel is still active, setting duty 0 for unused channel might be enough by using &lt;code&gt;app_pwm_channel_duty_set&lt;/code&gt; function.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38926?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 02:18:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c046dadc-3f0d-4698-ae06-81b9ce8c05fc</guid><dc:creator>Masa</dc:creator><description>&lt;p&gt;+1
I&amp;#39;m trying to do something similar and doesn&amp;#39;t work. If you find a solution, please share it here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38933?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2015 01:20:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c20aede-645e-4f3b-be4c-048a7759b55e</guid><dc:creator>Milk</dc:creator><description>&lt;p&gt;You mean that if I call  app_pwm_uninit(...),it will solve the problem that I mentioned.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38932?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2015 10:28:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4523591-c1ea-48ff-b010-1aa2701a277a</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;In the SDK 10 driver app_pwm_disable(...) will call nrf_drv_gpiote_task_disable(...).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38931?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2015 10:11:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f95ccf06-85fe-4b0f-87a3-4152e15bc138</guid><dc:creator>Milk</dc:creator><description>&lt;p&gt;Hi,Ole Bauck.
I use the RC to operate the system.I call  nrf_drv_gpiote_task_disable(LED_0) for cutting off the relation between LED_0 and gpiote.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38934?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2015 09:24:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4c53a66-31c0-4ad6-adcf-276de53f70a4</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;First of all you should use the app_pwm driver from SDK 10, this has some fixes to app_pwm_disable and app_pwm_uninit that caused inverted pwm output.
It is not necessary to call nrf_drv_gpiote_task_disable(LED_0), doing this may cause strange behaviour.
Calling app_pwm_disable will stop the timer, if both pwm instances (PWM1 and PWM2) is disabled and no other peripheral is requiring the HFCLK, the HFCLK will be stopped or go to idle (depending on RC or XTAL used) and thereby reduce the power consumption.
app_pwm_uninit will call app_pwm_disable if pwm is enabled and then deallocate the resources.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38941?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2015 02:12:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7dbdc2b6-590b-4af3-8fb6-6d1156b36c6d</guid><dc:creator>Milk</dc:creator><description>&lt;p&gt;Firstly,I initialized two PWMs as mentioned above.Sometimes I want to close one of them.&lt;/p&gt;
&lt;p&gt;For example,I want to close LED_0,&lt;strong&gt;so I call the funtion as follows:&lt;/strong&gt;
void pwm_led0_close()
{ uint32_t err_code;
app_pwm_disable(&amp;amp;PWM1);
nrf_drv_gpiote_out_task_disable(LED_0);
error_code = app_pwm_uninit(&amp;amp;PWM1);
APP_CHECK_ERROR(error_code);}
It worked to LED0,but as a result,It influenced the state of LED_1.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;As the same,when I close the LED_1 as the follows:&lt;/strong&gt;
void pwm_led1_close()
{ uint32_t err_code;
app_pwm_disable(&amp;amp;PWM2);
nrf_drv_gpiote_out_task_disable(LED_1);
error_code = app_pwm_uninit(&amp;amp;PWM2);
APP_CHECK_ERROR(error_code);}
It worked to LED_1,but It influenced the state of LED_0,
My question is how to close one of them under not influencing the state of another?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38930?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2015 01:03:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:432290a1-0454-4093-92bc-485035d58f74</guid><dc:creator>Milk</dc:creator><description>&lt;p&gt;I have tried to use the 2 channel config:APP_PWM_DEFAULT_CONFIG_2CH(...),but if I want to close one of them,I should call the function  app_pwm_disable(...),the result is all of them are closed,it is not I really want.
Then I use the APP_PWM_DEFAULT_CONFIG_1CH(...) to initialize two independently.But it also does not woks.&lt;/p&gt;
&lt;p&gt;When I called the pwm_led0_close() as the follows:
void  pwm_led0_close()
{
uint32_t err_code;
app_pwm_disable(&amp;amp;PWM1);
nrf_drv_gpiote_out_task_disable(LED_0);
error_code = app_pwm_uninit(&amp;amp;PWM1);
APP_CHECK_ERROR(error_code);
}&lt;/p&gt;
&lt;p&gt;The state of LED_1 also closed,it means the function pwm_led0_close() influences the state of LED_1.
In addition, calling the app_pwm_disable(...)  will stop the timer but will not reducing the power consumption.Only calling the the app_pwm_disable(...) and app_pwm_uninit(&amp;amp;PWM1) together will reducing the power consumption.&lt;a href="https://devzone.nordicsemi.com/question/54808/correct-procedure-for-uninitializingreinitializing-app_pwm/"&gt;&lt;strong&gt;app_pwm.c&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38929?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 12:26:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:132dfbff-3741-4188-b069-a76e43b5a9ba</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;The two pwm instances should not influence each other. Can you explain more in detail what your problem is? You can use the 2 channel config: APP_PWM_DEFAULT_CONFIG_2CH(...) if the two pwm channels should have the same frequency. Generally app_pwm_disable(...) is for stopping the timer and may reduce power consumption, app_pwm_uninit(...) is for releasing allocated resources in addition to disabling the pwm. If you want the output to be low you can set the pwm value to zero.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to control two channes PWM independently?</title><link>https://devzone.nordicsemi.com/thread/38940?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 10:45:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:584ac047-3b20-4c4f-a892-d3c82f655fb6</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;I do not really understand the question. What do you want to control of the PWM? Or what is the difference between these PWM&amp;#39;s?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>