<?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>Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/27694/pulsewidth-modulation-with-app_pwm-results-in-nrf_error_invalid_state</link><description>I have a nrf51-DK. I am trying to get a PWM signal on one pin. Here is my code: 
 static volatile bool ready_flag;
void pwm_ready_callback(uint32_t pwm_id){ ready_flag = true; } // PWM callback function

void test_pwm(){
 APP_PWM_INSTANCE(PWM1,2</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 06 Jul 2019 08:50:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/27694/pulsewidth-modulation-with-app_pwm-results-in-nrf_error_invalid_state" /><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/196937?ContentTypeID=1</link><pubDate>Sat, 06 Jul 2019 08:50:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95475c89-0303-4755-bd3b-4f48af3a4bd5</guid><dc:creator>Dtink_cp</dc:creator><description>&lt;p&gt;You can try to add two function before you configure:&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;app_pwm_disable(&amp;amp;PWM1);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;err_code = app_pwm_uninit(&amp;amp;PWM1);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Of course, you maybe change PWM1 to which is suited with you&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id="eJOY__extension_root"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109315?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 12:49:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:990a05fd-579a-4b0e-a6dd-882256d23bc2</guid><dc:creator>stephbur</dc:creator><description>&lt;p&gt;I copied all the relevant code into the main function and disabled all imports. Now it seems to work. I will enable imports one by one and see which one was the culprit.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109320?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 12:31:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a9a6038-4320-4984-88d9-6a6c06958f6e</guid><dc:creator>stephbur</dc:creator><description>&lt;p&gt;I am using CLion for editing and gnu-make together with arm-none-eabi-gcc to compile and nrfjprog to flash. All is running on Ubuntu 17.10.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109319?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 12:28:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4354d664-da0b-4297-bf53-017d72c3a61c</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;What IDE/toolchain are you using here ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109318?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 12:26:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e28034cf-6acc-40ff-910e-ccb77f952448</guid><dc:creator>stephbur</dc:creator><description>&lt;p&gt;#include &amp;quot;variables.h&amp;quot;
#include &amp;quot;DAC.h&amp;quot;
#include &amp;quot;DDC.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;sdk_config.h&amp;quot;
#include &amp;quot;setup.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void){
    setup();
    DDC m;
    m.test_pwm();
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;DDC is a class which (in the future) controls a current measurement chip (this is what I need the periodic signal for). At the moment everything in that class is commented out except for some LED control which helps me debug:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void DDC::set_success(int err){
    if (err == NRF_SUCCESS){
        nrf_gpio_pin_write(18, HIGH);
        nrf_delay_ms(500);
    } else {
        nrf_gpio_pin_write(19, HIGH);
        nrf_delay_ms(500);
      }
  }
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109317?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 12:15:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5988b76-173c-4d8a-a06e-c948558a8de7</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;app_pwm_init takes care of initializing GPIOs, so you dont need to use the nrf_gpio_cfg_output.&lt;/p&gt;
&lt;p&gt;nRF51 only have 3 TIMERS. nRF52832 have TIMER3 and TIMER4, but the nRF51 dont have them.&lt;/p&gt;
&lt;p&gt;Could you upload your main.c here ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109316?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 12:02:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6e6ba6c-b9f4-423c-806f-178db79861f3</guid><dc:creator>stephbur</dc:creator><description>&lt;p&gt;I do not use any Timer nor a SoftDevice. It happens with TIMER0, TIMER1 and TIMER2. For some reason I cannot enable TIMER3/4 to test with them. I only call app_pwm_init() once. Defining the pin with nrf_gpio_cfg_output(17); should be alright, isn&amp;#39;t it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109313?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 11:59:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f111998-aafa-4ba2-bb1e-b9397d0ab4a3</guid><dc:creator>stephbur</dc:creator><description>&lt;p&gt;the only thing I call in my main function is a setup function (which defines pins as input/output) and the function written above.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109312?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 11:53:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba929e2f-29f9-4f5e-b748-a6cbb55d0a51</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Could you post the code for the main() function ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE</title><link>https://devzone.nordicsemi.com/thread/109314?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 11:51:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3555405f-4666-4f56-9552-74d348ba599e</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The function &lt;code&gt;app_pwm_init()&lt;/code&gt; will return &lt;code&gt;NRF_ERROR_INVALID_STATE&lt;/code&gt; if the timer/PWM is already in use or if initialization failed. Are you calling the function app_pwm_init() more than once?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>