<?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 Duty Cycle Does Not Change</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/63626/pwm-duty-cycle-does-not-change</link><description>Hello, 
 I&amp;#39;m working on nRF52811, SDK16.0, Softdevice 7.0.1. 
 Using the pwm_driver example in the SDK, I&amp;#39;m trying to run a simple PWM for an RGB LED. Following is my simplified code. I can see the PWM at output but changing duty cycle (by seq_values</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 13 Jul 2020 14:53:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/63626/pwm-duty-cycle-does-not-change" /><item><title>RE: PWM Duty Cycle Does Not Change</title><link>https://devzone.nordicsemi.com/thread/259732?ContentTypeID=1</link><pubDate>Mon, 13 Jul 2020 14:53:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afe10f0a-6ecf-41d4-92aa-946fc84c6b65</guid><dc:creator>Aftab</dc:creator><description>&lt;p&gt;Finally this code worked:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_drv_pwm.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
//#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;


#define OUTPUT_PIN_1 30
#define OUTPUT_PIN_2 28
#define OUTPUT_PIN_3 25



uint8_t RGB_val_R=50;
uint8_t RGB_val_G=50;
uint8_t RGB_val_B=1;


static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);

// Declare variables holding PWM sequence values. In this example only one channel is used 
nrf_pwm_values_individual_t seq_values[] = {0, 0, 0, 0};
nrf_pwm_sequence_t const seq =
{
    .values.p_individual = seq_values,
    .length          = NRF_PWM_VALUES_LENGTH(seq_values),
    .repeats         = 0,
    .end_delay       = 0
};


static void pwm_init(void)
{
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            OUTPUT_PIN_1 | NRF_DRV_PWM_PIN_INVERTED,               // channel 0
            //NRF_DRV_PWM_PIN_NOT_USED,
            OUTPUT_PIN_2 | NRF_DRV_PWM_PIN_INVERTED,               // channel 1
            //NRF_DRV_PWM_PIN_NOT_USED,
            OUTPUT_PIN_3 | NRF_DRV_PWM_PIN_INVERTED,               // channel 2
            NRF_DRV_PWM_PIN_NOT_USED,                              // channel 3
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_1MHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 100,
        .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    // Init PWM without error handler
    APP_ERROR_CHECK(nrf_drv_pwm_init(&amp;amp;m_pwm0, &amp;amp;config0, NULL));
    
}


void rgb_outputs_init(void)
{
    // Start clock for accurate frequencies
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1; 
    // Wait for clock to start
    while(NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);
    
    pwm_init();
    rgb_outputs_set(255, 0, 0);
    NRF_LOG_INFO(&amp;quot;PWM Initialized...&amp;quot;);
}

void rgb_outputs_set(uint16_t R, uint16_t G, uint16_t B){

    seq_values-&amp;gt;channel_0 = 100 - (R*100)/255;
    seq_values-&amp;gt;channel_1 = 100 - (G*100)/255;
    seq_values-&amp;gt;channel_2 = 100 - (B*100)/255;
    nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1, NRF_DRV_PWM_FLAG_LOOP);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Duty Cycle Does Not Change</title><link>https://devzone.nordicsemi.com/thread/259689?ContentTypeID=1</link><pubDate>Mon, 13 Jul 2020 12:46:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:875ecb90-d4fa-48b1-b99d-f207ad5efb4b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Does the unmodified pwm_driver example work on your board? Is there any way for me to reproduce what you are seeing? Do you have an nRF52832, nRF52833, or nRF52840 DK to test on? Have you tried to debug to check the return value for&amp;nbsp;nrf_drv_pwm_simple_playback()? What does it return?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What happens if you try to run e.g. demo5() from the pwm_driver example. Does it behave properly? You can reduce the number of channels used by one if you only want to test with only 3.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;br /&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Duty Cycle Does Not Change</title><link>https://devzone.nordicsemi.com/thread/259607?ContentTypeID=1</link><pubDate>Mon, 13 Jul 2020 06:53:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54e41cce-ab93-4032-a006-db73b27e536d</guid><dc:creator>Aftab</dc:creator><description>&lt;p&gt;Hello, thanks for reply.&lt;/p&gt;
&lt;p&gt;If I set seq_values-&amp;gt;channel_X = 0, it completely turns off the LED which is expected.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I set seq_values-&amp;gt;channel_X = 100, it turns on the LED to fullest which is also expected.&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But any value in between does not effect the intensity of LED. I have tried several values from 10, 20, ...90. Every time the intensity is maximum except for 0.&lt;/p&gt;
&lt;p&gt;I tried both commenting and un-commentating&amp;nbsp;&lt;span&gt;NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1, with same result.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Duty Cycle Does Not Change</title><link>https://devzone.nordicsemi.com/thread/259518?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2020 16:43:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30d7ee52-23ff-4dcc-ab13-a0a51e5dd8c0</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Just so I understand you correctly, the change you are expecting is between the sec_values 0 and 50?&lt;/p&gt;
&lt;p&gt;If I read your code correctly, you set one channel to 0, the second channel to 50 (50%) and the last one to 0, and then you start the pwm, so I would expect this to not change any cycles.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Channel 0 will be continuously off (or on, depending on the polarity), channel 1 will be at 50%, and channel 2 will be the same as channel 0.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Are you saying that channel 1 is not at 50%?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I see that you commented out NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1. Do you start the HFCLK from somewhere else, or may the problem be that the clock is not running? Because if so, the PWM will not work.&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>