<?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>Why am I having problems driving an RGB LED with PWM from NRF52??!</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19013/why-am-i-having-problems-driving-an-rgb-led-with-pwm-from-nrf52</link><description>Hello Nordic Community. 
 I&amp;#39;m having issues trying to control a simple RGB LED circuit with the NRF52. I have set up 2 timers and PWM instances Red and Green on PWM1 and Blue on PWM2 but it&amp;#39;s just not working. What am I doing wrong?? Here is my code</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 26 Apr 2017 09:32:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19013/why-am-i-having-problems-driving-an-rgb-led-with-pwm-from-nrf52" /><item><title>RE: Why am I having problems driving an RGB LED with PWM from NRF52??!</title><link>https://devzone.nordicsemi.com/thread/73506?ContentTypeID=1</link><pubDate>Wed, 26 Apr 2017 09:32:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0702832a-2dfe-4c2b-9b64-de00e6fa31a7</guid><dc:creator>saiteja</dc:creator><description>&lt;p&gt;hi, i am running your application, if i give duty value in a function like update_pwm(0,0,0) it is still showing tri color. and also i am unable to uninit and unable to stop glowing LED once i glow LED.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why am I having problems driving an RGB LED with PWM from NRF52??!</title><link>https://devzone.nordicsemi.com/thread/73505?ContentTypeID=1</link><pubDate>Fri, 20 Jan 2017 00:52:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e20414c1-e88c-4988-94aa-782833efeda7</guid><dc:creator>benjamin_xo</dc:creator><description>&lt;p&gt;Thanks Ole and Awneil for your feedback. I used the PWM Driver instead as you suggested Ole and it worked perfectly. Here is my code which plays a test animation on 3 LEDS.&lt;/p&gt;
&lt;pre&gt;&lt;code&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;app_timer.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#define NRF_LOG_MODULE_NAME &amp;quot;APP&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;

#include &amp;quot;nrf_delay.h&amp;quot;

#define APP_TIMER_PRESCALER     0
#define APP_TIMER_OP_QUEUE_SIZE 2

int gLEDR = 12;
int gLEDG = 14;
int gLEDB = 15;

static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);
// static nrf_drv_pwm_t m_pwm1 = NRF_DRV_PWM_INSTANCE(1);
//static nrf_drv_pwm_t m_pwm2 = NRF_DRV_PWM_INSTANCE(2);

static uint16_t const m_top  = 10000;


//static nrf_pwm_values_individual_t  /*const*/ seq_values;
static nrf_pwm_values_individual_t  /*const*/ seq_values;
static nrf_pwm_sequence_t const seq =
    {
        .values.p_individual = &amp;amp;seq_values,
        .length              = NRF_PWM_VALUES_LENGTH(seq_values),
        .repeats             = 0,
        .end_delay           = 0
    };


static void pwm_init(void)
{
    uint32_t err_code;
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            gLEDR,// channel 0
            gLEDG, // channel 1
            gLEDB, // channel 2
            NRF_DRV_PWM_PIN_NOT_USED  // channel 3
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_4MHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = m_top,
        .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    err_code = nrf_drv_pwm_init(&amp;amp;m_pwm0, &amp;amp;config0, NULL);
    APP_ERROR_CHECK(err_code);
    // m_used |= USED_PWM(0);

        // This array cannot be allocated on stack (hence &amp;quot;static&amp;quot;) and it must
    // be in RAM (hence no &amp;quot;const&amp;quot;, though its content is not changed).
}

void update_pwm(int16_t dutyR, int16_t dutyG, int16_t dutyB)
{
    
    seq_values.channel_0 = m_top-dutyR;
    seq_values.channel_1 = m_top-dutyG;
    seq_values.channel_2 = m_top-dutyB;
    

    //seq_values = duty_cycle;

    //nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;m_seq, 1, 0);
    //nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1, NRF_DRV_PWM_FLAG_LOOP);
    nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1,  NRF_DRV_PWM_FLAG_LOOP);
}

int main(void)
{
  
  pwm_init();

    while(1){

        for (int i=0; i&amp;lt;100; i++){
            update_pwm(i*100,0,0);
            nrf_delay_ms(1);
        }

        for (int i=0; i&amp;lt;100; i++){
            update_pwm(10000,i*100,0);
            nrf_delay_ms(1);
        }

        for (int i=0; i&amp;lt;100; i++){
            update_pwm(10000,10000,i*100);
            nrf_delay_ms(1);
        }

        for (int i=100; i&amp;gt;0; i--){
            update_pwm(i*100,10000,10000);
            nrf_delay_ms(1);
        }

        for (int i=100; i&amp;gt;0; i--){
            update_pwm(0,i*100,10000);
            nrf_delay_ms(1);
        }

        for (int i=100; i&amp;gt;0; i--){
            update_pwm(0,0,i*100);
            nrf_delay_ms(1);
        }

        update_pwm(0,0,0);
        nrf_delay_ms(200);

        
   
    }


    
}
/**/
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why am I having problems driving an RGB LED with PWM from NRF52??!</title><link>https://devzone.nordicsemi.com/thread/73504?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2017 12:40:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62fa4705-a559-4341-bd20-5708c88a26c6</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;Since you are using nRF52 you should consider using the PWM driver, nrf_drv_pwm instead. This uses the PWM peripheral on the chip. Using the PWM library, app_pwm, on nRF52 you are wasting resources like timers and ppi and gpiote channels. Here is a snippet of code that sets the pwm driver to one duty cycle: &lt;a href="https://devzone.nordicsemi.com/question/91569/how-to-modify-the-pwm-value-with-easydma-for-nrf52/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you want to find out what is the problem with the code you are running now with app_pwm, you should go into debug mode and check that all the error codes are NRF_SUCCESS.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why am I having problems driving an RGB LED with PWM from NRF52??!</title><link>https://devzone.nordicsemi.com/thread/73503?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2017 10:24:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:428be6a9-0dd4-4871-875a-965fc5dbdc9e</guid><dc:creator>awneil</dc:creator><description>&lt;blockquote&gt;
&lt;p&gt;it&amp;#39;s just not working&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Tells us nothing.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;What, exactly, were you expecting to happen?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What, exactly, is actually happening?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What testing/debugging have &lt;strong&gt;&lt;em&gt;you&lt;/em&gt;&lt;/strong&gt;  done to explain the difference?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://www.catb.org/~esr/faqs/smart-questions.html#code"&gt;www.catb.org/.../smart-questions.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>