<?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>Setting a PWM in a seperat library</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74499/setting-a-pwm-in-a-seperat-library</link><description>I try to execute the PWM settings via the library in an extra .h/.c file to keep my main method as small as possible. Unfortunately the program sticks in the ErrCheck and does not execute the PWM. Unfortunately I can not find the error and there is no</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Apr 2021 12:52:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74499/setting-a-pwm-in-a-seperat-library" /><item><title>RE: Setting a PWM in a seperat library</title><link>https://devzone.nordicsemi.com/thread/307495?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 12:52:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a66e36db-28d2-4f5c-90e1-16dfd4b8b6b3</guid><dc:creator>Mechatroniker</dc:creator><description>&lt;p&gt;I finally found the mistake :) &lt;/p&gt;
&lt;p&gt;The command APP_PWM_INSTANCE(motor_pwm, 1); must be placed before the main.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your help &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting a PWM in a seperat library</title><link>https://devzone.nordicsemi.com/thread/307196?ContentTypeID=1</link><pubDate>Wed, 28 Apr 2021 10:06:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc4cb080-9e4c-43ac-be59-979e7a69715e</guid><dc:creator>awneil</dc:creator><description>[quote userid="103445" url="~/f/nordic-q-a/74499/setting-a-pwm-in-a-seperat-library/307129#307129"]writes 0x00000004 to the ErrCode[/quote]
&lt;p&gt;So look up that value to see what it means.&lt;/p&gt;
&lt;p&gt;The documentation for each SDK function call lists its possible error returns.&lt;/p&gt;
&lt;p&gt;You can find the documentation by doing a &amp;#39;Go To Declaration&amp;#39; (not definition) - the documentation is in the comments in the header file.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting a PWM in a seperat library</title><link>https://devzone.nordicsemi.com/thread/307132?ContentTypeID=1</link><pubDate>Wed, 28 Apr 2021 06:00:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:400355ec-57e0-441e-9db7-117f45cf8142</guid><dc:creator>Mechatroniker</dc:creator><description>&lt;p&gt;I tried again after restarting all systems and now I get the ErrCode 0x00000008.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting a PWM in a seperat library</title><link>https://devzone.nordicsemi.com/thread/307129?ContentTypeID=1</link><pubDate>Wed, 28 Apr 2021 05:47:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa81b176-a378-44a0-96b4-5624e80358ce</guid><dc:creator>Mechatroniker</dc:creator><description>&lt;p&gt;Thank you very much for your quick reply.&lt;br /&gt;When I run the program with the debugger, it writes at the position &lt;br /&gt;err_code = app_pwm_init(&amp;amp;motor_pwm, &amp;amp;pwm_config, status_pwm_handler); &amp;nbsp;&lt;br /&gt;0x000000 in the ErrCode. If I continue with the debugger it jumps back to the main.c file. If I go further it jumps back to the functions_pwm.c file and writes 0x00000004 to the ErrCode, then it jumps to the app_error_wak.c file and stays at the position &lt;br /&gt;NRF_BREAKPOINT_COND; &lt;br /&gt;Also with several further switching the program remains now at this place.&lt;br /&gt;&lt;br /&gt;In the Stack this Code appears:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1619588563316v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here my C Code again:&lt;/p&gt;
&lt;p&gt;main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_pwm.h&amp;quot;


#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#include &amp;quot;funktionen_pwm.h&amp;quot;

uint32_t an = 99;
uint32_t aus = 1;



int main(void)
{
    #ifdef PIN
     pins_konfigurieren();
     nrf_gpio_pin_set(15);
      nrf_gpio_pin_clear(14);
    #endif

    initialisierung_pwm();

    while (true)
    {
        wert_setzen_pwm(an);
        nrf_delay_ms(3);
        wert_setzen_pwm(aus);
        nrf_delay_ms(2);

    }

}


/** @} */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;funktionen_pwm.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_pwm.h&amp;quot;

const app_pwm_t motor_pwm;

void initialisierung_pwm(void)
{ 
    APP_PWM_INSTANCE(motor_pwm, 1);

    #define M_CONTR_PWM 16
    #define frequenz_teiler  1000

    static volatile bool status_pwm;
    void status_pwm_handler(uint32_t pwm_id)
    {
        status_pwm = true; 
    }
    ret_code_t err_code;
    app_pwm_config_t pwm_config = APP_PWM_DEFAULT_CONFIG_1CH(frequenz_teiler, M_CONTR_PWM);
    pwm_config.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
    err_code = app_pwm_init(&amp;amp;motor_pwm, &amp;amp;pwm_config, status_pwm_handler);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&amp;amp;motor_pwm);
    while(app_pwm_channel_duty_set(&amp;amp;motor_pwm, 0, 99) == NRF_ERROR_BUSY);
}


void wert_setzen_pwm(uint16_t Wert_PWM)
{
     while(app_pwm_channel_duty_set(&amp;amp;motor_pwm, 0, Wert_PWM) == NRF_ERROR_BUSY);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;funktionen_pwm.h&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#ifndef FUNKTIONEN_PWM_H_
#define FUNKTIONEN_PWM_H_



void initialisierung_pwm(void);
void wert_setzen_pwm(uint16_t);


#endif&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting a PWM in a seperat library</title><link>https://devzone.nordicsemi.com/thread/307062?ContentTypeID=1</link><pubDate>Tue, 27 Apr 2021 14:07:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f12357f8-3dce-4de8-9630-ace52de6e127</guid><dc:creator>awneil</dc:creator><description>[quote userid="103445" url="~/f/nordic-q-a/74499/setting-a-pwm-in-a-seperat-library"]the program sticks in the ErrCheck[/quote]
&lt;p&gt;So use the debugger to put a breakpoint there, and see what the error is.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/3652._5F00_Insert-Code-_2D00_-Nordic-2.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;not as an image!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>