<?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 control using accelerometer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/28485/pwm-control-using-accelerometer</link><description>hello friends, 
 i need to control 4 LED brightness using PWM according to accelerometer values. how can i do that 
 i am using SDK11, nrf52832, KEIL MDK5 
 i going to attach main file what i am doing wrong please check and let me know main.txt 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 20 Dec 2017 12:08:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/28485/pwm-control-using-accelerometer" /><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112678?ContentTypeID=1</link><pubDate>Wed, 20 Dec 2017 12:08:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4826f7ba-9062-479e-ba81-4dfc37e91360</guid><dc:creator>strengthstrong</dc:creator><description>&lt;p&gt;nrf_drv_pwm_sequence_values_update(&amp;amp;m_pwm0,1,new_pwm_values);
seq_id  is 1 ,not 0?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112674?ContentTypeID=1</link><pubDate>Thu, 16 Nov 2017 04:12:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a193af0-f102-4750-a853-57726e48b40d</guid><dc:creator>Rahul</dc:creator><description>&lt;p&gt;thank you sir using this i can improve my code&lt;/p&gt;
&lt;p&gt;thank you so much nordic support team&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112673?ContentTypeID=1</link><pubDate>Wed, 15 Nov 2017 13:58:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94e4e779-73c6-49af-9833-fa212778f619</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;So you can try something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;						if(accel_values.x &amp;gt; 0000 &amp;amp;&amp;amp; accel_values.x &amp;lt; 8000)
					{  // LED 1 blinking, other led off


seq_values[0].channel_0 = 50;
seq_values[0].channel_1 = 0;
seq_values[0].channel_2 = 0;
seq_values[0].channel_3 = 0;

nrf_pwm_values_t new_pwm_values; 

new_pwm_values.p_individual = seq_values;

nrf_drv_pwm_sequence_values_update(&amp;amp;m_pwm0,1,new_pwm_values);


					}
					
					
					if(accel_values.x &amp;gt; 8000 &amp;amp;&amp;amp; accel_values.x &amp;lt; 10000)
					{ LED 2 blinking, other led off

seq_values[0].channel_0 = 0;
seq_values[0].channel_1 = 50;
seq_values[0].channel_2 = 0;
seq_values[0].channel_3 = 0;

nrf_pwm_values_t new_pwm_values; 

new_pwm_values.p_individual = seq_values;

nrf_drv_pwm_sequence_values_update(&amp;amp;m_pwm0,1,new_pwm_values);


					}
					
												
						if(accel_values.x &amp;gt; 10000 &amp;amp;&amp;amp; accel_values.x &amp;lt; 12000)
					{ LED 3 blinking, other led off
						
								
								
seq_values[0].channel_0 = 0;
seq_values[0].channel_1 = 0;
seq_values[0].channel_2 = 50;
seq_values[0].channel_3 = 0;

nrf_pwm_values_t new_pwm_values; 

new_pwm_values.p_individual = seq_values;

nrf_drv_pwm_sequence_values_update(&amp;amp;m_pwm0,1,new_pwm_values);
							
					}
					
					
						if(accel_values.x &amp;gt; 12000 &amp;amp;&amp;amp; accel_values.x &amp;lt; 14000)
					{ LED 4 blinking, other led off
							

seq_values[0].channel_0 = 0;
seq_values[0].channel_1 = 0;
seq_values[0].channel_2 = 0;
seq_values[0].channel_3 = 50;

nrf_pwm_values_t new_pwm_values; 

new_pwm_values.p_individual = seq_values;

nrf_drv_pwm_sequence_values_update(&amp;amp;m_pwm0,1,new_pwm_values);


					}
					
					
						if(accel_values.x &amp;gt; 14000 &amp;amp;&amp;amp; accel_values.x &amp;lt; 16000)
					{ //ALL LED blinking

seq_values[0].channel_0 = 50;
seq_values[0].channel_1 = 50;
seq_values[0].channel_2 = 50;
seq_values[0].channel_3 = 50;

nrf_pwm_values_t new_pwm_values; 

new_pwm_values.p_individual = seq_values;

nrf_drv_pwm_sequence_values_update(&amp;amp;m_pwm0,1,new_pwm_values);


							
					}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112677?ContentTypeID=1</link><pubDate>Wed, 15 Nov 2017 13:12:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34cc1d36-8598-4456-9c2c-14201143ffa7</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;No examples uses this, but its very easy to use. Declare the &lt;code&gt;static nrf_pwm_values_individual_t seq_values_new[]&lt;/code&gt;  at top of main.c, after the &lt;em&gt;includes&lt;/em&gt; (You are already doing this in the code you uploaded) .&lt;/p&gt;
&lt;p&gt;Then you can use it like this to update the PWM duty cycle for the channel you want.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;seq_values[0].channel_0 = my_new_value; // New value for channel 0

nrf_pwm_values_t new_pwm_values; 

new_pwm_values.p_individual = seq_values;

nrf_drv_pwm_sequence_values_update(&amp;amp;m_pwm0,1,new_pwm_values);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112672?ContentTypeID=1</link><pubDate>Tue, 14 Nov 2017 05:22:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1743be1-58e5-45ff-979b-749e34558632</guid><dc:creator>Rahul</dc:creator><description>&lt;p&gt;is there any example for this ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112671?ContentTypeID=1</link><pubDate>Mon, 13 Nov 2017 16:17:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47331f5d-0c09-480b-b584-57629d5667fc</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;For the PWM driver, you can use the function &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.0.0/group__nrf__drv__pwm.html?cp=4_0_1_6_8_15_1_18#ga76346c8b3ceb9b7cb7b7a0b15c21dd21"&gt;nrf_drv_pwm_sequence_values_update()&lt;/a&gt; with a new pointer to the new duty cycle values(&lt;code&gt;nrf_pwm_values_individual_t&lt;/code&gt;) in order to change the duty cycle.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112676?ContentTypeID=1</link><pubDate>Mon, 13 Nov 2017 12:23:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5e734bd-73aa-422b-aae5-bed6d62c7f7f</guid><dc:creator>Rahul</dc:creator><description>&lt;p&gt;yes because i am not able to use remaining 3 channels in different region
can you explain how can i use remaining 3 channels in different region&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112675?ContentTypeID=1</link><pubDate>Mon, 13 Nov 2017 12:00:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb214325-1692-4cc0-ab8e-f9301bd7c968</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;If you take a look at the pwm_update_duty_cycle() function, you can see that this function is only changing the duty cycle of channel 0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112670?ContentTypeID=1</link><pubDate>Sat, 11 Nov 2017 04:34:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba2703d1-e79b-44ce-9a24-3b6181e18e49</guid><dc:creator>Rahul</dc:creator><description>&lt;p&gt;hello sir, what i want to do is for this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if(accel_values.x &amp;gt; 8000 &amp;amp;&amp;amp; accel_values.x &amp;lt; 10000)
                {
                    for(int i = 0; i &amp;lt;= 100; i++)
                    {
                        pwm_update_duty_cycle(25);
                    }
                }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;one led should glow&lt;/p&gt;
&lt;p&gt;and for other loop another led will glow&lt;/p&gt;
&lt;p&gt;but for every loop only LED 1 is glowing
how can i change this&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM control using accelerometer</title><link>https://devzone.nordicsemi.com/thread/112669?ContentTypeID=1</link><pubDate>Fri, 10 Nov 2017 15:01:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66bd4966-0187-45a9-9caa-9361e1767210</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;What kind of issues do you have ?&lt;/p&gt;
&lt;p&gt;I see that you are setting the duty cycle to the same value 100 times in a row. That should not be necessary, E.g:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;			    if(accel_values.x &amp;gt; 8000 &amp;amp;&amp;amp; accel_values.x &amp;lt; 10000)
				{
					for(int i = 0; i &amp;lt;= 100; i++)
					{
						pwm_update_duty_cycle(25);
					}
				}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So remove these &lt;code&gt;for(int i = 0; i &amp;lt;= 100; i++)&lt;/code&gt; loops, .i.e to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;				if(accel_values.x &amp;gt; 8000 &amp;amp;&amp;amp; accel_values.x &amp;lt; 10000)
				{
							
							pwm_update_duty_cycle(25);
				}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>