<?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: PWMMC problem on 8-bits MC68HC908MR16 in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/PWMMC-problem-on-8-bits-MC68HC908MR16/m-p/1981265#M24065</link>
    <description>&lt;P class="lia-align-justify"&gt;OK,&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;BR /&gt;Problem solved, the PWMMC device did not start correctly. Instead of enabling the PWMMC with the PWMEN bit only, we enabled it with other bits. In addition, we wrote (with an ‘=’) instead of reading and writing (with ‘|=’) to the PCTL1 register. As the documentation says, the PWMMC device buffers the registers and requires the register to be read before writing.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Oct 2024 13:04:13 GMT</pubDate>
    <dc:creator>Cruvix</dc:creator>
    <dc:date>2024-10-24T13:04:13Z</dc:date>
    <item>
      <title>PWMMC problem on 8-bits MC68HC908MR16</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/PWMMC-problem-on-8-bits-MC68HC908MR16/m-p/1978305#M24064</link>
      <description>&lt;P class="lia-align-justify"&gt;Hello community,&lt;/P&gt;&lt;P class="lia-align-justify"&gt;I encounter a problem with the &lt;STRONG&gt;PWMMC&lt;/STRONG&gt; peripheral on the 8-bits microcontroler&amp;nbsp;&lt;STRONG&gt;MC68HC908MR16&lt;/STRONG&gt; from freescale. Let me present you the problem.&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;STRONG&gt;I. Configuration&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Microcontroler :&amp;nbsp;&lt;STRONG&gt;MC68HC908MR16&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;IDE : &lt;STRONG&gt;CodeWarrior&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P class="lia-align-justify"&gt;&lt;STRONG&gt;II. Project presentation&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;I'm working on an old software that control a three-phase motor with a scalar control approach (open loop), based on the application note &lt;STRONG&gt;AN1857&lt;/STRONG&gt; (attachments). The principle is to loop through a sine wave (with its third harmonic) look up table each 0.4ms (2.5kHz) and output PWM signal describing this sine wave with the good duty cycle. I would like to generate a &lt;STRONG&gt;220Hz&lt;/STRONG&gt; sine wave with &lt;STRONG&gt;2.5kHz carrier frequency&lt;/STRONG&gt; =&amp;gt; 11 points for the whole signal.&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;STRONG&gt;III. Problem description&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;When I see the 6 PWM generated on a scope, I notice an inconsistent duty cycle. So, I try a simple approach to test &lt;STRONG&gt;PWMMC&lt;/STRONG&gt;'s configuration with only 2 duty cycle values (&lt;STRONG&gt;250 and 500 corresponding to 25% and 50% duty cycle respectively&lt;/STRONG&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//The table wih the dummy duty cycle values
const unsigned long aul_pval[2] = {
   250,
   500
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;In the PWM interrupt,&amp;nbsp;I cycle between these two values and load them into the &lt;STRONG&gt;PVAL1&lt;/STRONG&gt;, &lt;STRONG&gt;PVAL3&lt;/STRONG&gt; and &lt;STRONG&gt;PVAL5&lt;/STRONG&gt; registers :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;unsigned int uiPhase = 0;

void vPWMcalc (void){	
   COPCTL=0x00;	
   PCTL1.R &amp;amp;= 0xE3; /* clear PWMF bit */	  	  

   PVAL1 = aul_pval[uiPhase];
   PVAL3 = aul_pval[uiPhase];
   PVAL5 = aul_pval[uiPhase];

   if (uiPhase &amp;gt;= 1) {
      uiPhase = 0;
   }
   else {
      uiPhase++;
   }	

   PCTL1.R |= 0x02; /* set LDOK bit */					
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;However, when I ran this code, the PWM output does not work as I expected :&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I have &lt;STRONG&gt;2 times&lt;/STRONG&gt; the same duty cycle for consecutives pulses (I expect an alternating between the 2 values)&lt;/LI&gt;&lt;LI&gt;An inconsistent duty cycle is present and not in the simple dummy table&lt;/LI&gt;&lt;/UL&gt;&lt;P class="lia-align-justify"&gt;On the next figures, the &lt;FONT color="#FFFF00"&gt;yellow signal is the High PWM&lt;/FONT&gt; and &lt;FONT color="#FF00FF"&gt;purple signal the Low PWM&lt;/FONT&gt;. &lt;FONT color="#00CCFF"&gt;The blue one&lt;/FONT&gt; is just a port that I toggle in the PWM interrupt to show the center aligned mode.&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cruvix_0-1729514381802.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/305891i79F8D5A655DFA4A2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cruvix_0-1729514381802.png" alt="Cruvix_0-1729514381802.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;EM&gt;Figure 1&amp;nbsp; :&amp;nbsp;Duty cycle of 50% OK, but the next pulse is 50% too&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cruvix_1-1729514414888.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/305892iF209925E587E8F21/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cruvix_1-1729514414888.png" alt="Cruvix_1-1729514414888.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;EM&gt;&lt;FONT color="#000000"&gt;Figure 2 :&amp;nbsp;&lt;/FONT&gt;&lt;FONT color="#000000"&gt;Duty cycle of 25% OK, but the next pulse is 25% too&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cruvix_3-1729514715022.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/305895i2394D75E9B735441/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cruvix_3-1729514715022.png" alt="Cruvix_3-1729514715022.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;EM&gt;Figure 3 :&amp;nbsp;unknown PWM duty cycle (35% in principle)&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;Its look likes there is a reload every 2 cycles, whereas I configure the PWMMC peripheral with a reload every cycle, but is does not explain the unknown duty cycle on figure 3. Moreover, it look likes the bufferisation of &lt;STRONG&gt;PVAL1&lt;/STRONG&gt;, &lt;STRONG&gt;PVAL3&lt;/STRONG&gt; and &lt;STRONG&gt;PVAL5&lt;/STRONG&gt; are not applied every cycle.&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;STRONG&gt;III. PWMMC peripheral configuration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gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;0x00&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;PCTL1&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;R&lt;/SPAN&gt;&lt;SPAN&gt; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;|=&lt;/SPAN&gt; &lt;SPAN&gt;0x02&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P class="lia-align-justify"&gt;&lt;SPAN&gt;I attach too the code and PWMMC configuration of Freescale Application Note 1857 to see differences.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;STRONG&gt;IV. What I try to solve the problem (but does not work)&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Use volatile variables outside ISR to avoid CPU caching&lt;/LI&gt;&lt;LI&gt;Use the first interrupt request when enabling the PWMMC to load values in PVAL1, PVAL3 and PVAL5 in advance (As I understand modified registers are buffered).&lt;/LI&gt;&lt;/UL&gt;&lt;P class="lia-align-justify"&gt;After many searches on the web and in the documentation, I don't understand the problem &lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;Thank you in advance for your answers !&lt;/P&gt;&lt;P class="lia-align-justify"&gt;Regards.&lt;/P&gt;&lt;P class="lia-align-justify"&gt;Cruvix.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 21 Oct 2024 14:04:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/PWMMC-problem-on-8-bits-MC68HC908MR16/m-p/1978305#M24064</guid>
      <dc:creator>Cruvix</dc:creator>
      <dc:date>2024-10-21T14:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: PWMMC problem on 8-bits MC68HC908MR16</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/PWMMC-problem-on-8-bits-MC68HC908MR16/m-p/1981265#M24065</link>
      <description>&lt;P class="lia-align-justify"&gt;OK,&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;BR /&gt;Problem solved, the PWMMC device did not start correctly. Instead of enabling the PWMMC with the PWMEN bit only, we enabled it with other bits. In addition, we wrote (with an ‘=’) instead of reading and writing (with ‘|=’) to the PCTL1 register. As the documentation says, the PWMMC device buffers the registers and requires the register to be read before writing.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 13:04:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/PWMMC-problem-on-8-bits-MC68HC908MR16/m-p/1981265#M24065</guid>
      <dc:creator>Cruvix</dc:creator>
      <dc:date>2024-10-24T13:04:13Z</dc:date>
    </item>
  </channel>
</rss>

