<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Strange PWM results in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Strange-PWM-results/m-p/170201#M5181</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;when does it work?&amp;nbsp; over a certain percentage? under?&amp;nbsp; i think that casting, (byte)((percent*255)/100), may be the problem.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Dec 2007 07:16:52 GMT</pubDate>
    <dc:creator>joeservo</dc:creator>
    <dc:date>2007-12-07T07:16:52Z</dc:date>
    <item>
      <title>Strange PWM results</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Strange-PWM-results/m-p/170200#M5180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am working with a freescale MC9S12DT256 and attempting to get a pwm signal.&amp;nbsp; As a first approach processor expert was used and successfully produced a pwm signal.&amp;nbsp; Since this is for educational purposes the goal is define all memory locations manually.&amp;nbsp; The code below will sometimes produce a pwm signal and other times not.&amp;nbsp; I should also note that it compiles.&amp;nbsp; I have tested it on multiple processors and get the same result.&amp;nbsp; To ensure that it is correctly wired to the scope I have tested the code generated with processor expert and it works.&amp;nbsp; At this point I am stuck and not sure where my problem is.&amp;nbsp; Any help would be greatly appreciated.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Erik&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#include &amp;lt;hidef.h&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* common defines and macros */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include &amp;lt;mc9s12dt256.h&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* derivative information */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#pragma LINK_INFO DERIVATIVE "mc9s12dt256b"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#define EPWMCNT (*((volatile unsigned int*) (0x000000AC)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define EPWMPER (*((volatile unsigned int*) (0x000000B4)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define EPWMDTY (*((volatile unsigned int*) (0x000000BC)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define EPWMPRCLKE (*((volatile unsigned int*) (0x000000A3)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define EPWMSCLAE (*((volatile unsigned long*) (0x000000A8)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define EPWMCLK_PCLK0E (*((volatile unsigned int*) (0x000000A2)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define EPWME_PWME0E (*((volatile unsigned int*) (0x000000A0)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#define one (1&amp;lt;&amp;lt;0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;void pwmpercentage2(int percent){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (percent &amp;gt; 100) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; percent = 100;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (percent &amp;lt; 0) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; percent = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EPWMDTY=(byte)((percent*255)/100);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;volatile static byte pwmChannel[1];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;void main(void) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EPWMCNT = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EPWMPER=255; //sets the period&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EPWMDTY = 25;//initialize duty cycle.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EPWMPRCLKE = 3; //set prescaler register&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EPWMSCLAE = 187; //set scale register&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EPWMCLK_PCLK0E = one; //select clock source&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EPWME_PWME0E = one;&amp;nbsp; //run counter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; /* put your own code here */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; EnableInterrupts;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; pwmChannel[0]= PTP_PTP0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pwmpercentage2(50);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for(;&lt;/SPAN&gt;&lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif"&gt;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/A&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2007 23:51:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Strange-PWM-results/m-p/170200#M5180</guid>
      <dc:creator>elee40</dc:creator>
      <dc:date>2007-12-04T23:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Strange PWM results</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Strange-PWM-results/m-p/170201#M5181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;when does it work?&amp;nbsp; over a certain percentage? under?&amp;nbsp; i think that casting, (byte)((percent*255)/100), may be the problem.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2007 07:16:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Strange-PWM-results/m-p/170201#M5181</guid>
      <dc:creator>joeservo</dc:creator>
      <dc:date>2007-12-07T07:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Strange PWM results</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Strange-PWM-results/m-p/170202#M5182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I would say its about 1 out of every 10 times that it works.&amp;nbsp; For sure it fails more than it works.&amp;nbsp; I think the casting portion is okay because I tested this portion of the code with bean generated code and had no problems.&amp;nbsp; I use that line to cast it to a byte because the period is only 255 so the dutycycle should never be any larger.&amp;nbsp; I will give the code a run without that function and just simply set the pwm dutycyle to a value and see if it works.&amp;nbsp; Thanks for the reply and am open for any other suggestions.&lt;BR /&gt;&amp;nbsp;Erik&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2007 07:31:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Strange-PWM-results/m-p/170202#M5182</guid>
      <dc:creator>elee40</dc:creator>
      <dc:date>2007-12-07T07:31:18Z</dc:date>
    </item>
  </channel>
</rss>

