<?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>Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14096/explanation-of-pwm-example-code-please</link><description>Hi,
I need to configure pwm with 14uSec off time and 46uSec on time. I had a look at the pwm example in the install directory and also : developer.nordicsemi.com/.../a00039.html .
But it is bit confusing, in the sense, if I need to set a duty cycle</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 Jun 2016 19:28:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14096/explanation-of-pwm-example-code-please" /><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53885?ContentTypeID=1</link><pubDate>Thu, 02 Jun 2016 19:28:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cdbdd6e6-a377-456a-875f-0148040d1843</guid><dc:creator>nordicdev</dc:creator><description>&lt;p&gt;Answers are in the comments May 26 to June 1 2016&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53883?ContentTypeID=1</link><pubDate>Thu, 02 Jun 2016 19:27:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:117ceed5-381f-48cf-8d43-547f00bc837b</guid><dc:creator>nordicdev</dc:creator><description>&lt;p&gt;Hi Ole, thanks for your reply. The discussion here did answer the question asked. So I am going to mark this as answered. Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53882?ContentTypeID=1</link><pubDate>Wed, 01 Jun 2016 11:26:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7397f04a-7135-455e-a0bd-d166adfd20db</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;You have posted this question here: &lt;a href="https://devzone.nordicsemi.com/question/81849/how-to-control-the-number-of-pulses-using-app_pwm-library/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;
So I will not answer it here other than that it is not possible with the API in the PWM library.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53881?ContentTypeID=1</link><pubDate>Wed, 01 Jun 2016 09:39:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:599f56e4-5edd-40b2-b7ee-136401df8099</guid><dc:creator>nordicdev</dc:creator><description>&lt;p&gt;Hi Ole, Thanks for your reply. I am using app_pwm.c (PWM library). I am able to get PWM waves and I am able to change the duty cyle. But I am not able to configure the number of PWM cycles. I need to output N * PWM cycles. I will get the value of N from BLE app mobile phone connection. How to output the desired number of pwm cycles? thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53884?ContentTypeID=1</link><pubDate>Wed, 01 Jun 2016 07:59:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfff3cbe-34a5-44b1-92d0-43db80cbcb44</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;ol&gt;
&lt;li&gt;Yes, I mean app_pwm.c and app_pwm.h.&lt;/li&gt;
&lt;li&gt;You can have on/off time as low as 10usec. The PWM library uses the TIMER peripheral just as your code.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The PWM library can be used with or without the SoftDevice, no problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53880?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 23:07:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad338adf-5f04-45af-aebc-c64fcc0b7d4d</guid><dc:creator>nordicdev</dc:creator><description>&lt;p&gt;Hi Ole, thanks for your reply.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;When you meant PWM library, did you mean app_pwm.c and app_pwm.h (which has app_pwm_channel_init etc in it)?&lt;/li&gt;
&lt;li&gt;I dont have any problems using the PWM library. But, I want on/off time to go as low as 10usec. Is it possible with app_pwm.c library? I thought app_pwm.c uses softdevice. Since softdevice uses RTC, the lowest RTC can go is 30.5usec. But I need PWM pulses as low as 10usec. Also I need to use BLE in the same code base with PWM. Do you think I can still go for PWM library(app_pwm.c)? If not, what is your recommendation? Thanks.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53879?ContentTypeID=1</link><pubDate>Tue, 31 May 2016 13:47:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca96439a-6dbe-4a73-8549-b7422107446c</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;As the code is now BLE interrupts can invert the PWM if the TIMER_IRQHandler is interrupted an a toggle is missed (for example if a BLE interrupt lasting longer than MAX_SAMPLE_LEVELS happen just before &lt;code&gt;if(cc0_turn)&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The PWM library does not have this problem, but with this library you can only set the duty cycle of the PWM and not the frequency. I would use this library if you can, if not you will have to find out a clever way to update the PWM without risking invertions or dissortions in the signal. One way is to stop the timer, update the CC values and then start the timer again, this will avoid invertion, but will create a long low or high pulse on the line.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53878?ContentTypeID=1</link><pubDate>Mon, 30 May 2016 23:06:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ed54b30-cfa0-4ded-878f-d51b3af6a8a1</guid><dc:creator>nordicdev</dc:creator><description>&lt;p&gt;I was wondering what would happen if an interrupt(from timer) for the PWM pulse generation is overridden by the BLE interrupt. This is because, timer has low priority interrupt than BLE. How to handle this situation? Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53877?ContentTypeID=1</link><pubDate>Mon, 30 May 2016 23:04:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:374b11e0-5478-4cf9-b523-41b4547d0a0c</guid><dc:creator>nordicdev</dc:creator><description>&lt;p&gt;Hi Ole, Thanks for your reply and sorry for not being clear. I needed to control the PWM pulse duty cycle via BLE. Initially the duty cycle would be 75% (42usec on time, 14usec off time), after getting an input from the BLE bonded phone connection, the duty cycle would reduce(example: 50%). After getting a second input from BLE bonded phone connection, the period of the PWM pulse would reduce (for example, period of PWM pulse would reduce from 56usec to 24usec with on time 10usec and off time 14usec), etc.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53876?ContentTypeID=1</link><pubDate>Mon, 30 May 2016 14:17:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9469c7b7-32fc-42a8-a3a3-5da2a03a4afa</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;I am a bit confused here, what exactly did you need to control? You say that the PWM should have pulses of 42 usec (or 34usec in an earlier comment) and off time of 14 usec and at the same time you say that you should be able to control the duty cycle.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53875?ContentTypeID=1</link><pubDate>Sun, 29 May 2016 23:10:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4778781-3dac-42dd-ac26-7046d8c0d481</guid><dc:creator>nordicdev</dc:creator><description>&lt;p&gt;Thanks Ole. It works. But, I need softdevice + PWM to work. This is because I need BLE and control the duty cycle of the PWM pulses from the bonded BLE mode from the mobile phone App. As I need PWM pulses of on time 42usec and off time 14usec, this would be disturbed if softdevice is used, because softdevice has higher IRQ priority than timer. How to handle this situation? Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53874?ContentTypeID=1</link><pubDate>Fri, 27 May 2016 09:18:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d632ea53-81f4-46e2-8508-0e34bf17564c</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;Again, if you are using SoftDevice I will strongly not recommend to use this code to generate PWM.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To solve your problem you can add a counter in TIMER2_IRQHandler(). Increment the counter every time the handler is called. If the counter reach 3, then turn off the PPI channels and clear the counter. After 10ms turn on the PPI channels again and clear the timer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53873?ContentTypeID=1</link><pubDate>Fri, 27 May 2016 00:45:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aea04969-d907-490e-85a9-3be93bfbb1ae</guid><dc:creator>nordicdev</dc:creator><description>&lt;p&gt;I have got thist ot work by just copy pasting the code that I have sent you into another working project. Now, how do I set the number of cycles for the PWM? I need just 3 cycles of PWM(on time: 34usec, off time:14usec) after those 3 cycles, I need 10msec delay, then 3 cycles of PWM and the sequence continues. I tried using a different timer to keep track of the number of cycles, but does not work very well. Ideas please..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Explanation of pwm example code please</title><link>https://devzone.nordicsemi.com/thread/53872?ContentTypeID=1</link><pubDate>Thu, 26 May 2016 14:45:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1a152ab-3c39-4623-aa75-67b1e8d258e7</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;You are using code from SDK 8, which is old (the newest SDK is version 11). Now there is a &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/lib_pwm.html?cp=5_0_0_3_20"&gt;PWM library&lt;/a&gt; which is more documented and does not have problems like possibility of inverting the output signal as the earlier SDK examples had. Take a look at the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/pwm_example.html?cp=5_0_0_4_5_16"&gt;PWM example&lt;/a&gt; in SDK 11. You &lt;strong&gt;should not&lt;/strong&gt; use PWM library/example code prior to SDK 10.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>