<?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>PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14198/pwm-with-a-piezo-buzzer-how-can-i-change-the-pwm-frequency</link><description>I use the nrf51822qfaa,s110 v8.00,SDK V10.0.
I use PWM module with a piezo buzzer.
Now I need change the buzzer frequency,
How can I change the PWM frequency? 
 for example: 
 /* 2-channel PWM, 200Hz, output on DK LED pins. */
app_pwm_config_t pwm1_cfg</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 31 May 2016 12:11:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14198/pwm-with-a-piezo-buzzer-how-can-i-change-the-pwm-frequency" /><item><title>RE: PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/thread/54255?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 12:11:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83bc8eaf-f386-4dba-ba7c-068233b3a2a7</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;Looks good, maybe you should also change &lt;code&gt;uin16_t freq&lt;/code&gt; to &lt;code&gt;uint16_t period_us&lt;/code&gt; for better readability ;)&lt;/p&gt;
&lt;p&gt;You actually don&amp;#39;t have to call &lt;code&gt;app_pwm_disable()&lt;/code&gt; either as this is done in &lt;code&gt;app_pwm_uninit()&lt;/code&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/thread/54254?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 12:05:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:927c78c2-1a8a-421f-a0ea-75d0ddccaf5a</guid><dc:creator>Mahesh Venkitachalam</dc:creator><description>&lt;p&gt;&lt;code&gt;app_pwm_disenable()&lt;/code&gt; should be &lt;code&gt;app_pwm_disable()&lt;/code&gt; ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/thread/54250?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 12:01:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81d95774-91dd-4190-89f2-926a35cbb879</guid><dc:creator>Mahesh Venkitachalam</dc:creator><description>&lt;p&gt;Here&amp;#39;s a previous discussion on this topic: &lt;a href="https://devzone.nordicsemi.com/question/59711/changing-pwm-frequency-period/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/thread/54253?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 11:13:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8629b6ea-b5a2-4a09-ae67-6883d5dd3494</guid><dc:creator>Mike</dc:creator><description>&lt;p&gt;Is this OK?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; /*
 init, Once executed
 */

 void pwm_init(void)  
 {
    /* 1-channel PWM, 200Hz, output on DK LED pins. */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, BSP_LED_0);
    
    /* Switch the polarity of the second channel. */
    pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;
    
    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&amp;amp;PWM1);
  }
  

  
 /*
 pwm_change_frequency,Can be executed multiple times
 */
   void pwm_change_frequency(uint16_t freq)  
 {
 
  app_pwm_disenable(&amp;amp;PWM1);
  app_pwm_uninit(&amp;amp;PWM1);  
     /* 1-channel PWM, 200Hz, output on DK LED pins. */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(freq, BSP_LED_0);
    
    /* Switch the polarity of the second channel. */
    pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;
    
    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&amp;amp;PWM1);
    
    }
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/thread/54252?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 11:06:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63e55ff4-1bdd-4d11-adf9-c61b478d0d2a</guid><dc:creator>Mike</dc:creator><description>&lt;p&gt;please offer a detailed example that can change the PWM frenuency.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/thread/54251?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 10:47:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75b697b5-d328-42dc-a275-9a309b068a54</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;You cannot change the PWM frequency without un-initializing and then initialize the PWM instance again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/thread/54249?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 09:13:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86c7dba9-f4f2-4b91-93f7-426d19bf1042</guid><dc:creator>Mike</dc:creator><description>&lt;p&gt;I need change the PWM is from 1KHz, to ,1.5KHz,then 2.0KHz,then 2.7KHz.
I can not reset the NRF51822 CHIP.
How can i realtime change the PWM frequency at the 51822 is run?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM with a piezo buzzer,How can I change the PWM frequency?</title><link>https://devzone.nordicsemi.com/thread/54248?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 09:06:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:025fb709-5948-43ce-91de-875882fed2f0</guid><dc:creator>Mahesh Venkitachalam</dc:creator><description>&lt;p&gt;The first parameter of &lt;code&gt;APP_PWM_DEFAULT_CONFIG_2CH&lt;/code&gt; is the PWM period in microseconds.&lt;/p&gt;
&lt;p&gt;So in the above code, &lt;code&gt;5000 us =&amp;gt; 1000000/5000 Hz == 200 Hz&lt;/code&gt;. So to set the buzzer frequency to &lt;code&gt;f&lt;/code&gt;, set the value as &lt;code&gt;1000000/f&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Also, if you just need PWM on one pin, you can use &lt;code&gt;APP_PWM_DEFAULT_CONFIG_1CH&lt;/code&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>