<?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>A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74866/a-simple-pwm-led-approach-for-the-thingy-91</link><description>I&amp;#39;m trying to drive the RGB LED light on the Thingy:91. So far, I&amp;#39;ve not been successful. I was hoping that by listing the steps I perform I might be able to get some advice. This is the first time that I&amp;#39;ve dealt with PWM. Here are the steps I&amp;#39;m presently</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 14 May 2021 07:07:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74866/a-simple-pwm-led-approach-for-the-thingy-91" /><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309702?ContentTypeID=1</link><pubDate>Fri, 14 May 2021 07:07:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84339e72-b1c5-4de3-80d9-ee24aa2b9896</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p&gt;Thanks a lot for the feedback, Christopher! I am pleased to hear that your application works now :-)&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;p&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309645?ContentTypeID=1</link><pubDate>Thu, 13 May 2021 07:12:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5feee352-f187-4a1f-8d32-0035f8ecc1fe</guid><dc:creator>Christopher Hunt</dc:creator><description>&lt;p&gt;Just to close this off, all now appears well. I&amp;#39;m thinking that something just got &amp;quot;stuck&amp;quot; somewhere... After building and flashing the Zephyr example again, I then erased the board, added the spm and flashed my Rust code. It works! Thanks for your help. I&amp;#39;ll mark your initial reply as the answer as it helped.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309405?ContentTypeID=1</link><pubDate>Wed, 12 May 2021 08:36:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e57e5b88-514f-46f1-a9e4-7f6ba603eae3</guid><dc:creator>Christopher Hunt</dc:creator><description>&lt;p&gt;OK, I tried 50% of the max duty. No cigar.&lt;/p&gt;
&lt;p&gt;Would I be pushing the friendship to show you the code in full? :-)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/titanclass/thingy-91-nrf9160/blob/master/examples/blinky.rs"&gt;github.com/.../blinky.rs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309380?ContentTypeID=1</link><pubDate>Wed, 12 May 2021 07:36:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0148ccd-4804-41ad-8cb0-fcc8822b9174</guid><dc:creator>Christopher Hunt</dc:creator><description>&lt;p&gt;I can make the lights now blink on the nRF9160-dk with the max duty cycle. I&amp;#39;ll try again with the Thingy:91 and 50% of the max. I&amp;#39;ll get back to you shortly. Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309377?ContentTypeID=1</link><pubDate>Wed, 12 May 2021 07:18:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03d5c736-8fbf-42b7-9a2c-6bcfa38438de</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p&gt;Hello Christopher,&lt;/p&gt;
&lt;p&gt;the Zephyr example uses a duty cycle of 50% changing the frequency up- and downwards. The maximum frequency is dependent on the wave counter and its prescaler, which is why the “self-calibration” was added to this application.&lt;/p&gt;
&lt;p&gt;Could you elaborate what kind of issue you exactly have? Are you able to make the LEDs blink at all?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309262?ContentTypeID=1</link><pubDate>Tue, 11 May 2021 12:59:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff03c7af-ee97-41f8-a466-4f55ce1a49fa</guid><dc:creator>Christopher Hunt</dc:creator><description>&lt;p&gt;OK, I confess. I&amp;#39;m using Rust. :-) I&amp;#39;ve had a lot of success using Rust with other Nordic hardware and so I&amp;#39;m now trying to get board support happening with the Thingy:91. By point 3, here&amp;#39;s the code:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;    rprintln!(&amp;quot;PWM Blinky demo starting&amp;quot;);
    loop {
        pwm.set_duty_on_common(pwm.get_max_duty());
        delay(&amp;amp;mut timer, 250_000); // 250ms
        pwm.set_duty_on_common(0);
        delay(&amp;amp;mut timer, 1_000_000); // 1s
    }
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And here&amp;#39;s the setup:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;fn init_device(p: hal::pac::Peripherals) -&amp;gt; (Pwm&amp;lt;hal::pac::PWM0_NS&amp;gt;, Timer&amp;lt;hal::pac::TIMER0_NS&amp;gt;) {
    let p0 = gpio::p0::Parts::new(p.P0_NS);

    let pwm = Pwm::new(p.PWM0_NS);
    pwm.set_output_pin(
        pwm::Channel::C0,
        &amp;amp;p0.p0_02.into_push_pull_output(gpio::Level::High).degrade(),
    );

    let timer = Timer::new(p.TIMER0_NS);

    (pwm, timer)
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The Zephyr code you referred to actually does something interesting with the max duty value. It appears as though it keeps halving it until setting the duty is accepted. Perhaps that&amp;#39;s what I need to do here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309201?ContentTypeID=1</link><pubDate>Tue, 11 May 2021 11:29:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4b9ae51-7679-467c-a5a4-2940f282f4fc</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p&gt;Hello Christopher,&lt;/p&gt;
&lt;p&gt;Since you are not using Zephyr in your application, I assume that you are using the pwm_nrfx drivers directly?&lt;/p&gt;
&lt;p&gt;I’m not quite sure if I understand point 3, though. Can you elaborate? Thanks!&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309017?ContentTypeID=1</link><pubDate>Mon, 10 May 2021 14:03:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42551668-323c-4c06-9652-65f32c722bcf</guid><dc:creator>Christopher Hunt</dc:creator><description>&lt;p&gt;Do those settings of mine also look right though (I&amp;#39;m not using Zephyr in my own app)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309015?ContentTypeID=1</link><pubDate>Mon, 10 May 2021 14:02:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:949acac9-f2fe-481c-96d6-3fd022f01a52</guid><dc:creator>Christopher Hunt</dc:creator><description>&lt;p&gt;Thanks - that worked!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A simple PWM LED approach for the Thingy:91</title><link>https://devzone.nordicsemi.com/thread/309001?ContentTypeID=1</link><pubDate>Mon, 10 May 2021 13:26:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:016026d2-3af2-4a0a-93ea-017beb510a49</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p&gt;Hello Christopher,&lt;/p&gt;
&lt;p&gt;Zephyr provides a straightforward &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/basic/blinky_pwm/README.html"&gt;sample&lt;/a&gt; showing how to control an LED with a PWM peripheral.&lt;/p&gt;
&lt;p&gt;You can find it in your ncs folder: ../zephyr/samples/basic/blinky_pwm.&lt;/p&gt;
&lt;p&gt;It doesn’t work for the Thingy:91 from scratch, but you can easily get it to work with the following modifications:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create an overlay file in your application root called: &lt;em&gt;thingy91_nrf9160ns.overlay&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Add the following lines to the overlay file&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/ {
    pwmleds {
        compatible = &amp;quot;pwm-leds&amp;quot;;
        pwm_led0: pwm_led_0 {
            pwms = &amp;lt; &amp;amp;pwm0 0x1f &amp;gt;;
        };
    };

    aliases {
        pwm-led0 = &amp;amp;pwm_led0;
    };
};&lt;/pre&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Build and run&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The application should now trigger the blue LED colour of the lightwell LED.&lt;/p&gt;
&lt;p&gt;I hope this is a good starting point for you!&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>