<?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 driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46865/pwm-driver</link><description>Dear nordic, 
 I need a help from your side i want to create 1 hz(1000 ms time period) frequency pwm using PWM driver. i created upto 30 ms time period but i cant create time period above 30 ms or 1 hz(1000 ms) using PWM driver . 
 my code added below</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 03 May 2019 09:31:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46865/pwm-driver" /><item><title>RE: PWM driver</title><link>https://devzone.nordicsemi.com/thread/185115?ContentTypeID=1</link><pubDate>Fri, 03 May 2019 09:31:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a70a5029-9c02-431d-b941-5bf2095893d8</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Just look inside the app_pwm_channel_duty_set() functino in app_pwm.c.&lt;/p&gt;
&lt;p&gt;First, it calculates the ticks parameters, and then it tells the pwm library to set this amount of ticks using app_pwm_channel_duty_ticks_set(). You can use this function, app_pwm_channel_duty_ticks_set() directly from main.c if you want to, since app_pwm.h is already included in main.c, and this function also is defined in this file.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;First, check inside&amp;nbsp;app_pwm_init() what the timer_freq will be, which is calculated on line 883 in app_pwm.c. This corresponds to a frequency which you can find on line 194-206 in nrf_timer.h.&lt;/p&gt;
&lt;p&gt;Knowing what frequency you are running your timer on, you can calculate how many ticks you need for e.g. 100µs.&lt;/p&gt;
&lt;p&gt;If you want a period on 1 000 000µs, this will give you a frequency of 62500Hz, meaning each tick is 16µs. I don&amp;#39;t know if that is accurate enough for your application?&lt;/p&gt;
&lt;p&gt;If not, you can try to increase the bit width from NRF_TIMER_BIT_WIDTH_16 to 24. But then you have to modify the timer_freq = pwm_calculate_timer_frequency() as well, possibly some other functions as well, that are configuring the timeouts.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I recommend that you check out the example that I sent you. It uses the same peripherals, but without the libraries.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM driver</title><link>https://devzone.nordicsemi.com/thread/185090?ContentTypeID=1</link><pubDate>Fri, 03 May 2019 08:47:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65a16a71-2cca-4772-acf8-09868eb321b6</guid><dc:creator>Alan Ajit</dc:creator><description>&lt;p&gt;Thanks for replay. i tried it in PWM library it make 1000 ms time period but here my problem i want to set pulse width in(micro second range) ie. i want to create 1000 ms time period and 100 micro second pulse width(not duty cycle it is in percentage). how can i achieve this with PWM library. i need a urgent help please.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM driver</title><link>https://devzone.nordicsemi.com/thread/185089?ContentTypeID=1</link><pubDate>Fri, 03 May 2019 08:33:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:baa7e164-574f-463e-bae4-d0cb6b707162</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;With the implementation you have there, you will have a top value of 10000, and a clock frequency of 1MHz, so each period will be 100Hz.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I suppose you have tried, since you measure about 30ms. In order to get one second, you would have to have a pwm_frequency = base_clock[Hz]/top_value = 1Hz. So lowering the base clock to the lowest possible frequency, which is 125 000Hz you would need a top_value of 125 000. Since top_value is an uint16_t the max value you can have is 0xFFFF = dec 65 535. However, the MSB (most significant bit) decides whether it is an active low or active high pulse, so actually, you have a max top_value of 0x7FFF = dec 32 767.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Hence, it is not possible to have a PWM frequency of 1s using the pwm driver. There are some other options, though:&lt;/p&gt;
&lt;p&gt;One option is to use the pwm_library. Note that this doesn&amp;#39;t use the PWM driver, but rather the TIMER peripheral and the gpiote driver connected together by PPI.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you take the pwm_library example, and only change the line:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, BSP_LED_0, BSP_LED_1);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(1000000L, BSP_LED_0, BSP_LED_1);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in main.c, it will set the frequency to 1 000 000µs = 1s.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The other option, which is more or less the same, is to use the PPI directly. This is a bit more down to metal solution, but it also gives more room for modifications. You can e.g. change the clock frequency, if you need even longer PWM periods. If this is something you would like to look at, check the project that I attached in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/40048/timer-gpiote-ppi-problem" rel="noopener noreferrer" target="_blank"&gt;this ticket&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>