<?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 change  a pin between GPIO and PWM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71288/how-to-change-a-pin-between-gpio-and-pwm</link><description>Hi There 
 My design is basic on nrf52840. I need a pin be controlled alternately by GPIO module and PWM module in my application. The PWM function is realized by setting the PWM hardware module, as in the SDK example (nRF5_SDK_16.0.0_98a08e2\examples</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Mar 2021 23:00:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71288/how-to-change-a-pin-between-gpio-and-pwm" /><item><title>RE: How to change  a pin between GPIO and PWM</title><link>https://devzone.nordicsemi.com/thread/297325?ContentTypeID=1</link><pubDate>Tue, 02 Mar 2021 23:00:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aff02c1b-70f1-4a61-aeda-26ab60411ae9</guid><dc:creator>Di-sheng</dc:creator><description>&lt;p&gt;Ok, I got it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change  a pin between GPIO and PWM</title><link>https://devzone.nordicsemi.com/thread/292784?ContentTypeID=1</link><pubDate>Thu, 04 Feb 2021 00:14:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c66bde5f-6092-4a9e-896f-85f67af25a1e</guid><dc:creator>Di-sheng</dc:creator><description>&lt;p&gt;Hi SmallerPond,&lt;/p&gt;
&lt;p&gt;Thanks&amp;nbsp; for your replay.&lt;/p&gt;
&lt;p&gt;The code is&amp;nbsp; great.&lt;/p&gt;
&lt;p&gt;U&lt;span class="skip"&gt;nfortunately, I can not use this.&amp;nbsp;Because I used all channels of the PWM module and these channels cannot be stopped at the same time, that means some pins assigned to the PWM module need to be converted to be controlled by GPIO, while others still need to continue to output the PWM signal&amp;nbsp;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="skip"&gt;Thank you very much again.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="skip"&gt;B,Rs&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="skip"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="skip"&gt;Di-sheng&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change  a pin between GPIO and PWM</title><link>https://devzone.nordicsemi.com/thread/292780?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2021 23:02:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:887662d4-4382-4ac5-8668-3a18363912e7</guid><dc:creator>SmallerPond</dc:creator><description>&lt;p&gt;Actually, I thought I&amp;#39;d give it a try and you only have to stop the pwm and the gpio will work:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrfx_pwm.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#define PWM_GPIO_PIN                     NRF_GPIO_PIN_MAP(1, 12)

/* Create the PWM instance */
static nrfx_pwm_t m_pwm0 = NRFX_PWM_INSTANCE(0);

/* PWM values */
static nrf_pwm_values_common_t seq_values[] =
{
    4, 4, 4, 4, 16, 16, 16, 16, 6, 6, 6, 6, 12, 12, 12, 12,
    3, 3, 3, 3, 15, 15, 15, 15, 1, 1, 1, 1, 13, 13, 13, 13,
};

static nrf_pwm_sequence_t const seq =
{
    .values.p_common = seq_values,
    .length          = NRF_PWM_VALUES_LENGTH(seq_values),
    .repeats         = 10,
    .end_delay       = 0
};

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    nrfx_err_t error;
    /* Config PWM */
    nrfx_pwm_config_t config =
    {
        .base_clock   = NRF_PWM_CLK_1MHz,
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 20,
        .load_mode    = NRF_PWM_LOAD_COMMON,
        .step_mode    = NRF_PWM_STEP_AUTO,
        .output_pins  =
        {
            PWM_GPIO_PIN,
            NRFX_PWM_PIN_NOT_USED,
            NRFX_PWM_PIN_NOT_USED,
            NRFX_PWM_PIN_NOT_USED,
        }
    };
    error = nrfx_pwm_init(&amp;amp;m_pwm0, &amp;amp;config, NULL);
    APP_ERROR_CHECK(error);

    /* Config GPIO */
    nrf_gpio_pin_clear(PWM_GPIO_PIN);
    nrf_gpio_cfg_output(PWM_GPIO_PIN);

    /* Kick off PWM */
    APP_ERROR_CHECK(nrfx_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1, NRFX_PWM_FLAG_LOOP));

    /* Loop */
    for (;;)
    {
        /* Obviously this would happen using interrupts or timers or such */
        nrf_delay_ms(1000);
        nrfx_pwm_stop(&amp;amp;m_pwm0, true);
        nrf_gpio_pin_toggle(PWM_GPIO_PIN);
        nrf_delay_ms(1000);
        APP_ERROR_CHECK(nrfx_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1, NRFX_PWM_FLAG_LOOP));
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change  a pin between GPIO and PWM</title><link>https://devzone.nordicsemi.com/thread/292778?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2021 22:36:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16a61e31-026a-412f-8284-98e8b0cab02b</guid><dc:creator>Di-sheng</dc:creator><description>&lt;p&gt;Hi SmallerPond,&lt;/p&gt;
&lt;p&gt;Thanks for your reply.&lt;/p&gt;
&lt;p&gt;I want those pins which output PWM signal&amp;nbsp;can be controlled by&amp;nbsp;GPIO for few second and then&amp;nbsp; go back to PWM agian.&lt;/p&gt;
&lt;p&gt;Right now PWM and GPIO works, I hope when GPIO control the pin which come back from PWM and PWM still keep going .&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;B.Rs,&lt;/p&gt;
&lt;p&gt;Di-sheng&lt;/p&gt;
[quote userid="74636" url="~/f/nordic-q-a/71288/how-to-change-a-pin-between-gpio-and-pwm/292774#292774"]I think you can just uninit the pwm with&amp;nbsp;nrfx_pwm_uninit and then configure it as gpio, then just init the pwm again when you need it.&amp;nbsp; No need to worry about turning off the gpio since i think the pwm driver does this automatically.[/quote]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change  a pin between GPIO and PWM</title><link>https://devzone.nordicsemi.com/thread/292774?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2021 21:28:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f03a721d-29ed-46af-a7dd-7d0dd3d8ac43</guid><dc:creator>SmallerPond</dc:creator><description>&lt;p&gt;I think you can just uninit the pwm with&amp;nbsp;nrfx_pwm_uninit and then configure it as gpio, then just init the pwm again when you need it.&amp;nbsp; No need to worry about turning off the gpio since i think the pwm driver does this automatically.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>