<?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 can I create 1.7MHz, 2.5MHz, 3MHz duty-cycle 50% by PWM in nRF52832</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40950/how-can-i-create-1-7mhz-2-5mhz-3mhz-duty-cycle-50-by-pwm-in-nrf52832</link><description>Hi, 
 
 As well know, nRF52832 can use &amp;quot;16Mhz base-clock to output PWM signal, and it is very simple to create 4Mhz, 2Mhz, 1MHz signal output, 
 But, If I want to output a 1.7Mhz, 2.5Mhz, 3Mhz signal output with 50% duty-cycle, does it possible? 
 How</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 30 Nov 2018 02:16:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40950/how-can-i-create-1-7mhz-2-5mhz-3mhz-duty-cycle-50-by-pwm-in-nrf52832" /><item><title>RE: How can I create 1.7MHz, 2.5MHz, 3MHz duty-cycle 50% by PWM in nRF52832</title><link>https://devzone.nordicsemi.com/thread/159645?ContentTypeID=1</link><pubDate>Fri, 30 Nov 2018 02:16:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79369ccc-bfa1-41b0-a3a5-b6de140c6a9e</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;Thank you for your information.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I create 1.7MHz, 2.5MHz, 3MHz duty-cycle 50% by PWM in nRF52832</title><link>https://devzone.nordicsemi.com/thread/159520?ContentTypeID=1</link><pubDate>Thu, 29 Nov 2018 10:01:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c704719-5e3e-45ab-9171-3013e4b96911</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Oh, I&amp;#39;ve made a terrible mistake. You won&amp;#39;t be able able to get a PWM frequency of 1.7MHz or 2.5MHz, from a 16MHz timer. You will only be able to have a PWM frequency in integers of MHz, ie, 1, 2, 3, 4... MHz. I&amp;#39;m sorry for the confusion.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I create 1.7MHz, 2.5MHz, 3MHz duty-cycle 50% by PWM in nRF52832</title><link>https://devzone.nordicsemi.com/thread/159287?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 15:36:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4737cc70-a341-41a1-85bd-9e9496086ef9</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please find the following source code.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static uint16_t const              m_demo1_top  = 6;
static uint16_t const              m_demo1_step = 200;

static uint8_t                     m_demo1_phase;
static nrf_pwm_values_individual_t m_demo1_seq_values;

static nrf_pwm_sequence_t const    m_demo1_seq =
{
    .values.p_individual = &amp;amp;m_demo1_seq_values,
    .length              = NRF_PWM_VALUES_LENGTH(m_demo1_seq_values),
    .repeats             = 0,
    .end_delay           = 2
};

static void demo1_handler(nrf_drv_pwm_evt_type_t event_type)
{
    if (event_type == NRF_DRV_PWM_EVT_FINISHED)
    {
	}
}

void PwmInit(void)
{
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {																// 設定 &amp;quot;連接到 PWM 的 Pin&amp;quot; 和 Pin 的初始狀態
            3 | NRF_DRV_PWM_PIN_INVERTED,								// Offset 0x00000560. Channel-0
            4 | NRF_DRV_PWM_PIN_INVERTED,								// Offset 0x00000564. Channel-1
            31 | NRF_DRV_PWM_PIN_INVERTED,								// Offset 0x00000569. Channel-2
            2 | NRF_DRV_PWM_PIN_INVERTED 								// Offset 0x0000056C. Channel-3
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_16MHz,								// Offset 0x0000050C. 這個地方設的是 PWM 暫存器的 PRESCALER
        .count_mode   = /*NRF_PWM_MODE_UP_AND_DOWN*/ NRF_PWM_MODE_UP,	// Offset 0x00000504. 計數模式 (上緣 or 上緣+下緣)
        .top_value    = m_demo1_top,									// Offset 0x00000508. 脈衝發生器計數器計數的值。 當DECODER.MODE = WaveForm時，將忽略該寄存器，並且僅使用來自RAM的值。
        .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,						// Offset 0x00000510. (bit-0/1) 1st half word (16-bit) in ch.0; 2nd in ch.1; ...; 4th in ch.3
        .step_mode    = NRF_PWM_STEP_AUTO								// Offset 0x00000510. (bit-8) 選擇用於推進活動序列的源: SEQ [n] .REFRESH用於確定加載內部比較寄存器
    };
    APP_ERROR_CHECK(nrf_drv_pwm_init(&amp;amp;m_pwm0, &amp;amp;config0, demo1_handler));

    m_demo1_seq_values.channel_0 = 3;
    m_demo1_seq_values.channel_1 = m_demo1_top/2 /*0*/;
    m_demo1_seq_values.channel_2 = m_demo1_top/2 /*0*/;
    m_demo1_seq_values.channel_3 = m_demo1_top/2 /*0*/;
    m_demo1_phase                = 0;

    (void)nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;m_demo1_seq, 1, NRF_DRV_PWM_FLAG_LOOP);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If I call &amp;quot;PwmInit()&amp;quot; function. The PWM frequency is 2.667MHz and duty is 0.2us/0.16us.&lt;/p&gt;
&lt;p&gt;How to modify PWM setting, then I can get 2.5MHz frequency and 50% duty-cycle?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you,.&lt;/p&gt;
&lt;p&gt;Chianglin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I create 1.7MHz, 2.5MHz, 3MHz duty-cycle 50% by PWM in nRF52832</title><link>https://devzone.nordicsemi.com/thread/159240?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 13:31:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f68206fa-d24a-4005-8316-761c1a0218ee</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;COUNTERTOP sets the PWM frequency, and &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/structnrf__pwm__sequence__t.html" target="_self"&gt;nrf_pwm_sequence_t&lt;/a&gt; &amp;quot;sequence&amp;quot; of duty cycle values sets the duty-cycle.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;COUNTERTOP resets the PWM counter, the compare matches in the &amp;quot;sequence&amp;quot; triggers the GPIO state change.&lt;br /&gt;&lt;br /&gt;See&amp;nbsp;&lt;a title="nrfx_pwm_simple_playback" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/group__nrfx__pwm.html?cp=4_0_0_6_9_0_13_1_19#gafbdadeeba36d9f70239f9cf08f4c9ff4"&gt;nrfx_pwm_simple_playback&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I create 1.7MHz, 2.5MHz, 3MHz duty-cycle 50% by PWM in nRF52832</title><link>https://devzone.nordicsemi.com/thread/159234?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 13:16:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e6f6451-858d-46f3-89ea-4d29b9b46c93</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/haakonsh"&gt;haakonsh&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your answer so quickly.&lt;/p&gt;
&lt;p&gt;So, it is possible to create any frequency output by PWM (Include 1.7MHz, 2.5MHz and 3MHz by 50% duty-cycle,)? And I only need to modify&amp;nbsp;&lt;a title="COUNTERTOP" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/pwm.html?cp=2_0_0_5_16_4_6#register.COUNTERTOP"&gt;COUNTERTOP&lt;/a&gt;&amp;nbsp;register?&lt;/p&gt;
&lt;p&gt;Does it true?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;
&lt;p&gt;Chianglin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I create 1.7MHz, 2.5MHz, 3MHz duty-cycle 50% by PWM in nRF52832</title><link>https://devzone.nordicsemi.com/thread/159223?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 12:44:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11f3be66-2605-48fd-b246-af7c150d5612</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;The 16MHz clock can be divided by 2^x, but this is just the base clock frequency, it&amp;#39;s the&amp;nbsp;&lt;a title="COUNTERTOP" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/pwm.html?cp=2_0_0_5_16_4_6#register.COUNTERTOP"&gt;COUNTERTOP&lt;/a&gt;&amp;nbsp;register that determines the PWM frequency and&amp;nbsp; COMPx&amp;nbsp; (Compare Match) that determines the duty-cycle.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;See&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/pwm.html?cp=2_0_0_5_16"&gt;PWM — Pulse width modulation&lt;/a&gt;,&amp;nbsp;&lt;a title="PWM" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/hardware_driver_pwm.html?cp=4_0_0_2_0_8"&gt;PWM&lt;/a&gt;&amp;nbsp;driver doc,&amp;nbsp;&amp;nbsp;&lt;a title="PWM driver" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/group__nrfx__pwm.html?cp=4_0_0_6_9_0_13_1"&gt;PWM driver&lt;/a&gt;&amp;nbsp;API, and the&amp;nbsp;&lt;a title="PWM Driver Example" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/pwm_hw_example.html?cp=4_0_0_4_5_22"&gt;PWM Driver Example&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>