<?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 dimming led rgb with trouble on third and thourth channel.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19620/pwm-dimming-led-rgb-with-trouble-on-third-and-thourth-channel</link><description>i am having trouble with pwm module 2. only two of the channels are working but not the third nor the fourth.
i tried pwm module 1 but im having the same problem there. i cant tell what im missing :/ 
 the third channel only works if i declare it on</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 Jun 2017 12:25:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19620/pwm-dimming-led-rgb-with-trouble-on-third-and-thourth-channel" /><item><title>RE: pwm dimming led rgb with trouble on third and thourth channel.</title><link>https://devzone.nordicsemi.com/thread/76368?ContentTypeID=1</link><pubDate>Tue, 13 Jun 2017 12:25:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8387ece9-0d6d-403c-a866-209f970829ec</guid><dc:creator>luke</dc:creator><description>&lt;p&gt;i kept working on it. and after a while with no progress i just moved the function down the main(void)/changed its location within the main(void) and it worked for some reason.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pwm dimming led rgb with trouble on third and thourth channel.</title><link>https://devzone.nordicsemi.com/thread/76367?ContentTypeID=1</link><pubDate>Thu, 16 Feb 2017 12:00:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52c4dc2a-a447-4437-86f9-907dae7e2c77</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;Sorry, I gave you code that don&amp;#39;t work. It will not work since dutyCycleCh1, 2 and 3 is not compile time constants. You cannot set the value of a static or global variable to a non compile constant (a variable), &lt;code&gt;static uint16_t pwm_seq[4] = ...&lt;/code&gt; will only be run once at startup, not when the function is called. This is correct code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static uint16_t pwm_seq[4] = {0x8000, 0x8000, 0x8000, 0}; //initialize to 0 duty cycle

uint16_t dutyCycleCh1 = (dutyCycleRed * rgbCounterTop)/100;  
uint16_t dutyCycleCh2 = (dutyCycleGreen * rgbCounterTop)/100; 
uint16_t dutyCycleCh3 = (dutyCycleBlue * rgbCounterTop)/100;

pwm_seq[0] = dutyCycleCh1  | 0x8000;
pwm_seq[1] = dutyCycleCh2  | 0x8000;
pwm_seq[2] = dutyCycleCh3  | 0x8000;
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pwm dimming led rgb with trouble on third and thourth channel.</title><link>https://devzone.nordicsemi.com/thread/76366?ContentTypeID=1</link><pubDate>Thu, 16 Feb 2017 11:02:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9e9bc2d-fddf-465e-9780-fb0948014104</guid><dc:creator>luke</dc:creator><description>&lt;p&gt;i made the rgb pwm to work on module 0 without actually the static declaration. altho ur making sense, i actually followed nrf52832 v1.2 datasheet with example code without the static.
i tried putting the static declaration and got an error that says &amp;quot;initializer element is not a compile-time constant&amp;quot; and thats bcz the value of pwm_seq_rgb is not a constant (dutyCycleCh1 is a variable).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pwm dimming led rgb with trouble on third and thourth channel.</title><link>https://devzone.nordicsemi.com/thread/76365?ContentTypeID=1</link><pubDate>Mon, 13 Feb 2017 10:02:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c39be1e-59d3-4409-959e-73508b4b099f</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;A good start will be do declare pwm_seq as static:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static uint16_t pwm_seq[4] = {dutyCycleCh1  | 0x8000, dutyCycleCh2  | 0x8000, dutyCycleCh3  | 0x8000, 0};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you don&amp;#39;t do this, pwm_seq will be placed in the stack and NRF_PWM2-&amp;gt;SEQ[0].PTR will point to a place in stack. After the function ends pwm_seq will not exist anymore, or more specific the place in the stack where it was may be overwritten by another function.&lt;/p&gt;
&lt;p&gt;The static keyword will place the variable some place else in RAM and it will exist throughout the lifetime of the program. See &lt;a href="http://stackoverflow.com/questions/5033627/static-variable-inside-of-a-function-in-c"&gt;here&lt;/a&gt; for more info, or read about static and automatic variables in C.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>