<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>PSoC4 Smarter Life Challenge - DAS Project :Example 3 LED Dimming (PWM based)</title><link>https://community.element14.com/challenges-projects/design-challenges/smarter-life/w/documents/16749/psoc4-smarter-life-challenge---das-project-example-3-led-dimming-pwm-based</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>PSoC4 Smarter Life Challenge - DAS Project :Example 3 LED Dimming (PWM based)</title><link>https://community.element14.com/challenges-projects/design-challenges/smarter-life/w/documents/16749/psoc4-smarter-life-challenge---das-project-example-3-led-dimming-pwm-based</link><pubDate>Wed, 17 Dec 2014 03:55:17 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:56b2ae1d-e1e7-4e3d-9d39-79249896a4a2</guid><dc:creator>bose</dc:creator><comments>https://community.element14.com/challenges-projects/design-challenges/smarter-life/w/documents/16749/psoc4-smarter-life-challenge---das-project-example-3-led-dimming-pwm-based#comments</comments><description>Current Revision posted to Documents by bose on 12/17/2014 3:55:17 AM&lt;br /&gt;
&lt;p style="margin:0;"&gt;This example show how to perform LED dimming using PWM module for Cypress PSoC 4 Pioneer Kit.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Here is the Application Schematics:&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/620x355/__key/communityserver-wikis-components-files/00-00-00-01-96/8875.contentimage_5F00_45798.png"&gt;&lt;img alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/96/8875.contentimage_45798.png-620x355.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=8K48tO7XXI7ivRgD2sOlZy%2BD0J6hcJERLFzFEMkngY0%3D&amp;amp;se=2026-08-15T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=lHJpmFtv7HvyRGv3tOxhcQ==" style="max-height: 355px;max-width: 620px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/796x439/__key/communityserver-wikis-components-files/00-00-00-01-96/5732.contentimage_5F00_45799.png"&gt;&lt;img loading="lazy" alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/96/5732.contentimage_45799.png-796x439.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=29EHSW1czVkV6bk36tmZQXxyb9fgqGaUIkXIz5NZAqY%3D&amp;amp;se=2026-08-15T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=DvtcT0BvsXVVXbNTCTGe7A==" style="max-height: 439px;max-width: 796px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;This example uses the PWM block in a timed configuration to produce the dimming effect on the LED.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;The PWM module { &lt;strong&gt;PWM (TCPWM mode) [v1.0]&lt;/strong&gt; }configuration is as shown below:&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/620x653/__key/communityserver-wikis-components-files/00-00-00-01-96/8284.contentimage_5F00_45800.png"&gt;&lt;img loading="lazy" alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/96/8284.contentimage_45800.png-620x653.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=KUCmHc%2F%2BgYhIdDX%2Fqv43tivGIEENL4UppQtOF56iqWw%3D&amp;amp;se=2026-08-15T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=SPfuZTq3rwPfh2ah6+yYnA==" style="max-height: 653px;max-width: 620px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;In the code one needs to vary the Compare factor for the PWM to generate a DC average output that would lead to dimming of the led.&lt;/p&gt;&lt;p style="margin:0;"&gt;Ideally a capacitor is needed to produce the DC averge but since the LED load is not significant, its possible to directly generate the dimming on the pin connected LED.&lt;/p&gt;&lt;p style="margin:0;"&gt;Here is the code for this example:&lt;/p&gt;&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;project.h&amp;gt;
int main()
{
     uint32 i = 0; //Used as a Counter
     uint32 op = 0; //Used to define which operation is being currently performed : 0-additions 1-subtractions
     // Start the PWM generation
     PWM_1_Start();
     for(;;)
     {
          CyDelay(5); //Cycle Delay
          // Process the Counter Operation
          if(op == 0)
               i += 10;       
          else
               i -= 10;
          // Change the PWM duty cycle value as per the Counter
          PWM_1_WriteCompare(i);
          // Handle Counter overflow
          if(i&amp;gt;=1000)
          {
               op = 1; // Start Decrementing as max value has already reached
          }
          else if(i&amp;lt;=1)
          {
               op = 0; // Start Incrementing as Min value has already reached
               CyDelay(800); // Delay to keep the LED off for more time
          }
     }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="display:none;"&gt;&lt;/div&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;After building and loading this code the Green LED on the Pioneer Kit would show the dimming effect.&lt;/p&gt;&lt;p style="margin:0;"&gt;Its important to note here that this dimming would show up some visible blink and may also cause EMI/EMC or RFI issues in case the output is used to control LED drivers.&lt;/p&gt;&lt;p style="margin:0;"&gt;The better solution would be use the &lt;em&gt;PrISM&lt;/em&gt; module to generate precise dimming without flicker or emission issues.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: psoc4, examples, smarter, das_project, smarter_life&lt;/div&gt;
</description></item></channel></rss>